1 22 package org.jboss.test.cmp2.dbschema.util; 23 24 import java.sql.ResultSet ; 25 import java.sql.SQLException ; 26 27 28 32 public final class Column 33 { 34 private static final String TABLE_NAME = "TABLE_NAME"; 35 private static final String COLUMN_NAME = "COLUMN_NAME"; 36 private static final String DATA_TYPE = "DATA_TYPE"; 37 private static final String TYPE_NAME = "TYPE_NAME"; 38 private static final String COLUMN_SIZE = "COLUMN_SIZE"; 39 private static final String IS_NULLABLE = "IS_NULLABLE"; 40 private static final String COLUMN_DEF = "COLUMN_DEF"; 41 42 private final String tableName; 43 private final String name; 44 private final short dataType; 45 private final String typeName; 46 private final int columnSize; 47 private final String nullable; 48 private final String columnDef; 49 50 52 public Column(ResultSet rs) throws SQLException 53 { 54 tableName = rs.getString(TABLE_NAME); 55 name = rs.getString(COLUMN_NAME); 56 dataType = rs.getShort(DATA_TYPE); 57 typeName = rs.getString(TYPE_NAME); 58 columnSize = rs.getInt(COLUMN_SIZE); 59 nullable = rs.getString(IS_NULLABLE); 60 columnDef = rs.getString(COLUMN_DEF); 61 } 62 63 65 public String getTableName() 66 { 67 return tableName; 68 } 69 70 public String getName() 71 { 72 return name; 73 } 74 75 public short getDataType() 76 { 77 return dataType; 78 } 79 80 public String getTypeName() 81 { 82 return typeName; 83 } 84 85 public int getColumnSize() 86 { 87 return columnSize; 88 } 89 90 public boolean isNotNullable() 91 { 92 return nullable.equalsIgnoreCase("NO"); 93 } 94 95 public String getColumnDef() 96 { 97 return columnDef; 98 } 99 100 public void assertName(String name) throws Exception 101 { 102 if(this.name.equals(name)) 103 return; 104 throw new Exception ("Column name: is " + this.name + " but expected " + name); 105 } 106 107 public void assertDataType(int dataType) throws Exception 108 { 109 if(this.dataType == dataType) 110 return; 111 throw new Exception ("Data type: is " + this.dataType + " but expected " + dataType); 112 } 113 114 public void assertNotNull(boolean notNullable) throws Exception 115 { 116 if(this.nullable.equalsIgnoreCase("NO") == notNullable) 117 return; 118 throw new Exception ("Column not nullable: is " + !notNullable + " but expected " + notNullable); 119 } 120 121 public void assertTypeNotNull(int dataType, boolean notNull) throws Exception 122 { 123 assertDataType(dataType); 124 assertNotNull(notNull); 125 } 126 127 public String toString() 128 { 129 StringBuffer sb = new StringBuffer (); 130 sb.append('['). 131 append(TABLE_NAME).append('=').append(tableName).append(';'). 132 append(COLUMN_NAME).append('=').append(name).append(';'). 133 append(DATA_TYPE).append('=').append(dataType).append(';'). 134 append(TYPE_NAME).append('=').append(typeName).append(';'). 135 append(COLUMN_SIZE).append('=').append(columnSize).append(';'). 136 append(IS_NULLABLE).append('=').append(nullable).append(';'). 137 append(COLUMN_DEF).append('=').append(columnDef).append(';'). 138 append(']'); 139 return sb.toString(); 140 } 141 } 142 | Popular Tags |