%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.torque.map.ColumnMap |
|
|
1 | package org.apache.torque.map; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2005 The Apache Software Foundation. |
|
5 | * |
|
6 | * Licensed under the Apache License, Version 2.0 (the "License") |
|
7 | * you may not use this file except in compliance with the License. |
|
8 | * You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
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 326224 2005-10-18 20:35:33Z tfischer $ |
|
24 | */ |
|
25 | public class ColumnMap implements java.io.Serializable |
|
26 | { |
|
27 | /** Type of the column. */ |
|
28 | 4 | private Object type = null; |
29 | ||
30 | /** Size of the column. */ |
|
31 | 4 | private int size = 0; |
32 | ||
33 | /** Scale of the column */ |
|
34 | 4 | private int scale = 0; |
35 | ||
36 | /** Is it a primary key? */ |
|
37 | 4 | private boolean pk = false; |
38 | ||
39 | /** Is null value allowed ?*/ |
|
40 | 4 | private boolean notNull = false; |
41 | ||
42 | /** Name of the table that this column is related to. */ |
|
43 | 4 | private String relatedTableName = ""; |
44 | ||
45 | /** Name of the column that this column is related to. */ |
|
46 | 4 | private String relatedColumnName = ""; |
47 | ||
48 | /** The TableMap for this column. */ |
|
49 | private TableMap table; |
|
50 | ||
51 | /** The name of the column. */ |
|
52 | private String columnName; |
|
53 | ||
54 | ||
55 | /** |
|
56 | * Constructor. |
|
57 | * |
|
58 | * @param name The name of the column. |
|
59 | * @param containingTable TableMap of the table this column is in. |
|
60 | */ |
|
61 | public ColumnMap(String name, TableMap containingTable) |
|
62 | 4 | { |
63 | 4 | this.columnName = name; |
64 | 4 | table = containingTable; |
65 | 4 | } |
66 | ||
67 | /** |
|
68 | * Get the name of a column. |
|
69 | * |
|
70 | * @return A String with the column name. |
|
71 | */ |
|
72 | public String getColumnName() |
|
73 | { |
|
74 | 0 | return columnName; |
75 | } |
|
76 | ||
77 | /** |
|
78 | * Get the table name + column name. |
|
79 | * |
|
80 | * @return A String with the full column name. |
|
81 | */ |
|
82 | public String getFullyQualifiedName() |
|
83 | { |
|
84 | 0 | return table.getName() + "." + columnName; |
85 | } |
|
86 | ||
87 | /** |
|
88 | * Get the name of the table this column is in. |
|
89 | * |
|
90 | * @return A String with the table name. |
|
91 | */ |
|
92 | public String getTableName() |
|
93 | { |
|
94 | 0 | return table.getName(); |
95 | } |
|
96 | ||
97 | /** |
|
98 | * Set the type of this column. |
|
99 | * |
|
100 | * @param type An Object specifying the type. |
|
101 | */ |
|
102 | public void setType (Object type) |
|
103 | { |
|
104 | 4 | this.type = type; |
105 | 4 | } |
106 | ||
107 | /** |
|
108 | * Set the size of this column. |
|
109 | * |
|
110 | * @param size An int specifying the size. |
|
111 | */ |
|
112 | public void setSize(int size) |
|
113 | { |
|
114 | 4 | this.size = size; |
115 | 4 | } |
116 | ||
117 | /** |
|
118 | * Set if this column is a primary key or not. |
|
119 | * |
|
120 | * @param pk True if column is a primary key. |
|
121 | */ |
|
122 | public void setPrimaryKey(boolean pk) |
|
123 | { |
|
124 | 4 | this.pk = pk; |
125 | 4 | } |
126 | ||
127 | /** |
|
128 | * Set if this column may be null. |
|
129 | * |
|
130 | * @param nn True if column may be null. |
|
131 | */ |
|
132 | public void setNotNull(boolean nn) |
|
133 | { |
|
134 | 0 | this.notNull = nn; |
135 | 0 | } |
136 | ||
137 | /** |
|
138 | * Set the foreign key for this column. |
|
139 | * |
|
140 | * @param fullyQualifiedName The name of the table.column that is |
|
141 | * foreign. |
|
142 | */ |
|
143 | public void setForeignKey(String fullyQualifiedName) |
|
144 | { |
|
145 | 0 | if (fullyQualclass="keyword">ifiedName != null && fullyQualclass="keyword">ifiedName.length() > 0) |
146 | { |
|
147 | 0 | relatedTableName = fullyQualifiedName.substring( |
148 | 0, fullyQualifiedName.indexOf('.')); |
|
149 | 0 | relatedColumnName = fullyQualifiedName.substring( |
150 | fullyQualifiedName.indexOf('.') + 1); |
|
151 | } |
|
152 | else |
|
153 | { |
|
154 | 0 | relatedTableName = ""; |
155 | 0 | relatedColumnName = ""; |
156 | } |
|
157 | 0 | } |
158 | ||
159 | /** |
|
160 | * Set the foreign key for this column. |
|
161 | * |
|
162 | * @param tableName The name of the table that is foreign. |
|
163 | * @param columnName The name of the column that is foreign. |
|
164 | */ |
|
165 | public void setForeignKey(String tableName, String columnName) |
|
166 | { |
|
167 | 4 | if (tableName != null && tableName.length() > 0 && columnName != class="keyword">null |
168 | && columnName.length() > 0) |
|
169 | { |
|
170 | 0 | relatedTableName = tableName; |
171 | 0 | relatedColumnName = columnName; |
172 | } |
|
173 | else |
|
174 | { |
|
175 | 4 | relatedTableName = ""; |
176 | 4 | relatedColumnName = ""; |
177 | } |
|
178 | 4 | } |
179 | ||
180 | /** |
|
181 | * Get the type of this column. |
|
182 | * |
|
183 | * @return An Object specifying the type. |
|
184 | */ |
|
185 | public Object getType() |
|
186 | { |
|
187 | 0 | return type; |
188 | } |
|
189 | ||
190 | /** |
|
191 | * The "precision" value from the XML |
|
192 | * size="<precision>[,<scale>]" |
|
193 | * attribute. Where [,<scale>] is optional. |
|
194 | * |
|
195 | * If the size attribute has not been set in the XML, it will return 0.<p> |
|
196 | * |
|
197 | * Note that the size="P,S" format should be replaced with |
|
198 | * size="P" scale="S". |
|
199 | * |
|
200 | * @return An int specifying the size. |
|
201 | */ |
|
202 | public int getSize() |
|
203 | { |
|
204 | 0 | return size; |
205 | } |
|
206 | ||
207 | /** |
|
208 | * Is this column a primary key? |
|
209 | * |
|
210 | * @return True if column is a primary key. |
|
211 | */ |
|
212 | public boolean isPrimaryKey() |
|
213 | { |
|
214 | 0 | return pk; |
215 | } |
|
216 | ||
217 | /** |
|
218 | * Is null value allowed ? |
|
219 | * |
|
220 | * @return True if column may be null. |
|
221 | */ |
|
222 | public boolean isNotNull() |
|
223 | { |
|
224 | 0 | return (notNull || isPrimaryKey()); |
225 | } |
|
226 | ||
227 | /** |
|
228 | * Is this column a foreign key? |
|
229 | * |
|
230 | * @return True if column is a foreign key. |
|
231 | */ |
|
232 | public boolean isForeignKey() |
|
233 | { |
|
234 | 0 | return (relatedTableName != null && relatedTableName.length() > 0); |
235 | } |
|
236 | ||
237 | /** |
|
238 | * Get the table.column that this column is related to. |
|
239 | * |
|
240 | * @return A String with the full name for the related column. |
|
241 | */ |
|
242 | public String getRelatedName() |
|
243 | { |
|
244 | 0 | return relatedTableName + "." + relatedColumnName; |
245 | } |
|
246 | ||
247 | /** |
|
248 | * Get the table name that this column is related to. |
|
249 | * |
|
250 | * @return A String with the name for the related table. |
|
251 | */ |
|
252 | public String getRelatedTableName() |
|
253 | { |
|
254 | 0 | return relatedTableName; |
255 | } |
|
256 | ||
257 | /** |
|
258 | * Get the column name that this column is related to. |
|
259 | * |
|
260 | * @return A String with the name for the related column. |
|
261 | */ |
|
262 | public String getRelatedColumnName() |
|
263 | { |
|
264 | 0 | return relatedColumnName; |
265 | } |
|
266 | ||
267 | /** |
|
268 | * Gets the scale set for this column (if any) as set in the XML database |
|
269 | * definition. E.g., the value of the scale attribute or the scale portion |
|
270 | * of a size="P,S" attribute. |
|
271 | * (Note: size="P,S" format is being deprecated!). |
|
272 | * |
|
273 | * @return Returns the scale. |
|
274 | */ |
|
275 | public int getScale() |
|
276 | { |
|
277 | 0 | return scale; |
278 | } |
|
279 | ||
280 | /** |
|
281 | * @param scale The scale to set. |
|
282 | */ |
|
283 | public void setScale(int scale) |
|
284 | { |
|
285 | 4 | this.scale = scale; |
286 | 4 | } |
287 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |