KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > commons > dsi > ddl > ColumnDefinition


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.commons.dsi.ddl;
20
21 /**
22  * An abstraction of a databse table column.
23  *
24  * @author Michael Bell
25  * @version $Revision: 1.1 $
26  *
27  */

28 public class ColumnDefinition {
29     
30     /**
31      * Constant indicating a date data type.
32      */

33     static public int DATE = 0;
34     
35     /**
36      * Constant indicating a text data type.
37      */

38     static public int TEXT = 1;
39     
40     /**
41      * Constant indicating a number data type.
42      */

43     static public int NUMBER = 2;
44     
45     /**
46      * Constant indicating a long text data type.
47      */

48     static public int LONG_TEXT = 3;
49     
50     /**
51      * Constant indicating a boolean data type.
52      */

53     static public int BOOLEAN = 4;
54     
55     /**
56      * The name of the column.
57      */

58     private String JavaDoc m_sColumnName = null;
59     
60     /**
61      * The data type of the column.
62      */

63     private int m_nDataType = 1;
64     
65     /**
66      * Default value for column.
67      */

68     Object JavaDoc m_default = null;
69     
70     /**
71      * <code>boolean</code> flag to indicate whether column can be NULL.
72      */

73     boolean m_bAllowNull = false;
74     
75     /**
76      * <code>boolean</code> flag to indicate whether column value has to be unique.
77      */

78     
79     boolean m_bIsUnique = false;
80     
81     /**
82      * <code>boolean</code> flag to indicate whether column is a primary key.
83      */

84     boolean m_bIsPrimaryKey = false;
85     
86     /**
87      * The table name that this column references as a foreign key.
88      */

89     String JavaDoc m_sForeignKeyRef = null;
90     
91     /**
92      * Creates a column definition for a column with the given name
93      * and datatype.
94      *
95      * @param sColName the column name
96      * @param nDataType the data type
97      */

98     public ColumnDefinition(String JavaDoc sColName, int nDataType) {
99         m_sColumnName = sColName;
100         m_nDataType = nDataType;
101     }
102     
103     /**
104      * Creates a column definition for a column with the given name
105      * ,datatype and whether the column can be NULL.
106      *
107      * @param sColName the column name
108      * @param nDataType the data type
109      * @param bAllowNull <code>true</code> if the column can be NULL
110      */

111     public ColumnDefinition(String JavaDoc sColName, int nDataType,boolean bAllowNull) {
112         this(sColName,nDataType);
113         m_bAllowNull = bAllowNull;
114     }
115     
116     /**
117      * Creates a column definition for a column.
118      *
119      * @param sColName the column name
120      * @param bIsPrimaryKey <code>true</code> if the column is a primary key
121      * @param nDataType the data type
122      */

123     public ColumnDefinition(String JavaDoc sColName, boolean bIsPrimaryKey, int nDataType) {
124         this(sColName,nDataType);
125         m_bIsPrimaryKey = bIsPrimaryKey;
126     }
127     
128     /**
129      * Creates a column definition for a column.
130      *
131      * @param sColName the column name
132      * @param bIsPrimaryKey <code>true</code> if the column is a primary key
133      * @param nDataType the data type
134      * @param bAllowNull <code>true</code> if the column can be NULL
135      */

136     public ColumnDefinition(String JavaDoc sColName, boolean bIsPrimaryKey, int nDataType, boolean bAllowNull) {
137         this(sColName,bIsPrimaryKey,nDataType);
138         m_bAllowNull = bAllowNull;
139     }
140     
141     /**
142      * Creates a column definition for a column.
143      *
144      * @param sColName the column name
145      * @param nDataType the data type
146      * @param defaultVal the default value
147      */

148     public ColumnDefinition(String JavaDoc sColName, int nDataType, Object JavaDoc defaultVal) {
149         this(sColName,nDataType);
150         m_default = defaultVal;
151     }
152     
153     /**
154      * Creates a column definition for a column.
155      *
156      * @param sColName the column name
157      * @param bIsPrimaryKey <code>true</code> if the column is a primary key
158      * @param nDataType the data type
159      * @param defaultVal the default value
160      */

161     public ColumnDefinition(String JavaDoc sColName, boolean bIsPrimaryKey, int nDataType, Object JavaDoc defaultVal) {
162         this(sColName,nDataType,defaultVal);
163         m_bIsPrimaryKey = bIsPrimaryKey;
164         m_bIsUnique = true;
165     }
166     
167     /**
168      * Returns the column name.
169      *
170      * @return the column name
171      */

172     public String JavaDoc getName() {
173         return m_sColumnName;
174     }
175     
176     /**
177      * Returns the data type.
178      *
179      * @return the data type
180      */

181     public int getDataType() {
182         return m_nDataType;
183     }
184     
185     /**
186      * Returns <code>true</code> if the column is a primary key.
187      *
188      * @return <code>true</code> if the column is a primary key
189      */

190     public boolean isPrimaryKey() {
191         return m_bIsPrimaryKey;
192     }
193     
194     /**
195      * Returns <code>true</code> if the column values must be unique.
196      *
197      * @return <code>true</code> if the column values must be unique
198      */

199     public boolean isUnique() {
200         return m_bIsUnique;
201     }
202     
203     /**
204      * Sets whether the column values must be unique.
205      *
206      * @param bIsUnique <code>true</code> if the column values must be unique
207      */

208     public void setIsUnique(boolean bIsUnique) {
209         m_bIsUnique = bIsUnique;
210     }
211     
212     /**
213      * Returns <code>true</code> if the column can have NULL values.
214      *
215      * @return <code>true</code> if the column can have NULL values
216      */

217     public boolean allowNulls() {
218         return m_bAllowNull;
219     }
220
221     /**
222      * Returns the default value for the column.
223      *
224      * @return the default value for the column
225      */

226     public Object JavaDoc getDefault() {
227         return m_default;
228     }
229
230     /**
231      * Returns <code>true</code> if the column is/has a foreign key.
232      *
233      * @return <code>true</code> if the column is/has a foreign key
234      */

235     public boolean isForeignKey() {
236         return m_sForeignKeyRef != null;
237     }
238
239     /**
240      * Returns the table name of the foreign key reference.
241      *
242      * @return the foreign key reference
243      */

244     public String JavaDoc getForeignKeyReference() {
245         return m_sForeignKeyRef;
246     }
247
248     /**
249      * Adds a foreign key reference .
250      *
251      * @param string the table name of the foreign key reference
252      */

253     public void addForeignKey(String JavaDoc sForeignKeyRef) {
254         m_sForeignKeyRef = sForeignKeyRef;
255     }
256     
257 }
258
Popular Tags