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 com.fatwire.gst.foundation.facade.sql.table;
18  
19  /**
20   * 
21   * 
22   * A column definition for a table
23   * 
24   * @author Dolf Dijkstra
25   * 
26   */
27  public class TableColumn {
28  
29      public enum Type {
30          ccchar("cc.char"), ccvarchar("cc.varchar"), ccbigtext("cc.bigtext"), ccsmallint("cc.smallint"), ccinteger(
31                  "cc.integer"), ccbigint("cc.bigint"), ccnumeric("cc.numeric"), ccdouble("cc.double"), ccdatetime(
32                  "cc.datetime"), ccblob("cc.blob");
33  
34          private final String prop;
35  
36          Type(String prop) {
37              this.prop = prop;
38          }
39  
40          public String getProperty() {
41              return prop;
42          }
43  
44      }
45  
46      private final String name;
47  
48      private final Type type;
49  
50      private final boolean primary;
51  
52      private boolean unique;
53  
54      private int length;
55  
56      private int decimal;
57  
58      private boolean nullable;
59  
60      public TableColumn(final String name, final Type type) {
61          this(name, type, false);
62      }
63  
64      public TableColumn(final String name, final Type type, final boolean primary) {
65          super();
66          this.name = name;
67          this.primary = primary;
68          this.type = type;
69      }
70  
71      public int getDecimal() {
72          return decimal;
73      }
74  
75      public TableColumn setDecimal(int decimal) {
76          this.decimal = decimal;
77          return this;
78      }
79  
80      public int getLength() {
81          return length;
82      }
83  
84      public TableColumn setLength(int length) {
85          this.length = length;
86          return this;
87      }
88  
89      public boolean isNullable() {
90          return nullable;
91      }
92  
93      public TableColumn setNullable(boolean nullable) {
94          this.nullable = nullable;
95          return this;
96      }
97  
98      public boolean isPrimary() {
99          return primary;
100     }
101 
102     public String getName() {
103         return name;
104     }
105 
106     public Type getType() {
107         return type;
108     }
109 
110     public boolean isUnique() {
111         return unique;
112     }
113 
114     public TableColumn setUnique(boolean unique) {
115         this.unique = unique;
116         return this;
117     }
118 
119 }