Initial commit.
[cfb.git] / prod / net / jaekl / cfb / db / Column.java
1 package net.jaekl.cfb.db;
2
3 public class Column {
4         public enum Type {
5                 CHAR, INTEGER, TIMESTAMP, TIMESTAMPTZ, VARCHAR 
6         };
7         public enum Null {
8                 NOT_NULL, NULL
9         }
10         
11         String m_name;
12         Type m_type;
13         int m_width;
14         Null m_null;
15         
16         public Column(String name, Type type, int width, Null canBeNull) 
17         {
18                 m_name = name;
19                 m_type = type;
20                 m_width = width;
21                 m_null = canBeNull;
22         }
23         
24         public String getName() { return m_name; }
25         public Type getType() { return m_type; }
26         public int getWidth() { return m_width; }
27         public Null getNull() { return m_null; }
28         
29         // Create a column based on an array of Objects
30         // Input format:  { name, type, width, can_be_null } 
31         public static Column construct(Object[] spec) {
32                 assert(null != spec);
33                 assert(4 == spec.length);
34                 assert(spec[0] instanceof String);
35                 assert(spec[1] instanceof Type);
36                 assert(spec[2] instanceof Number);
37                 assert(spec[3] instanceof Null);
38                 
39                 String name = (String)(spec[0]);
40                 Type type = (Type)(spec[1]);
41                 Number width = (Number)(spec[2]);
42                 Null canBeNull = (Null)(spec[3]);
43                 
44                 return new Column(name, type, width.intValue(), canBeNull);
45         }
46 }