| 1 package com.daffodilwoods.daffodildb.server.datadictionarysystem; 2 3 import java.io.*; 4 import java.util.*; 5 6 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 7 import com.daffodilwoods.database.general.*; 8 import com.daffodilwoods.database.resource.*; 9 10 public class SystemTablesCreator { 11 public final static Integer SQLIdentifierSize = new Integer (128); 12 public final static Integer characterDataSize = new Integer (1026); 13 public final static Integer viewDefinitionSize = new Integer (4096); 14 public final static Integer dtdIdentifierSize = new Integer (257); 15 public final static Integer serializeObjectDataSize = new Integer (12000); 16 17 public final static String domainCatalog = "system"; 18 public final static String domainSchema = "information_schema"; 19 public final static String sqlIdentifier = "sql_Identifier"; 20 public final static String characterData = "character_data"; 21 public final static String cardinalNumber = "cardinal_number"; 22 public final static String timeStamp = "time_stamp"; 23 public final static String transactionIndexTable = "default_index_transactionId"; 24 public final static String sessionIndexTable = "default_index_sessionId"; 25 public final static String databaseInfoIndexTable = "databaseInfo"; 26 public final static String tableInfoIndexTable = "tableInfo"; 27 public final static String ColumnInfoIndexTable = "columnInfo"; 28 public final static String ClusterInfoIndexTable = "clusterInfo"; 29 static Properties properties; 30 static HashMap structureMap; 31 public static HashMap primaryKeymap; 32 static { 33 try { 34 properties = new Properties(); 35 Class cl = Class.forName("com.daffodilwoods.daffodildb.server.datadictionarysystem.SystemTablesCreator"); 36 java.net.URL urlw = cl.getResource("/com/daffodilwoods/daffodildb/server/datadictionarysystem/systemtablesStructure.obj"); 37 ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(urlw.openStream())); 38 structureMap = (HashMap) ois.readObject(); 39 ois.close(); 40 java.net.URL urlprimary = cl.getResource("/com/daffodilwoods/daffodildb/server/datadictionarysystem/systemtablesPrimaryKeys.obj"); 41 ObjectInputStream oisPrimary = new ObjectInputStream(new BufferedInputStream(urlprimary.openStream())); 42 primaryKeymap = (HashMap) oisPrimary.readObject(); 43 oisPrimary.close(); 44 java.net.URL url = cl.getResource("/com/daffodilwoods/daffodildb/server/datadictionarysystem/systemtablesdefinition.properties"); 45 properties.load(url.openStream()); 46 } catch (IOException ex) { 47 } catch (ClassNotFoundException ex) { 48 } 49 } 50 51 public SystemTablesCreator() throws DException {} 52 53 54 static String [] routine_columnUsage_primaryKeys() { 55 return new String [] {"SPECIFIC_CATALOG", "SPECIFIC_SCHEMA", "SPECIFIC_NAME", "TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME", "COLUMN_NAME"}; 56 } 57 58 static String [] routine_TableUsage_primaryKeys() { 59 return new String [] {"SPECIFIC_CATALOG", "SPECIFIC_SCHEMA", "SPECIFIC_NAME", "TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME"}; 60 } 61 62 public static String [] viewNames = {SystemTables.columns_ViewName.getIdentifier(), SystemTables.tables_ViewName.getIdentifier()}; 63 64 public static String [] tableNames = {SystemTables.characterSets_TableName.getIdentifier(), 65 SystemTables.check_constraints_TableName.getIdentifier(), 66 SystemTables.check_column_usage_TableName.getIdentifier(), 67 SystemTables.check_table_usage_TableName.getIdentifier(), 68 69 SystemTables.collations_TableName.getIdentifier(), 70 SystemTables.column_privileges_TableName.getIdentifier(), 71 SystemTables.columns_TableName.getIdentifier(), 72 SystemTables.dataTypeDescriptor_TableName.getIdentifier(), 73 SystemTables.domains_TableName.getIdentifier(), 74 SystemTables.domain_constraints_TableName.getIdentifier(), 75 SystemTables.key_column_usage_TableName.getIdentifier(), 76 SystemTables.role_authorization_TableName.getIdentifier(), 77 SystemTables.roles_TableName.getIdentifier(), 78 SystemTables.referential_constraints_TableName.getIdentifier(), 79 SystemTables.schema_TableName.getIdentifier(), 80 SystemTables.table_constraints_TableName.getIdentifier(), 81 SystemTables.table_privileges_TableName.getIdentifier(), 82 SystemTables.tables_TableName.getIdentifier(), 83 SystemTables.triggers_TableName.getIdentifier(), 84 SystemTables.trigger_table_usage_TableName.getIdentifier(), 85 SystemTables.trigger_column_usage_TableName.getIdentifier(), 86 SystemTables.triggered_update_columns_TableName.getIdentifier(), 87 SystemTables.users_TableName.getIdentifier(), 88 SystemTables.usage_privileges_TableName.getIdentifier(), 89 SystemTables.views_TableName.getIdentifier(), 90 SystemTables.view_colum_usage_TableName.getIdentifier(), 91 SystemTables.view_table_usage_TableName.getIdentifier(), 92 SystemTables.transaction_TableName.getIdentifier(), 93 SystemTables.parameters_TableName.getIdentifier(), 94 SystemTables.routines_TableName.getIdentifier(), 95 SystemTables.routine_privileges_TableName.getIdentifier(), 96 SystemTables.INDEXINFO.getIdentifier(), 97 SystemTables.INDEXCOLUMNS.getIdentifier(), 98 SystemTables.FULLTEXTINFO.getIdentifier(), 99 SystemTables.FULLTEXTCOLUMNINFO.getIdentifier(), 100 SystemTables.DATABASEFULLTEXTINFO.getIdentifier(), 101 SystemTables.DATABASEFULLTEXTCOLUMNINFO.getIdentifier(), 102 103 SystemTables.user_defined_type_TableName.getIdentifier(), 104 SystemTables.user_defined_type_privileges_TableName.getIdentifier(), 105 SystemTables.method_specifications_TableName.getIdentifier(), 106 SystemTables.method_specification_parameters_TableName.getIdentifier(), 107 108 SystemTables.transforms_TableName.getIdentifier(), 109 SystemTables.sequence_number_TableName.getIdentifier(), 110 SystemTables.DATABASEINFO.getIdentifier(), 111 SystemTables.TABLEINFO.getIdentifier(), 112 SystemTables.COLUMNINFO.getIdentifier(), 113 SystemTables.CLUSTERINFO.getIdentifier(), 114 SystemTables.dualSystemTable.getIdentifier(), 115 SystemTables.routine_table_usage_TableName.getIdentifier(), 116 SystemTables.routine_column_usage_TableName.getIdentifier() 117 }; 118 119 120 public static String [] getPrimaryKeys(QualifiedIdentifier tableName) throws DException { 121 return (String []) primaryKeymap.get(tableName); 122 } 123 124 public static Object [][] getTableStructure(QualifiedIdentifier tableName) throws DException { 125 if (tableName.getName().startsWith("default_index")) { 126 return DefaultIndexTableStructure(); 127 } else if (tableName.getName().equalsIgnoreCase(transactionIndexTable)) { 128 return TransactionIndexTableStructure(); 129 } else if (tableName.getName().startsWith(sessionIndexTable)) { 130 return SessionIndexTableStructure(); 131 } else if (tableName.getName().equalsIgnoreCase("dualSystemTable")) { 132 return dualSystemTableStructure(); 133 } else if (tableName.getName().equalsIgnoreCase("dualSystemTable")) { 134 return dualSystemTableStructure(); 135 } else { 136 Object [][] asads = (Object [][]) structureMap.get(tableName); 137 return asads; 138 } 139 } 140 141 142 143 public static ArrayList getInformationSchemaStatements() throws DException { 144 ArrayList informationSchemaStatement = new ArrayList(10); 145 informationSchemaStatement.add("CREATE SCHEMA " + SystemTables.systemCatalog + ".INFORMATION_SCHEMA AUTHORIZATION _SYSTEM"); 146 informationSchemaStatement.add("CREATE DOMAIN " + SystemTables.systemCatalog + ".INFORMATION_SCHEMA.CARDINAL_NUMBER AS INTEGER " + 147 "CONSTRAINT CARDINAL_NUMBER_DOMAIN_CHECK " + 148 "CHECK ( VALUE >= 0 )"); 149 informationSchemaStatement.add("CREATE DOMAIN " + SystemTables.systemCatalog + ".INFORMATION_SCHEMA.CHARACTER_DATA AS " + 150 "CHARACTER VARYING (" + characterDataSize + ") "); 151 informationSchemaStatement.add("CREATE DOMAIN " + SystemTables.systemCatalog + ".INFORMATION_SCHEMA.SQL_IDENTIFIER AS " + 152 "CHARACTER VARYING (" + SQLIdentifierSize + ") "); 153 informationSchemaStatement.add(" CREATE DOMAIN " + SystemTables.systemCatalog + ".INFORMATION_SCHEMA.TIME_STAMP AS TIMESTAMP (2)"); 154 return informationSchemaStatement; 155 } 156 157 public static ArrayList getDefinitionSchemaStatement() throws DException { 158 ArrayList tableDefinitionList = new ArrayList(50); 159 tableDefinitionList.add("Create Schema " + SystemTables.systemCatalog + 160 ".Definition_Schema authorization _SYSTEM"); 161 tableDefinitionList.add(properties.getProperty("UsersDefinition")); 162 tableDefinitionList.add(properties.getProperty("RolesDefinition")); 163 tableDefinitionList.add(properties.getProperty("Role_Authorization_DescriptorsDefinition")); 164 tableDefinitionList.add(properties.getProperty("SchemataDefinition")); 165 tableDefinitionList.add(properties.getProperty("Character_SetsDefinition")); 166 tableDefinitionList.add(properties.getProperty("CollationsDefinition")); 167 tableDefinitionList.add(properties.getProperty("DomainDefinition")); 168 169 tableDefinitionList.add(properties.getProperty("TablesDefinition")); 170 171 tableDefinitionList.add(properties.getProperty("ColumnsDefinition")); 172 tableDefinitionList.add(properties.getProperty("Data_Type_DescriptorDefinition")); 173 174 tableDefinitionList.add(properties.getProperty("Table_ConstraintsDefinition")); 175 tableDefinitionList.add(properties.getProperty("Key_Column_UsageDefinition")); 176 tableDefinitionList.add(properties.getProperty("Referential_ConstraintsDefinition")); 177 tableDefinitionList.add(properties.getProperty("Check_ConstraintsDefinition")); 178 tableDefinitionList.add(properties.getProperty("Check_Column_UsageDefinition")); 179 tableDefinitionList.add(properties.getProperty("Check_Table_UsageDefinition")); 180 181 tableDefinitionList.add(properties.getProperty("TriggersDefinition")); 182 tableDefinitionList.add(properties.getProperty("Trigger_Table_UsageDefinition")); 183 tableDefinitionList.add(properties.getProperty("Trigger_Column_UsageDefinition")); 184 tableDefinitionList.add(properties.getProperty("Triggered_Update_ColumnsDefinition")); 185 186 tableDefinitionList.add(properties.getProperty("ViewsDefinition")); 187 tableDefinitionList.add(properties.getProperty("View_Column_UsageDefinition")); 188 tableDefinitionList.add(properties.getProperty("View_Table_UsageDefinition")); 189 190 tableDefinitionList.add(properties.getProperty("Domain_ConstraintsDefinition")); 191 192 tableDefinitionList.add(properties.getProperty("Column_PrivilegesDefinition")); 193 tableDefinitionList.add(properties.getProperty("Table_PrivilegesDefinition")); 194 tableDefinitionList.add(properties.getProperty("Usage_PrivilegesDefinition")); 195 196 tableDefinitionList.add(properties.getProperty("RoutinesDefinition")); 197 tableDefinitionList.add(properties.getProperty("ParametersDefinition")); 198 199 tableDefinitionList.add(properties.getProperty("Routine_PrivilegesDefinition")); 200 tableDefinitionList.add(properties.getProperty("IndexInfoDefinition")); 201 tableDefinitionList.add(properties.getProperty("IndexColumnsDefinition")); 202 203 tableDefinitionList.add(properties.getProperty("FulltextindexDefinition")); 204 tableDefinitionList.add(properties.getProperty("FulltextIndexColumnsDefinition")); 205 206 tableDefinitionList.add(properties.getProperty("User_Defined_TypesDefinition")); 207 tableDefinitionList.add(properties.getProperty("User_Defined_Type_PrivilegesDefinition")); 208 tableDefinitionList.add(properties.getProperty("TransformDefinition")); 209 tableDefinitionList.add(properties.getProperty("Method_SpecificationDefinition")); 210 tableDefinitionList.add(properties.getProperty("Method_Specification_ParametersDefinition")); 211 tableDefinitionList.add(properties.getProperty("Sequence_NumberDefinition")); 212 213 return tableDefinitionList; 214 } 215 216 public static ArrayList getSystemViews() { 217 ArrayList viewDefinitionList = new ArrayList(4); 218 viewDefinitionList.add(properties.getProperty("TablesViewDefinition")); 219 viewDefinitionList.add(properties.getProperty("ColumnsViewDefinition")); 220 viewDefinitionList.add(properties.getProperty("GrantTablesViewQuery")); 221 viewDefinitionList.add(properties.getProperty("GrantColumnsViewQuery")); 222 return viewDefinitionList; 223 } 224 225 public static ArrayList getSystemTableIndexes() throws DException { 226 ArrayList indexesList = new ArrayList(7); 227 indexesList.add("create index psg_table_constraint_1 on " + SystemTables.table_constraints_TableName + " (table_catalog,table_schema,table_name,constraint_type,is_deferrable) "); 228 indexesList.add("create index psg_key_column_usage_1 on " + SystemTables.key_column_usage_TableName + " (table_catalog,table_schema,table_name,column_name) "); 229 indexesList.add("create index psg_domain_constraint_1 on " + SystemTables.domain_constraints_TableName + " (domain_catalog,domain_schema,domain_name) "); 230 indexesList.add("create index psg_referential_constraint_1 on " + SystemTables.referential_constraints_TableName + " (unique_constraint_catalog,unique_constraint_schema,unique_constraint_name) "); 231 indexesList.add("create index psg_triggers_1 on " + SystemTables.triggers_TableName + " (event_object_catalog,event_object_schema,event_object_table,event_manipulation,action_orientation,condition_timing) "); 232 indexesList.add("create index psg_triggered_update_columns_1 on " + SystemTables.triggered_update_columns_TableName + " (event_object_catalog,event_object_schema,event_object_table) "); 233 indexesList.add("create index psg_schemata_1 on " + SystemTables.schema_TableName + " (SCHEMA_OWNER) "); 234 indexesList.add("create index psg_views_1 on " + SystemTables.views_TableName + " (TABLE_CATALOG, TABLE_SCHEMA, MATERIALIZED_TABLE_NAME ) "); 235 return indexesList; 236 } 237 238 239 240 241 static Object [][] dualSystemTableStructure() { 242 return new Object [][] { {"Column_name", new Long (Datatype.INT), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 243 }; 244 } 245 246 static Object [][] DefaultIndexTableStructure() { 247 return new Object [][] { {"RecordClusterAddress", new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 248 , {"RecordNumber", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 249 , {"ClusterSize", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 250 , {"NextNodeAddress", new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 251 , {"NextNodeRecordNumber", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 252 , {"NextClusterSize", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 253 , {CharacteristicsConstants.systemFields[CharacteristicsConstants.rowId], new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 254 , {CharacteristicsConstants.systemFields[CharacteristicsConstants.transactionId], new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 255 , {CharacteristicsConstants.systemFields[CharacteristicsConstants.sessionId], new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 256 , 257 }; 258 } 259 260 static Object [][] TransactionIndexTableStructure() { 261 return new Object [][] { {"RecordClusterAddress", new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 262 , {"RecordNumber", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 263 , {"ClusterSize", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 264 , {"NextNodeAddress", new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 265 , {"NextNodeRecordNumber", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 266 , {"NextClusterSize", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 267 , {"SavedTransactionId", new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 268 , 269 }; 270 } 271 272 static Object [][] SessionIndexTableStructure() { 273 return new Object [][] { {"RecordClusterAddress", new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 274 , {"RecordNumber", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 275 , {"ClusterSize", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 276 , {"NextNodeAddress", new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 277 , {"NextNodeRecordNumber", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 278 , {"NextClusterSize", new Long (Datatype.INTEGER), new Integer (Datatype.INTSIZE), Boolean.TRUE, null, null, null} 279 , {"SavedSessionId", new Long (Datatype.LONG), new Integer (Datatype.LONGSIZE), Boolean.TRUE, null, null, null} 280 , 281 }; 282 } 283 284 334 376 377 383 384 385 386 388 public static void changeStructure(double version) throws DException { 389 try { 390 Class cl = Class.forName("com.daffodilwoods.daffodildb.server.datadictionarysystem.SystemTablesCreator"); 391 java.net.URL urlw = cl.getResource("/com/daffodilwoods/daffodildb/server/datadictionarysystem/systemtablesStructure.obj"); 392 ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(urlw.openStream())); 393 structureMap = (HashMap) ois.readObject(); 394 if (version >= 3.4) { 395 Object [][] columnsTableStructure = (Object [][]) structureMap.get( (Object ) SystemTables.columns_TableName); 396 columnsTableStructure[9][2] = new Integer (1027); 397 } 398 ois.close(); 399 } catch (IOException ex) { 400 } catch (ClassNotFoundException ex) { 401 } 402 } 403 } 404 | Popular Tags |