View Javadoc
1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package tools.gsf.facade.sql.table;
18  
19  /**
20   * A column definition for a table
21   *
22   * @author Dolf Dijkstra
23   */
24  public class TableColumn {
25  
26      public enum Type {
27          ccchar("cc.char"), ccvarchar("cc.varchar"), ccbigtext("cc.bigtext"), ccsmallint("cc.smallint"), ccinteger(
28                  "cc.integer"), ccbigint("cc.bigint"), ccnumeric("cc.numeric"), ccdouble("cc.double"), ccdatetime(
29                  "cc.datetime"), ccblob("cc.blob");
30  
31          private final String prop;
32  
33          Type(String prop) {
34              this.prop = prop;
35          }
36  
37          public String getProperty() {
38              return prop;
39          }
40  
41      }
42  
43      private final String name;
44  
45      private final Type type;
46  
47      private final boolean primary;
48  
49      private boolean unique;
50  
51      private int length;
52  
53      private int decimal;
54  
55      private boolean nullable;
56  
57      public TableColumn(final String name, final Type type) {
58          this(name, type, false);
59      }
60  
61      public TableColumn(final String name, final Type type, final boolean primary) {
62          super();
63          this.name = name;
64          this.primary = primary;
65          this.type = type;
66      }
67  
68      public int getDecimal() {
69          return decimal;
70      }
71  
72      public TableColumn setDecimal(int decimal) {
73          this.decimal = decimal;
74          return this;
75      }
76  
77      public int getLength() {
78          return length;
79      }
80  
81      public TableColumn setLength(int length) {
82          this.length = length;
83          return this;
84      }
85  
86      public boolean isNullable() {
87          return nullable;
88      }
89  
90      public TableColumn setNullable(boolean nullable) {
91          this.nullable = nullable;
92          return this;
93      }
94  
95      public boolean isPrimary() {
96          return primary;
97      }
98  
99      public String getName() {
100         return name;
101     }
102 
103     public Type getType() {
104         return type;
105     }
106 
107     public boolean isUnique() {
108         return unique;
109     }
110 
111     public TableColumn setUnique(boolean unique) {
112         this.unique = unique;
113         return this;
114     }
115 
116 }