1 package org.apache.torque.map;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 /***
58 * ColumnMap is used to model a column of a table in a database.
59 *
60 * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
61 * @version $Id: ColumnMap.java,v 1.7 2003/03/21 17:31:08 mpoeschl Exp $
62 */
63 public class ColumnMap implements java.io.Serializable
64 {
65 /*** Type of the column. */
66 private Object type = null;
67
68 /*** Size of the column. */
69 private int size = 0;
70
71 /*** Is it a primary key? */
72 private boolean pk = false;
73
74 /*** Is null value allowed ?*/
75 private boolean notNull = false;
76
77 /*** Name of the table that this column is related to. */
78 private String relatedTableName = "";
79
80 /*** Name of the column that this column is related to. */
81 private String relatedColumnName = "";
82
83 /*** The TableMap for this column. */
84 private TableMap table;
85
86 /*** The name of the column. */
87 private String columnName;
88
89
90 /***
91 * Constructor.
92 *
93 * @param name The name of the column.
94 * @param containingTable TableMap of the table this column is in.
95 */
96 public ColumnMap(String name, TableMap containingTable)
97 {
98 this.columnName = name;
99 table = containingTable;
100 }
101
102 /***
103 * Get the name of a column.
104 *
105 * @return A String with the column name.
106 */
107 public String getColumnName()
108 {
109 return columnName;
110 }
111
112 /***
113 * Get the table name + column name.
114 *
115 * @return A String with the full column name.
116 */
117 public String getFullyQualifiedName()
118 {
119 return table.getName() + "." + columnName;
120 }
121
122 /***
123 * Get the name of the table this column is in.
124 *
125 * @return A String with the table name.
126 */
127 public String getTableName()
128 {
129 return table.getName();
130 }
131
132 /***
133 * Set the type of this column.
134 *
135 * @param type An Object specifying the type.
136 */
137 public void setType (Object type)
138 {
139 this.type = type;
140 }
141
142 /***
143 * Set the size of this column.
144 *
145 * @param size An int specifying the size.
146 */
147 public void setSize(int size)
148 {
149 this.size = size;
150 }
151
152 /***
153 * Set if this column is a primary key or not.
154 *
155 * @param pk True if column is a primary key.
156 */
157 public void setPrimaryKey(boolean pk)
158 {
159 this.pk = pk;
160 }
161
162 /***
163 * Set if this column may be null.
164 *
165 * @param nn True if column may be null.
166 */
167 public void setNotNull(boolean nn)
168 {
169 this.notNull = nn;
170 }
171
172 /***
173 * Set the foreign key for this column.
174 *
175 * @param fullyQualifiedName The name of the table.column that is
176 * foreign.
177 */
178 public void setForeignKey(String fullyQualifiedName)
179 {
180 if (fullyQualifiedName != null && fullyQualifiedName.length() > 0)
181 {
182 relatedTableName = fullyQualifiedName.substring(
183 0, fullyQualifiedName.indexOf('.'));
184 relatedColumnName = fullyQualifiedName.substring(
185 fullyQualifiedName.indexOf('.') + 1);
186 }
187 else
188 {
189 relatedTableName = "";
190 relatedColumnName = "";
191 }
192 }
193
194 /***
195 * Set the foreign key for this column.
196 *
197 * @param tableName The name of the table that is foreign.
198 * @param columnName The name of the column that is foreign.
199 */
200 public void setForeignKey(String tableName, String columnName)
201 {
202 if (tableName != null && tableName.length() > 0 && columnName != null
203 && columnName.length() > 0)
204 {
205 relatedTableName = tableName;
206 relatedColumnName = columnName;
207 }
208 else
209 {
210 relatedTableName = "";
211 relatedColumnName = "";
212 }
213 }
214
215 /***
216 * Get the type of this column.
217 *
218 * @return An Object specifying the type.
219 */
220 public Object getType()
221 {
222 return type;
223 }
224
225 /***
226 * Get the size of this column.
227 *
228 * @return An int specifying the size.
229 */
230 public int getSize()
231 {
232 return size;
233 }
234
235 /***
236 * Is this column a primary key?
237 *
238 * @return True if column is a primary key.
239 */
240 public boolean isPrimaryKey()
241 {
242 return pk;
243 }
244
245 /***
246 * Is null value allowed ?
247 *
248 * @return True if column may be null.
249 */
250 public boolean isNotNull()
251 {
252 return (notNull || isPrimaryKey());
253 }
254
255 /***
256 * Is this column a foreign key?
257 *
258 * @return True if column is a foreign key.
259 */
260 public boolean isForeignKey()
261 {
262 return (relatedTableName != null && relatedTableName.length() > 0);
263 }
264
265 /***
266 * Get the table.column that this column is related to.
267 *
268 * @return A String with the full name for the related column.
269 */
270 public String getRelatedName()
271 {
272 return relatedTableName + "." + relatedColumnName;
273 }
274
275 /***
276 * Get the table name that this column is related to.
277 *
278 * @return A String with the name for the related table.
279 */
280 public String getRelatedTableName()
281 {
282 return relatedTableName;
283 }
284
285 /***
286 * Get the column name that this column is related to.
287 *
288 * @return A String with the name for the related column.
289 */
290 public String getRelatedColumnName()
291 {
292 return relatedColumnName;
293 }
294 }