KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb > DBColumn


1 package org.apache.ojb.tools.mapping.reversedb;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /**
19  *
20  * @author <a HREF="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
21  * @version $Id: DBColumn.java,v 1.1.2.1 2005/12/21 22:32:04 tomdz Exp $
22  */

23 public class DBColumn implements MetadataNodeInterface, javax.swing.tree.TreeNode JavaDoc, org.apache.ojb.tools.mapping.reversedb.gui.PropertySheetModel
24 {
25   private DBTable aTable;
26   private String JavaDoc strColumnName;
27   private String JavaDoc strJavaFieldName;
28   private String JavaDoc strJavaFieldType;
29   private int iColumnType;
30   private String JavaDoc strColumnTypeName;
31   private boolean isPrimaryKeyPart = false;
32   private boolean bAutoIncrement = false;
33   
34   
35   private boolean enabled = true;
36   
37   
38   /** Creates a new instance of DBColumn */
39   
40   public DBColumn (java.sql.DatabaseMetaData JavaDoc pdbMeta, DBTable paTable,
41                    String JavaDoc pstrColumnName, int piColumnType,
42                    String JavaDoc pstrColumnTypeName)
43   {
44     aTable = paTable;
45     strColumnName = pstrColumnName;
46 /* this.strJavaFieldName = Character.toLowerCase(pstrColumnName.charAt(0))
47       + pstrColumnName.substring(1);*/

48     this.strJavaFieldName = Namer.nameField(this.strColumnName);
49     iColumnType = piColumnType;
50     this.strJavaFieldType = Utilities.hmJDBCTypeToJavaType.get(new Integer JavaDoc(iColumnType)).toString();
51     strColumnTypeName = pstrColumnTypeName;
52   }
53   
54   public boolean getAutoIncrement()
55   {
56     return this.bAutoIncrement;
57   }
58   
59   public void setAutoIncrement(boolean b)
60   {
61     this.bAutoIncrement = b;
62   }
63   
64   public boolean isEnabled()
65   {
66     return this.enabled;
67   }
68   
69   public void setEnabled(boolean b)
70   {
71     this.enabled = b;
72   }
73   
74   public int getColumnType()
75   {
76     return this.iColumnType;
77   }
78   
79   public String JavaDoc getJavaFieldName()
80   {
81     return this.strJavaFieldName;
82   }
83   
84   public void setJavaFieldName(String JavaDoc s)
85   {
86     this.strJavaFieldName = s;
87   }
88   
89   public String JavaDoc getJavaFieldType()
90   {
91     return this.strJavaFieldType;
92   }
93   
94   public void setJavaFieldType(String JavaDoc s)
95   {
96     this.strJavaFieldType = s;
97   }
98   
99   public void setColumnType(int i)
100   {
101     this.iColumnType = i;
102   }
103   
104   public void setColumnType(String JavaDoc s)
105   {
106     Integer JavaDoc i = (Integer JavaDoc)Utilities.mJDBCNameToType.get(s);
107     if (i != null)
108     {
109       this.iColumnType = i.intValue();
110     }
111   }
112   
113   public String JavaDoc getColumnTypeName()
114   {
115     return this.strColumnTypeName;
116   }
117   
118   public DBTable getDBTable()
119   {
120     return this.aTable;
121   }
122   
123   public boolean isTreeEnabled()
124   {
125     return this.aTable.isTreeEnabled() && this.isEnabled();
126   }
127   
128
129   public void read()
130     throws java.sql.SQLException JavaDoc
131   {
132   }
133   
134   public void generateReferences()
135     throws java.sql.SQLException JavaDoc
136   {
137   }
138   
139   public void setPrimaryKeyPart(boolean b)
140   {
141     this.isPrimaryKeyPart = b;
142   }
143   
144   public boolean isPrimaryKeyPart()
145   {
146     return this.isPrimaryKeyPart;
147   }
148   
149   public String JavaDoc getColumnName()
150   {
151     return this.strColumnName;
152   }
153   
154   public java.util.Enumeration JavaDoc children ()
155   {
156     return null;
157   }
158   
159   public boolean getAllowsChildren ()
160   {
161     return false;
162   }
163   
164   public javax.swing.tree.TreeNode JavaDoc getChildAt (int param)
165   {
166     return null;
167   }
168   
169   public int getChildCount ()
170   {
171     return 0;
172   }
173   
174   public int getIndex (javax.swing.tree.TreeNode JavaDoc treeNode)
175   {
176     return 0;
177   }
178   
179   public javax.swing.tree.TreeNode JavaDoc getParent ()
180   {
181     return this.aTable;
182   }
183   
184   public boolean isLeaf ()
185   {
186     return true;
187   }
188
189   public String JavaDoc toString()
190   {
191     if (this.isPrimaryKeyPart) return strColumnName + " (PK)";
192     else return this.strColumnName;
193   }
194
195   
196   public Class JavaDoc getPropertySheetClass ()
197   {
198     return org.apache.ojb.tools.mapping.reversedb.gui.DBColumnPropertySheet.class;
199   }
200   
201   public String JavaDoc getXML()
202   {
203     if (this.isTreeEnabled())
204     {
205         java.io.StringWriter JavaDoc sw = new java.io.StringWriter JavaDoc();
206         writeXML(new java.io.PrintWriter JavaDoc(sw));
207         return sw.getBuffer().toString();
208 /*
209       String strReturn =
210           " <field-descriptor id=\"" + this.id + "\"" + System.getProperty("line.separator")
211        + " name=\"" + this.strJavaFieldName + "\"" + System.getProperty("line.separator")
212        + " column=\"" + this.strColumnName + "\"" + System.getProperty("line.separator")
213        + " jdbc-type=\"" + Utilities.hmJDBCTypeToName.get(new Integer(this.iColumnType)) + "\"" + System.getProperty("line.separator");
214       if (this.isPrimaryKeyPart())
215           strReturn += " primarykey=\"true\"" + System.getProperty("line.separator");
216       if (this.getAutoIncrement())
217           strReturn += " <autoincrement>true</autoincrement>" + System.getProperty("line.separator");
218       strReturn += " />";
219       return strReturn;
220  */

221     }
222     else return "";
223  
224   }
225   
226   public void writeXML(java.io.PrintWriter JavaDoc pw)
227   {
228       pw.println(" <field-descriptor ");
229       pw.println(" name=\"" + this.strJavaFieldName + "\"");
230       pw.println(" column=\"" + this.strColumnName + "\"");
231       pw.println(" jdbc-type=\"" + Utilities.hmJDBCTypeToName.get(new Integer JavaDoc(this.iColumnType)) + "\"" );
232       if (this.isPrimaryKeyPart())
233           pw.println( " primarykey=\"true\"" );
234       if (this.getAutoIncrement())
235           pw.println( " <autoincrement>true</autoincrement>");
236       pw.println(" />");
237   }
238   
239   public void generateJava (java.io.File JavaDoc aFile, String JavaDoc strHeader, String JavaDoc strFooter) throws java.io.IOException JavaDoc, java.io.FileNotFoundException JavaDoc
240   {
241     throw new UnsupportedOperationException JavaDoc("Generate Java on DBColumn is not allowed");
242   }
243   
244   public void setPackage (String JavaDoc packageName)
245   {
246     throw new UnsupportedOperationException JavaDoc("Set Package on DBColumn is not allowed");
247   }
248   
249   public String JavaDoc getJavaFieldDefinition()
250   {
251     if (this.isTreeEnabled())
252     {
253       return " private " + this.getJavaFieldType() + " " + this.getJavaFieldName() + ";";
254     }
255     else return "";
256   }
257   
258    public String JavaDoc getJavaGetterSetterDefinition()
259   {
260     if (this.isTreeEnabled())
261     {
262       String JavaDoc strReturn = "";
263       strReturn = " public " + this.getJavaFieldType() + " get"
264         + this.getJavaFieldName().substring(0,1).toUpperCase()
265         + this.getJavaFieldName().substring(1) + "()"
266         + System.getProperty("line.separator");
267
268       strReturn += " {" + System.getProperty("line.separator");
269       strReturn += " return this." + this.getJavaFieldName() + ";" + System.getProperty("line.separator");
270       strReturn += " }" + System.getProperty("line.separator");
271       strReturn += " public void set"
272         + this.getJavaFieldName().substring(0,1).toUpperCase()
273         + this.getJavaFieldName().substring(1) + "(" + this.getJavaFieldType() + " param)"
274         + System.getProperty("line.separator");
275       strReturn += " {" + System.getProperty("line.separator");
276       strReturn += " this." + this.getJavaFieldName() + " = param;" + System.getProperty("line.separator");
277       strReturn += " }" + System.getProperty("line.separator");
278       return strReturn;
279     }
280     else return "";
281   }
282
283   /**
284    * @deprecated
285    */

286   public int getId()
287   {
288     return 0;
289   }
290   
291 }
292
293 /***************************** Changelog *****************************
294 // $Log: DBColumn.java,v $
295 // Revision 1.1.2.1 2005/12/21 22:32:04 tomdz
296 // Updated license
297 //
298 // Revision 1.1 2004/05/05 16:39:05 arminw
299 // fix fault
300 // wrong package structure used:
301 // org.apache.ojb.tools.reversdb
302 // org.apache.ojb.tools.reversdb2
303 //
304 // instead of
305 // org.apache.ojb.tools.mapping.reversdb
306 // org.apache.ojb.tools.mapping.reversdb2
307 //
308 // Revision 1.1 2004/05/04 13:45:00 arminw
309 // move reverseDB stuff
310 //
311 // Revision 1.9 2004/04/04 23:53:42 brianm
312 // Fixed initial copyright dates to match cvs repository
313 //
314 // Revision 1.8 2004/03/11 18:16:22 brianm
315 // ASL 2.0
316 //
317 // Revision 1.7 2003/12/12 16:37:16 brj
318 // removed unnecessary casts, semicolons etc.
319 //
320 // Revision 1.6 2003/07/22 11:05:13 florianbruckner
321 // add a name beautifier (courtesy G.Wayne Kidd)
322 //
323 // Revision 1.5 2003/06/21 10:27:45 florianbruckner
324 // implement XML generation with PrintWriter; getXML() still works and uses writeXML(java.io.PrintWriter)
325 // getId() is deprecated and returns 0 now; Ids are not used for XML generation.
326 //
327 // Revision 1.4 2003/01/28 21:42:53 florianbruckner
328 // update XML generation
329 //
330 // Revision 1.3 2003/01/28 19:59:14 florianbruckner
331 // some updates to schema reading to make it a bit more compatible
332 //
333 // Revision 1.2 2002/06/17 19:34:33 jvanzyl
334 // Correcting all the package references.
335 // PR:
336 // Obtained from:
337 // Submitted by:
338 // Reviewed by:
339 //
340 // Revision 1.1.1.1 2002/06/17 18:16:51 jvanzyl
341 // Initial OJB import
342 //
343 // Revision 1.2 2002/05/16 11:47:09 florianbruckner
344 // fix CR/LF issue, change license to ASL
345 //
346 // Revision 1.1 2002/04/18 11:44:16 mpoeschl
347 //
348 // move files to new location
349 //
350 // Revision 1.4 2002/04/09 17:08:32 thma
351 // *** empty log message ***
352 //
353 // Revision 1.3 2002/04/07 09:05:16 thma
354 // *** empty log message ***
355 //
356 // Revision 1.2 2002/03/11 17:36:05 florianbruckner
357 // fix line break issue for these files that were previously checked in with -kb
358 //
359 // Revision 1.1 2002/03/04 17:19:32 thma
360 // initial checking for Florians Reverse engineering tool
361 //
362 // Revision 1.1.1.1 2002/02/20 13:35:25 Administrator
363 // initial import
364 //
365 /***************************** Changelog *****************************/

366
Popular Tags