1 10 11 package com.triactive.jdo.store; 12 13 import java.io.PrintWriter ; 14 import java.io.StringWriter ; 15 import java.sql.DatabaseMetaData ; 16 import java.sql.ResultSet ; 17 import java.sql.SQLException ; 18 import java.sql.Types ; 19 import javax.jdo.JDOFatalDataStoreException; 20 21 22 39 40 class ColumnInfo 41 { 42 45 public String tableCat; 46 47 50 public String tableSchem; 51 52 55 public String tableName; 56 57 60 public String columnName; 61 62 65 public short dataType; 66 67 70 public String typeName; 71 72 76 public int columnSize; 77 78 81 public int decimalDigits; 82 83 86 public int numPrecRadix; 87 88 95 public int nullable; 96 97 100 public String remarks; 101 102 105 public String columnDef; 106 107 111 public int charOctetLength; 112 113 117 public int ordinalPosition; 118 119 125 public String isNullable; 126 127 128 private int hash = 0; 129 130 131 145 146 public ColumnInfo(ResultSet rs) throws JDOFatalDataStoreException 147 { 148 try 149 { 150 tableCat = rs.getString(1); 151 tableSchem = rs.getString(2); 152 tableName = rs.getString(3); 153 columnName = rs.getString(4); 154 dataType = rs.getShort(5); 155 typeName = rs.getString(6); 156 columnSize = rs.getInt(7); 157 decimalDigits = rs.getInt(9); 158 numPrecRadix = rs.getInt(10); 159 nullable = rs.getInt(11); 160 remarks = rs.getString(12); 161 columnDef = rs.getString(13); 162 charOctetLength = rs.getInt(16); 163 ordinalPosition = rs.getInt(17); 164 isNullable = rs.getString(18); 165 } 166 catch (SQLException e) 167 { 168 throw new JDOFatalDataStoreException("Can't read JDBC metadata from result set", e); 169 } 170 171 if (dataType == Types.OTHER) 172 { 173 178 String upperTypeName = typeName.toUpperCase(); 179 180 if (upperTypeName.equals("BLOB")) 181 dataType = Types.BLOB; 182 else if (upperTypeName.equals("CLOB")) 183 dataType = Types.CLOB; 184 else if (upperTypeName.equals("FLOAT")) 185 dataType = Types.FLOAT; 186 else if (upperTypeName.endsWith("LONGVARBINARY")) 187 dataType = Types.LONGVARBINARY; 188 else if (upperTypeName.endsWith("LONGVARCHAR")) 189 dataType = Types.LONGVARCHAR; 190 } 191 } 192 193 194 200 201 public ColumnInfo(String tableCat, 202 String tableSchem, 203 String tableName, 204 String columnName, 205 short dataType, 206 String typeName, 207 int columnSize, 208 int decimalDigits, 209 int numPrecRadix, 210 int nullable, 211 String remarks, 212 String columnDef, 213 int charOctetLength, 214 int ordinalPosition, 215 String isNullable) 216 { 217 this.tableCat = tableCat; 218 this.tableSchem = tableSchem; 219 this.tableName = tableName; 220 this.columnName = columnName; 221 this.dataType = dataType; 222 this.typeName = typeName; 223 this.columnSize = columnSize; 224 this.decimalDigits = decimalDigits; 225 this.numPrecRadix = numPrecRadix; 226 this.nullable = nullable; 227 this.remarks = remarks; 228 this.columnDef = columnDef; 229 this.charOctetLength = charOctetLength; 230 this.ordinalPosition = ordinalPosition; 231 this.isNullable = isNullable; 232 } 233 234 235 245 246 public final boolean equals(Object obj) 247 { 248 if (obj == this) 249 return true; 250 251 if (!(obj instanceof ColumnInfo)) 252 return false; 253 254 ColumnInfo ci = (ColumnInfo)obj; 255 256 return (tableCat == null ? ci.tableCat == null : tableCat.equals(ci.tableCat)) 257 && (tableSchem == null ? ci.tableSchem == null : tableSchem.equals(ci.tableSchem)) 258 && tableName.equals(ci.tableName) 259 && columnName.equals(ci.columnName); 260 } 261 262 263 268 269 public final int hashCode() 270 { 271 if (hash == 0) 272 { 273 hash = (tableCat == null ? 0 : tableCat.hashCode()) 274 ^ (tableSchem == null ? 0 : tableSchem.hashCode()) 275 ^ tableName.hashCode() 276 ^ columnName.hashCode(); 277 } 278 279 return hash; 280 } 281 282 283 288 289 public String toString() 290 { 291 StringWriter sw = new StringWriter (); 292 PrintWriter pw = new PrintWriter (sw); 293 294 pw.println(this.getClass().getName()); 295 pw.print(" tableCat = "); pw.println(tableCat); 296 pw.print(" tableSchem = "); pw.println(tableSchem); 297 pw.print(" tableName = "); pw.println(tableName); 298 pw.print(" columnName = "); pw.println(columnName); 299 pw.print(" dataType = "); pw.println(dataType); 300 pw.print(" typeName = "); pw.println(typeName); 301 pw.print(" columnSize = "); pw.println(columnSize); 302 pw.print(" decimalDigits = "); pw.println(decimalDigits); 303 pw.print(" numPrecRadix = "); pw.println(numPrecRadix); 304 pw.print(" nullable = "); pw.println(nullable); 305 pw.print(" remarks = "); pw.println(remarks); 306 pw.print(" columnDef = "); pw.println(columnDef); 307 pw.print(" charOctetLength = "); pw.println(charOctetLength); 308 pw.print(" ordinalPosition = "); pw.println(ordinalPosition); 309 pw.print(" isNullable = "); pw.println(isNullable); 310 pw.close(); 311 312 return sw.toString(); 313 } 314 } 315 | Popular Tags |