1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.devaki.nextobjects.workspace.models.objects;
21 import java.io.Serializable;
22 import java.util.Vector;
23 import org.devaki.nextobjects.workspace.models.BaseModel;
24 import org.devaki.nextobjects.workspace.models.graphics.ObjectView;
25 import org.devaki.nextobjects.workspace.models.columns.Column;
26 /***
27 * Object of type "class"
28 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
29 * @see http://db.apache.org/torque/schema-reference.html
30 *
31 */
32 public abstract class BaseClass extends BaseObject implements Serializable
33 {
34 /***
35 * torque schema propertie
36 */
37 private boolean skipSql = false;
38 /***
39 * torque schema propertie
40 */
41 private String idMethod = "none";
42 /***
43 * torque schema propertie
44 */
45 private boolean heavyIndexing = false;
46 /***
47 * torque schema propertie
48 */
49 private boolean abstractClass = false;
50 /***
51 * torque schema propertie
52 */
53 private String baseClass = "";
54 /***
55 * torque schema propertie
56 */
57 private String basePeer = "org.apache.torque.util.BasePeer";
58 /***
59 * torque schema propertie
60 */
61 private String javaName = "";
62 /***
63 * torque schema propertie
64 */
65 private String javaNamingMethod = "underscore";
66 /***
67 * torque schema propertie
68 */
69 private String alias = "";
70 /***
71 * torque schema propertie
72 */
73 private static int countBaseClasss = 0;
74 /***
75 * data changed
76 */
77 private boolean dataChanged = false;
78 /***
79 * data changed
80 */
81 private Vector Uniques = new Vector(1);
82 /***
83 * data changed
84 */
85 private Vector Indexes = new Vector(1);
86 /***
87 * Construct a standard BaseClass
88 */
89 public BaseClass()
90 {
91 super();
92 countBaseClasss++;
93 }
94 /***
95 * Construct a nextGraphicsObject with a pre-defined NOModel
96 * @param pModel the base model
97 */
98 public BaseClass(final BaseModel pModel)
99 {
100 super(pModel);
101 this.setBaseClass(pModel.getBaseClass());
102 this.setBasePeer(pModel.getBasePeer());
103 this.setIdMethod(pModel.getDefaultIdMethod());
104 countBaseClasss++;
105 }
106 /***
107 * Construct a nextGraphicsObject by copying another nextGraphicsObject
108 * @param pObject the class to clone
109 */
110 public BaseClass(final BaseClass pObject)
111 {
112 super(pObject);
113 this.setName(pObject.getName());
114 this.setCode(pObject.getCode());
115 this.setJavaName(pObject.getJavaName());
116 this.setIdMethod(pObject.getIdMethod());
117 this.setSkipSql(pObject.getSkipSql());
118 this.setAbstractClass(pObject.getAbstractClass());
119 this.setBaseClass(pObject.getBaseClass());
120 this.setBasePeer(pObject.getBasePeer());
121 this.setAlias(pObject.getAlias());
122 this.setJavaNamingMethod(pObject.getJavaNamingMethod());
123 this.setHeavyIndexing(pObject.getHeavyIndexing());
124 this.setDescription(pObject.getDescription());
125 this.setNotes(pObject.getNotes());
126 this.setData(pObject.getData());
127 this.setUniques(pObject.getUniques());
128 this.setIndexes(pObject.getIndexes());
129 countBaseClasss++;
130 }
131 /***
132 * get the object view
133 * @return object view
134 */
135 public abstract ObjectView getObjectView();
136 /***
137 * ?
138 * @param pHeavyIndexing heavy indexing
139 */
140 public final void setHeavyIndexing(final boolean pHeavyIndexing)
141 {
142 this.heavyIndexing = pHeavyIndexing;
143 }
144 /***
145 * Specifies how the name attribute is converted to the Java class name of
146 * the corresponding OM object
147 * @param pJavaNamingMethod java naming method
148 */
149 public final void setJavaNamingMethod(final String pJavaNamingMethod)
150 {
151 if (pJavaNamingMethod.equals("nochange")
152 || pJavaNamingMethod.equals("underscore")
153 || pJavaNamingMethod.equals("javaname"))
154 {
155 this.javaNamingMethod = pJavaNamingMethod;
156 }
157 else
158 {
159 this.javaNamingMethod = "underscore";
160 }
161 }
162 /***
163 * Set the table alias
164 * @param pAlias alias
165 */
166 public final void setAlias(final String pAlias)
167 {
168 this.alias = pAlias;
169 }
170 /***
171 * Used for OM Peer generation
172 * @param pBasePeer basepeer
173 */
174 public final void setBasePeer(final String pBasePeer)
175 {
176 this.basePeer = pBasePeer;
177 }
178 /***
179 * Used for OM Peer generation
180 * @param pBaseClass base class
181 */
182 public final void setBaseClass(final String pBaseClass)
183 {
184 this.baseClass = pBaseClass;
185 }
186 /***
187 * Set whether or not to generate the class as Abstract or not
188 * @param pAbstractClass is abstract
189 */
190 public final void setAbstractClass(final boolean pAbstractClass)
191 {
192 this.abstractClass = pAbstractClass;
193 if (pAbstractClass)
194 {
195 setSkipSql(true);
196 }
197 }
198 /***
199 * Set whether or not to skip SQL generation
200 * @param pSkipSql skip sql
201 */
202 public final void setSkipSql(final boolean pSkipSql)
203 {
204 this.skipSql = pSkipSql;
205 }
206 /***
207 * Set how will the primary keys be created
208 * @param pIdMethod id method
209 */
210 public final void setIdMethod(final String pIdMethod)
211 {
212 if (pIdMethod.equals("idbroker")
213 || pIdMethod.equals("native")
214 || pIdMethod.equals("autoincrement")
215 || pIdMethod.equals("none"))
216 {
217 this.idMethod = pIdMethod;
218 }
219 else
220 {
221 this.idMethod = "null";
222 }
223 }
224 /***
225 * Set how this table will be referenced in Java
226 * @param pJavaName javaname
227 */
228 public final void setJavaName(final String pJavaName)
229 {
230 this.javaName = pJavaName;
231 }
232 /***
233 * Initializes the list of fields with the Vector given as parameter
234 * @param pColumns columns
235 */
236 public final void setData(final Vector pColumns)
237 {
238 this.getColumns().removeAllElements();
239 for (int i = 0; i < pColumns.size(); i++)
240 {
241 Column newCol = new Column((Column) pColumns.elementAt(i));
242 newCol.setParent(this);
243 this.getColumns().addElement(newCol);
244 }
245
246 if (this.getMyModel() != null)
247 {
248 this.resetModelStatus();
249 this.getMyModel().getPanel().repaint();
250 }
251 this.dataChanged = true;
252 }
253 /***
254 * Set the heavyIndexibg Toque's flaf
255 * @return heavy indexing
256 */
257 public final boolean getHeavyIndexing()
258 {
259 return this.heavyIndexing;
260 }
261 /***
262 * Specifies how the name attribute is converted to the Java class name of
263 * the corresponding OM object
264 * @return javanaming method
265 */
266 public final String getJavaNamingMethod()
267 {
268 return this.javaNamingMethod;
269 }
270 /***
271 * Get the table alias
272 * @return alias
273 */
274 public final String getAlias()
275 {
276 return this.alias;
277 }
278 /***
279 * Used for OM Peer generation
280 * @return the base class
281 */
282 public final String getBaseClass()
283 {
284 return this.baseClass;
285 }
286 /***
287 * Used for OM Peer generation
288 * @return the base peer
289 */
290 public final String getBasePeer()
291 {
292 return this.basePeer;
293 }
294 /***
295 * Get whether or not to generate the class as Abstract or not
296 * @return is abstract
297 */
298 public final boolean getAbstractClass()
299 {
300 return this.abstractClass;
301 }
302 /***
303 * Get zhether or not to skip SQL generation
304 * @return skip sql
305 */
306 public final boolean getSkipSql()
307 {
308 return this.skipSql;
309 }
310 /***
311 * Set how will the primary keys be created
312 * @return id-method
313 */
314 public final String getIdMethod()
315 {
316 return this.idMethod;
317 }
318 /***
319 * Get how this table will be referenced in Java
320 * @return javaname
321 */
322 public final String getJavaName()
323 {
324 return this.javaName;
325 }
326 /***
327 * Return all the indexes of that table.
328 * @return indexes
329 */
330 public final Vector getIndexes()
331 {
332 return Indexes;
333 }
334 /***
335 * Return all the unique constraint of that table.
336 * @return unicity constraints
337 */
338 public final Vector getUniques()
339 {
340 return Uniques;
341 }
342 /***
343 * Set the indexes of a database.
344 * @param vector indexes
345 */
346 public final void setIndexes(final Vector vector)
347 {
348 Indexes = vector;
349 }
350 /***
351 * Set the uniques constraint of a database
352 * @param vector uniques
353 */
354 public final void setUniques(final Vector vector)
355 {
356 Uniques = vector;
357 }
358 /***
359 * Get Column for the given code
360 * @param pString the column code
361 * @return the column
362 */
363 public final Column getColumnForId(final String pString)
364 {
365 Column tmp = null;
366 for (int i = 0; i < getColumns().size(); i++)
367 {
368 if (((Column) this.getColumns().elementAt(i))
369 .getCode()
370 .equals(pString))
371 {
372 tmp = (Column) this.getColumns().elementAt(i);
373 }
374 }
375 return tmp;
376 }
377 }