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