1 29 30 package com.caucho.quercus.lib.db; 31 32 import java.sql.DatabaseMetaData ; 33 import java.sql.ResultSet ; 34 import java.sql.SQLException ; 35 import java.sql.Types ; 36 37 40 public class JdbcColumnMetaData { 41 private final JdbcTableMetaData _table; 42 43 private final String _name; 44 45 private final int _jdbcType; 46 47 private final int _length; 48 49 private final boolean _isNotNull; 50 private final boolean _isUnsigned; 51 private final boolean _isZeroFill; 52 53 private boolean _isPrimaryKey; 54 private boolean _isIndex; 55 private boolean _isUnique; 56 57 60 public JdbcColumnMetaData(JdbcTableMetaData table, ResultSet rs) 61 throws SQLException 62 { 63 _table = table; 64 65 _name = rs.getString(4); 67 _jdbcType = rs.getInt(5); 69 _length = rs.getInt(7); 71 72 _isNotNull = rs.getInt(11) == DatabaseMetaData.columnNoNulls; 74 75 String type = rs.getString(6).toLowerCase(); 77 78 _isUnsigned = type.indexOf("unsigned") >= 0; 79 _isZeroFill = type.indexOf("zerofill") >= 0; 80 } 81 82 85 public String getName() 86 { 87 return _name; 88 } 89 90 93 public JdbcTableMetaData getTable() 94 { 95 return _table; 96 } 97 98 101 public int getLength() 102 { 103 return _length; 104 } 105 106 109 public boolean isNotNull() 110 { 111 return _isNotNull; 112 } 113 114 117 public boolean isPrimaryKey() 118 { 119 return _isPrimaryKey; 120 } 121 122 125 void setPrimaryKey(boolean isPrimaryKey) 126 { 127 _isPrimaryKey = isPrimaryKey; 128 } 129 130 133 public boolean isIndex() 134 { 135 return _isIndex; 136 } 137 138 141 void setIndex(boolean isIndex) 142 { 143 _isIndex = isIndex; 144 } 145 146 149 public boolean isUnique() 150 { 151 return _isUnique; 152 } 153 154 157 void setUnique(boolean isUnique) 158 { 159 _isUnique = isUnique; 160 } 161 162 165 public int getJdbcType() 166 { 167 return _jdbcType; 168 } 169 170 173 public static boolean isNumeric(int jdbcType) 174 { 175 switch (jdbcType) { 176 case Types.BIT: 177 case Types.TINYINT: 178 case Types.SMALLINT: 179 case Types.INTEGER: 180 case Types.BIGINT: 181 case Types.DOUBLE: 182 case Types.FLOAT: 183 case Types.REAL: 184 return true; 185 default: 186 return false; 187 } 188 } 189 190 193 public boolean isNumeric() 194 { 195 return isNumeric(_jdbcType); 196 } 197 198 201 public boolean isFloat() 202 { 203 switch (_jdbcType) { 204 case Types.DOUBLE: 205 case Types.FLOAT: 206 case Types.REAL: 207 return true; 208 default: 209 return false; 210 } 211 } 212 213 216 public boolean isUnsigned() 217 { 218 return _isUnsigned; 219 } 220 221 224 public boolean isZeroFill() 225 { 226 return _isZeroFill; 227 } 228 229 232 public static boolean isBlob(int jdbcType) 233 { 234 switch (jdbcType) { 235 case Types.LONGVARBINARY: 238 case Types.LONGVARCHAR: 239 case Types.BLOB: 240 case Types.CLOB: 241 return true; 242 default: 243 return false; 244 } 245 } 246 247 250 public boolean isBlob() 251 { 252 return isBlob(_jdbcType); 253 } 254 255 public String toString() 256 { 257 return "JdbcColumnMetaData[" + getName() + "]"; 258 } 259 } 260 261 | Popular Tags |