1 24 25 package com.mckoi.database; 26 27 import java.util.ArrayList ; 28 import com.mckoi.util.BigNumber; 29 import com.mckoi.database.global.SQLTypes; 30 31 39 40 public class GTSQLTypeInfoDataSource extends GTDataSource { 41 42 46 private DatabaseConnection database; 47 48 51 private ArrayList key_value_pairs; 52 53 56 private static final BigNumber TYPE_NULLABLE = 57 BigNumber.fromInt(java.sql.DatabaseMetaData.typeNullable); 58 59 62 public GTSQLTypeInfoDataSource(DatabaseConnection connection) { 63 super(connection.getSystem()); 64 this.database = connection; 65 this.key_value_pairs = new ArrayList (); 66 } 67 68 71 private void addType(String name, int type, int precision, 72 String prefix, String suffix, String oops, 73 boolean searchable) { 74 key_value_pairs.add(name); 75 key_value_pairs.add(BigNumber.fromLong(type)); 76 key_value_pairs.add(BigNumber.fromLong(precision)); 77 key_value_pairs.add(prefix); 78 key_value_pairs.add(suffix); 79 key_value_pairs.add(searchable ? BigNumber.fromLong(3) : 80 BigNumber.fromLong(0)); 81 } 82 83 86 public GTSQLTypeInfoDataSource init() { 87 88 addType("BIT", SQLTypes.BIT, 1, null, null, null, true); 89 addType("BOOLEAN", SQLTypes.BIT, 1, null, null, null, true); 90 addType("TINYINT", SQLTypes.TINYINT, 9, null, null, null, true); 91 addType("SMALLINT", SQLTypes.SMALLINT, 9, null, null, null, true); 92 addType("INTEGER", SQLTypes.INTEGER, 9, null, null, null, true); 93 addType("BIGINT", SQLTypes.BIGINT, 9, null, null, null, true); 94 addType("FLOAT", SQLTypes.FLOAT, 9, null, null, null, true); 95 addType("REAL", SQLTypes.REAL, 9, null, null, null, true); 96 addType("DOUBLE", SQLTypes.DOUBLE, 9, null, null, null, true); 97 addType("NUMERIC", SQLTypes.NUMERIC, 9, null, null, null, true); 98 addType("DECIMAL", SQLTypes.DECIMAL, 9, null, null, null, true); 99 addType("CHAR", SQLTypes.CHAR, 9, "'", "'", null, true); 100 addType("VARCHAR", SQLTypes.VARCHAR, 9, "'", "'", null, true); 101 addType("LONGVARCHAR", SQLTypes.LONGVARCHAR, 9, "'", "'", null, true); 102 addType("DATE", SQLTypes.DATE, 9, null, null, null, true); 103 addType("TIME", SQLTypes.TIME, 9, null, null, null, true); 104 addType("TIMESTAMP", SQLTypes.TIMESTAMP, 9, null, null, null, true); 105 addType("BINARY", SQLTypes.BINARY, 9, null, null, null, false); 106 addType("VARBINARY", SQLTypes.VARBINARY, 9, null, null, null, false); 107 addType("LONGVARBINARY", SQLTypes.LONGVARBINARY, 108 9, null, null, null, false); 109 addType("JAVA_OBJECT", SQLTypes.JAVA_OBJECT, 9, null, null, null, false); 110 111 return this; 112 } 113 114 116 public DataTableDef getDataTableDef() { 117 return DEF_DATA_TABLE_DEF; 118 } 119 120 public int getRowCount() { 121 return key_value_pairs.size() / 6; 122 } 123 124 public TObject getCellContents(final int column, final int row) { 125 int i = (row * 6); 126 switch (column) { 127 case 0: return columnValue(column, (String ) key_value_pairs.get(i)); 129 case 1: return columnValue(column, (BigNumber) key_value_pairs.get(i + 1)); 131 case 2: return columnValue(column, (BigNumber) key_value_pairs.get(i + 2)); 133 case 3: return columnValue(column, (String ) key_value_pairs.get(i + 3)); 135 case 4: return columnValue(column, (String ) key_value_pairs.get(i + 4)); 137 case 5: return columnValue(column, null); 139 case 6: return columnValue(column, TYPE_NULLABLE); 141 case 7: return columnValue(column, Boolean.TRUE); 143 case 8: return columnValue(column, (BigNumber) key_value_pairs.get(i + 5)); 145 case 9: return columnValue(column, Boolean.FALSE); 147 case 10: return columnValue(column, Boolean.FALSE); 149 case 11: return columnValue(column, Boolean.FALSE); 151 case 12: return columnValue(column, null); 153 case 13: return columnValue(column, BigNumber.fromLong(0)); 155 case 14: return columnValue(column, BigNumber.fromLong(10000000)); 157 case 15: return columnValue(column, null); 159 case 16: return columnValue(column, null); 161 case 17: return columnValue(column, BigNumber.fromLong(10)); 163 default: 164 throw new Error ("Column out of bounds."); 165 } 166 } 167 168 170 public void dispose() { 171 super.dispose(); 172 key_value_pairs = null; 173 database = null; 174 } 175 176 178 181 static final DataTableDef DEF_DATA_TABLE_DEF; 182 183 static { 184 185 DataTableDef def = new DataTableDef(); 186 def.setTableName( 187 new TableName(Database.SYSTEM_SCHEMA, "sUSRSQLTypeInfo")); 188 189 def.addColumn( stringColumn("TYPE_NAME")); 191 def.addColumn(numericColumn("DATA_TYPE")); 192 def.addColumn(numericColumn("PRECISION")); 193 def.addColumn( stringColumn("LITERAL_PREFIX")); 194 def.addColumn( stringColumn("LITERAL_SUFFIX")); 195 def.addColumn( stringColumn("CREATE_PARAMS")); 196 def.addColumn(numericColumn("NULLABLE")); 197 def.addColumn(booleanColumn("CASE_SENSITIVE")); 198 def.addColumn(numericColumn("SEARCHABLE")); 199 def.addColumn(booleanColumn("UNSIGNED_ATTRIBUTE")); 200 def.addColumn(booleanColumn("FIXED_PREC_SCALE")); 201 def.addColumn(booleanColumn("AUTO_INCREMENT")); 202 def.addColumn( stringColumn("LOCAL_TYPE_NAME")); 203 def.addColumn(numericColumn("MINIMUM_SCALE")); 204 def.addColumn(numericColumn("MAXIMUM_SCALE")); 205 def.addColumn( stringColumn("SQL_DATA_TYPE")); 206 def.addColumn( stringColumn("SQL_DATETIME_SUB")); 207 def.addColumn(numericColumn("NUM_PREC_RADIX")); 208 209 def.setImmutable(); 211 212 DEF_DATA_TABLE_DEF = def; 213 214 } 215 216 } 217 | Popular Tags |