1 package com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors; 2 3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 4 import com.daffodilwoods.daffodildb.server.serversystem.*; 5 import com.daffodilwoods.daffodildb.server.sql99.common.*; 6 import com.daffodilwoods.daffodildb.server.sql99.ddl.utility.*; 7 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 8 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 9 import com.daffodilwoods.database.resource.*; 10 import com.daffodilwoods.database.utility.*; 11 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem.PrimaryConstraintException; 12 13 public class DataTypeDescriptor extends Descriptor { 14 15 public static final int implicit_maximum_characterLargeObject_length = 1073741823; public static final int implicit_maximum_character_length = 4192; 17 public static final int implicit_maximum_numeric_precision = 38; 18 public static final int implicit_maximum_numeric_scale = 38; 19 public static final int implicit_maximum_float_precision = 15; 20 public static final int implicit_numeric_precision_radix = 10; 21 public static final int implicit_maximum_time_precision = 9; 22 23 26 27 public String object_catalog; 28 public String object_schema; 29 public String object_name; 30 public String object_type; 31 public String dtd_identifier; 32 public String data_Type; 33 public Integer character_maximum_length; 34 public Integer character_octet_length; 35 public String collation_catalog; 36 public String collation_schema; 37 public String collation_name; 38 public Integer numeric_precision; 39 public Integer numeric_precision_radix; 40 public Integer numeric_scal; 41 public Integer datatime_precision; 42 public String interval_type; 43 public String interval_precision; 44 public String user_defined_type_catalog; 45 public String user_defined_type_schema; 46 public String user_defined_type_name; 47 public String scope_catalog; 48 public String scope_schema; 49 public String scope_name; 50 public Integer maximum_cardinality; 51 52 private int type = -1; 53 54 public DataTypeDescriptor() throws DException { 55 } 56 57 public void load(_ServerSession serverSession) throws DException { 58 DataDictionary dd = (DataDictionary) serverSession.getDataDictionary(); 59 _SelectQueryIterator dtds = (_SelectQueryIterator) dd.getPreparedStatementGetter(). 60 getDataTypeDescriptorTableExecuter().executeForFresh(new Object [] { 61 object_catalog, object_schema, object_name, object_type, dtd_identifier}); 62 if (!dtds.first()) { 63 dtds.first(); 64 65 66 67 68 throw new DException("DSE295", null); 69 } 70 loadDataFromRecord( (Object []) dtds.getObject()); 71 } 72 73 public void loadDataFromRecord(_SelectQueryIterator iter) throws DException { 74 loadDataFromRecord( (Object []) iter.getObject()); 75 } 76 77 private void loadDataFromRecord(Object [] dataValues) throws DException { 78 object_catalog = (String ) dataValues[SystemTablesFields. 79 data_type_descriptor_object_catalog]; 80 object_schema = (String ) dataValues[SystemTablesFields. 81 data_type_descriptor_object_schema]; 82 object_name = (String ) dataValues[SystemTablesFields. 83 data_type_descriptor_object_name]; 84 object_type = (String ) dataValues[SystemTablesFields. 85 data_type_descriptor_object_type]; 86 dtd_identifier = (String ) dataValues[SystemTablesFields. 87 data_type_descriptor_dtd_identifier]; 88 data_Type = (String ) dataValues[SystemTablesFields. 89 data_type_descriptor_data_type]; 90 character_maximum_length = (Integer ) dataValues[SystemTablesFields. 91 data_type_descriptor_character_maximum_length]; 92 character_octet_length = (Integer ) dataValues[SystemTablesFields. 93 data_type_descriptor_character_octet_length]; 94 collation_catalog = (String ) dataValues[SystemTablesFields. 95 data_type_descriptor_collation_catalog]; 96 collation_schema = (String ) dataValues[SystemTablesFields. 97 data_type_descriptor_collation_schema]; 98 collation_name = (String ) dataValues[SystemTablesFields. 99 data_type_descriptor_collation_name]; 100 numeric_precision = (Integer ) dataValues[SystemTablesFields. 101 data_type_descriptor_numeric_precision]; 102 numeric_precision_radix = (Integer ) dataValues[SystemTablesFields. 103 data_type_descriptor_numeric_precision_radix]; 104 numeric_scal = (Integer ) dataValues[SystemTablesFields. 105 data_type_descriptor_numeric_scale]; 106 datatime_precision = (Integer ) dataValues[SystemTablesFields. 107 data_type_descriptor_datetime_precision]; 108 interval_type = (String ) dataValues[SystemTablesFields. 109 data_type_descriptor_interval_type]; 110 interval_precision = (String ) dataValues[SystemTablesFields. 111 data_type_descriptor_interval_precision]; 112 user_defined_type_catalog = (String ) dataValues[SystemTablesFields. 113 data_type_descriptor_user_defined_type_catalog]; 114 user_defined_type_schema = (String ) dataValues[SystemTablesFields. 115 data_type_descriptor_user_defined_type_schema]; 116 user_defined_type_name = (String ) dataValues[SystemTablesFields. 117 data_type_descriptor_user_defined_type_name]; 118 scope_catalog = (String ) dataValues[SystemTablesFields. 119 data_type_descriptor_scope_catlog]; 120 scope_schema = (String ) dataValues[SystemTablesFields. 121 data_type_descriptor_scope_schema]; 122 scope_name = (String ) dataValues[SystemTablesFields. 123 data_type_descriptor_scope_name]; 124 maximum_cardinality = (Integer ) dataValues[SystemTablesFields. 125 data_type_descriptor_maximum_cardinality]; 126 } 127 128 public void save(_ServerSession serverSession) throws DException { 129 Object [] columnValues = new Object [] { 130 object_catalog, object_schema, object_name, 131 object_type, dtd_identifier, data_Type, character_maximum_length, 132 character_octet_length, collation_catalog, 133 collation_schema, collation_name, numeric_precision, 134 numeric_precision_radix, numeric_scal, 135 datatime_precision, interval_type, interval_precision, 136 user_defined_type_catalog, user_defined_type_schema, 137 user_defined_type_name, 138 scope_catalog, scope_schema, scope_name, maximum_cardinality}; 139 try { 140 SqlSchemaConstants.insert(serverSession, 141 SqlSchemaConstants.dataTypeDescriptor_TableName, null, 142 columnValues); 143 } catch (PrimaryConstraintException de) { 144 DException tde = new DException("DSE1137", new Object [] {object_name}); 145 throw tde; 146 } catch (DException de) { 147 if (de.getDseCode().equals("DSE1255")) { 148 DException tde = new DException("DSE1137", new Object [] {object_name}); 149 throw tde; 150 } 151 throw de; 152 } 153 } 154 155 public void delete(_ServerSession serverSession) throws DException { 156 booleanvalueexpression condition = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getDataTypeDescriptorTableCondition(); 157 super.deleteDataTypeDescriptor(serverSession, SqlSchemaConstants.dataTypeDescriptor_TableName, condition, new Object [] {object_catalog, object_schema, object_name, object_type, dtd_identifier}); 158 } 159 160 public boolean isFixedLength() throws DException { 161 String data_Type = this.data_Type.toLowerCase(); 162 return (data_Type.indexOf("clob") != -1 || 163 data_Type.indexOf("var") != -1 || 164 data_Type.indexOf("large") != -1 || 165 data_Type.indexOf("blob") != -1 || 166 data_Type.indexOf("dec") != -1 || 167 data_Type.indexOf("bigdecimal") != -1 || 168 data_Type.indexOf("decimal") != -1 || 169 data_Type.indexOf("numeric") != -1 || 170 data_Type.equalsIgnoreCase("array")) ? false : true; 171 } 172 173 public boolean isStringLargeObjectOrArrayType() throws DException { 174 String data_Type = this.data_Type.toLowerCase(); 175 return (data_Type.indexOf("clob") != -1 || 176 data_Type.indexOf("long varchar") != -1 || 177 data_Type.indexOf("binary") != -1 || 178 data_Type.indexOf("varbinary") != -1 || 179 data_Type.indexOf("long varbinary") != -1 || 180 data_Type.indexOf("large") != -1 || 181 data_Type.indexOf("blob") != -1 || 182 data_Type.equalsIgnoreCase("array")); 183 } 184 185 public boolean isApproximateNumericType() throws DException { 186 String data_Type = this.data_Type.toLowerCase(); 187 return (data_Type.indexOf("real") != -1 || 188 data_Type.indexOf("float") != -1 || 189 data_Type.indexOf("double precision") != -1 || 190 data_Type.indexOf("sum") != -1); 191 } 192 193 public int getDescriptorType() { 194 return DATA_TYPE_DESCRIPTOR; 195 } 196 197 public boolean isCharacterType() { 198 return character_maximum_length != null; 199 } 200 201 public boolean isNumericType() { 202 return numeric_precision != null; 203 } 204 205 public boolean isDateTimeType() { 206 return datatime_precision != null; 207 } 208 209 public boolean isBitType() { 210 return data_Type.equalsIgnoreCase(SqlKeywords.BIT); 211 } 212 213 public boolean isBitVaryingType() { 214 return data_Type.equalsIgnoreCase(SqlSchemaConstants.BitVaryingType); 215 } 216 217 public boolean isBooleanType() { 218 return data_Type.equalsIgnoreCase(SqlKeywords.BOOLEAN); 219 } 220 221 222 public boolean isBinaryType() { 223 return character_octet_length != null && 224 character_octet_length.intValue() != 0; 225 } 226 227 228 229 public boolean isDateType() { 230 return data_Type.equalsIgnoreCase(SqlKeywords.DATE); 231 } 232 233 public boolean isTimeType() { 234 return data_Type.equalsIgnoreCase(SqlKeywords.TIME); 235 } 236 237 public boolean isTimestampType() { 238 return data_Type.equalsIgnoreCase(SqlKeywords.TIMESTAMP); 239 } 240 241 public int getCharacterLength() { 242 int character_length = character_maximum_length == null 243 ? 0 244 : character_maximum_length.hashCode(); 245 return character_length; 246 } 247 248 public int getType() throws DException { 249 if (type == -1) { 250 type = TypeConverter.getDataBaseType(data_Type); 251 } 252 return type; 253 } 254 255 public int getBytesCount() throws DException { 256 int numPecision = numeric_precision == null ? 0 : 257 numeric_precision.hashCode(); 258 int charLength = character_maximum_length == null ? 0 : 259 character_maximum_length.hashCode(); 260 int datePrecision = datatime_precision == null ? 0 : 261 datatime_precision.hashCode(); 262 int intervalPrecision = interval_precision == null ? 0 : 263 interval_precision.hashCode(); 264 return GeneralUtility.getBytesCount(getType(), GeneralUtility.getPrecision(charLength, numPecision, datePrecision, intervalPrecision)); 265 } 266 267 public int getPrecision() throws DException { 268 int numPecision = numeric_precision == null ? 0 : 269 numeric_precision.hashCode(); 270 int charLength = character_maximum_length == null ? 0 : 271 character_maximum_length.hashCode(); 272 int datePrecision = datatime_precision == null ? 0 : 273 datatime_precision.hashCode(); 274 int intervalPrecision = interval_precision == null ? 0 : 275 interval_precision.hashCode(); 276 return GeneralUtility.getPrecision(charLength, numPecision, datePrecision, intervalPrecision); 277 } 278 279 public int getScale() throws DException { 280 return numeric_scal == null ? 0 : numeric_scal.hashCode(); 281 } 282 } 283 | Popular Tags |