1 package org.apache.ojb.tools.mapping.reversedb; 2 3 17 18 23 public class DBColumn implements MetadataNodeInterface, javax.swing.tree.TreeNode , org.apache.ojb.tools.mapping.reversedb.gui.PropertySheetModel 24 { 25 private DBTable aTable; 26 private String strColumnName; 27 private String strJavaFieldName; 28 private String strJavaFieldType; 29 private int iColumnType; 30 private String strColumnTypeName; 31 private boolean isPrimaryKeyPart = false; 32 private boolean bAutoIncrement = false; 33 34 35 private boolean enabled = true; 36 37 38 39 40 public DBColumn (java.sql.DatabaseMetaData pdbMeta, DBTable paTable, 41 String pstrColumnName, int piColumnType, 42 String pstrColumnTypeName) 43 { 44 aTable = paTable; 45 strColumnName = pstrColumnName; 46 48 this.strJavaFieldName = Namer.nameField(this.strColumnName); 49 iColumnType = piColumnType; 50 this.strJavaFieldType = Utilities.hmJDBCTypeToJavaType.get(new Integer (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 getJavaFieldName() 80 { 81 return this.strJavaFieldName; 82 } 83 84 public void setJavaFieldName(String s) 85 { 86 this.strJavaFieldName = s; 87 } 88 89 public String getJavaFieldType() 90 { 91 return this.strJavaFieldType; 92 } 93 94 public void setJavaFieldType(String 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 s) 105 { 106 Integer i = (Integer )Utilities.mJDBCNameToType.get(s); 107 if (i != null) 108 { 109 this.iColumnType = i.intValue(); 110 } 111 } 112 113 public String 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 131 { 132 } 133 134 public void generateReferences() 135 throws java.sql.SQLException 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 getColumnName() 150 { 151 return this.strColumnName; 152 } 153 154 public java.util.Enumeration children () 155 { 156 return null; 157 } 158 159 public boolean getAllowsChildren () 160 { 161 return false; 162 } 163 164 public javax.swing.tree.TreeNode 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 treeNode) 175 { 176 return 0; 177 } 178 179 public javax.swing.tree.TreeNode getParent () 180 { 181 return this.aTable; 182 } 183 184 public boolean isLeaf () 185 { 186 return true; 187 } 188 189 public String toString() 190 { 191 if (this.isPrimaryKeyPart) return strColumnName + " (PK)"; 192 else return this.strColumnName; 193 } 194 195 196 public Class getPropertySheetClass () 197 { 198 return org.apache.ojb.tools.mapping.reversedb.gui.DBColumnPropertySheet.class; 199 } 200 201 public String getXML() 202 { 203 if (this.isTreeEnabled()) 204 { 205 java.io.StringWriter sw = new java.io.StringWriter (); 206 writeXML(new java.io.PrintWriter (sw)); 207 return sw.getBuffer().toString(); 208 221 } 222 else return ""; 223 224 } 225 226 public void writeXML(java.io.PrintWriter 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 (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 aFile, String strHeader, String strFooter) throws java.io.IOException , java.io.FileNotFoundException 240 { 241 throw new UnsupportedOperationException ("Generate Java on DBColumn is not allowed"); 242 } 243 244 public void setPackage (String packageName) 245 { 246 throw new UnsupportedOperationException ("Set Package on DBColumn is not allowed"); 247 } 248 249 public String getJavaFieldDefinition() 250 { 251 if (this.isTreeEnabled()) 252 { 253 return " private " + this.getJavaFieldType() + " " + this.getJavaFieldName() + ";"; 254 } 255 else return ""; 256 } 257 258 public String getJavaGetterSetterDefinition() 259 { 260 if (this.isTreeEnabled()) 261 { 262 String 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 286 public int getId() 287 { 288 return 0; 289 } 290 291 } 292 293 366 | Popular Tags |