1 package com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 6 import com.daffodilwoods.daffodildb.server.serversystem.*; 7 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem.*; 8 import com.daffodilwoods.daffodildb.server.sql99.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 10 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 11 import com.daffodilwoods.database.general.*; 12 import com.daffodilwoods.database.resource.*; 13 14 public class IndexDescriptor extends Descriptor { 15 public String table_catalog; 16 public String table_schema; 17 public String table_name; 18 public String indexname; 19 public String indextablename; 20 public Object numberOfRecords = new Integer (0); 21 public Object rootNodeAddress = new Integer (0); 22 public Object rootClusterSize = new Integer (0); 23 public Object rootRecordNumber = new Integer (0); 24 public Object fixedVariable; 25 public Boolean is_system_generated = Boolean.FALSE; 26 public static final int maxIndexColumnSize = 4192; 27 ArrayList indexColumnDescriptors; 28 private int columnCount = 0; 29 30 31 32 public IndexDescriptor() throws DException { 33 } 34 35 public void load(_ServerSession serverSession) throws DException { 36 _Executer indexInfoExecuter = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getConditionIndexInfoExecuter(); 37 _SelectQueryIterator iter = (_SelectQueryIterator) indexInfoExecuter.execute(new Object [] {table_catalog, table_schema, table_name, indexname}); 38 if (!iter.first()) { 39 throw new DException("DSE976", new Object [] {indexname, getQualifiedTable()}); 40 } 41 loadData(iter); 42 loadColumnDescriptors(serverSession); 43 } 44 45 private void loadData(_SelectQueryIterator iter) throws DException { 46 Object [] values = (Object []) iter.getObject(); 47 indextablename = (String ) values[0]; 48 numberOfRecords = values[1]; 49 rootNodeAddress = values[2]; 50 rootClusterSize = values[3]; 51 rootRecordNumber = values[4]; 52 fixedVariable = values[5]; 53 is_system_generated = (Boolean ) values[6]; 54 } 55 56 public void loadDataFromRecord(_SelectQueryIterator iter) throws DException { 57 Object [] values = (Object []) iter.getObject(); 58 table_catalog = (String ) values[SystemTablesFields.indexInfo_table_catalog]; 59 table_schema = (String ) values[SystemTablesFields.indexInfo_table_schema]; 60 table_name = (String ) values[SystemTablesFields.indexInfo_table_name]; 61 indexname = (String ) values[SystemTablesFields.indexInfo_indexname]; 62 indextablename = (String ) values[SystemTablesFields. 63 indexInfo_indextablename]; 64 numberOfRecords = values[SystemTablesFields.indexInfo_numberofRecords]; 65 rootNodeAddress = values[SystemTablesFields.indexInfo_rootNodeAddress]; 66 rootClusterSize = values[SystemTablesFields.indexInfo_rootClusterSize]; 67 rootRecordNumber = values[SystemTablesFields.indexInfo_rootRecordNumber]; 68 fixedVariable = values[SystemTablesFields.indexInfo_fixedVariable]; 69 is_system_generated = (Boolean ) values[SystemTablesFields.indexInfo_is_system_generated]; 70 } 71 72 public void loadColumnDescriptors(_ServerSession serverSession) throws DException { 73 _Executer indexExecuter = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getIndexExecuter(); 74 _SelectQueryIterator iter = (_SelectQueryIterator) indexExecuter.execute(new Object [] {table_catalog, table_schema, table_name, indexname}); 75 if (!iter.first()) { 76 throw new DException("DSE977", null); 77 } 78 indexColumnDescriptors = new ArrayList(); 79 do { 80 IndexColumnDescriptor columnDescriptor = new IndexColumnDescriptor(SystemTables.INDEXCOLUMNS); 81 columnDescriptor.table_catalog = table_catalog; 82 columnDescriptor.table_schema = table_schema; 83 columnDescriptor.table_name = table_name; 84 columnDescriptor.indexname = indexname; 85 columnDescriptor.loadDataFromRecord(iter); 86 indexColumnDescriptors.add(columnDescriptor); 87 } while (iter.next()); 88 } 89 90 public void save(_ServerSession serverSession) throws DException { 91 Object [] columnValues = new Object [] { 92 table_catalog, table_schema, 93 table_name, indexname, indextablename, numberOfRecords, 94 rootNodeAddress, rootClusterSize, rootRecordNumber, fixedVariable, is_system_generated}; 95 try { 96 SqlSchemaConstants.insert(serverSession, SystemTables.INDEXINFO, null, 97 columnValues); 98 } catch (PrimaryConstraintException de) { 99 DException tde = new DException("DSE1142", new Object [] {indexname, 100 getTableName()}); 101 throw tde; 102 } catch (SizeMisMatchException de) { 103 if (de.getDseCode().equals("DSE773")) { 104 DException tde = new DException("DSE8103", null); 105 throw tde; 106 } 107 } catch (DException de) { 108 if (de.getDseCode().equals("DSE1255")) { 109 DException tde = new DException("DSE1142", new Object [] {indexname, 110 getTableName()}); 111 throw tde; 112 } 113 if (de.getDseCode().equals("DSE773")) { 114 DException tde = new DException("DSE8103", null); 115 throw tde; 116 } 117 throw de; 118 } 119 saveIndexColumns(serverSession); 120 } 121 122 public void saveIndexColumns(_ServerSession serverSession) throws DException { 123 for (int i = 0, columnCount = indexColumnDescriptors.size(); 124 i < columnCount; i++) { 125 IndexColumnDescriptor columnDescriptor = (IndexColumnDescriptor) 126 indexColumnDescriptors.get(i); 127 columnDescriptor.save(serverSession); 128 } 129 } 130 131 public void delete(_ServerSession serverSession) throws DException { 132 booleanvalueexpression condition = ( (DataDictionary) serverSession.getDataDictionary()). 133 getPreparedStatementGetter().getIndexInfoTableCondition(); 134 super.delete(serverSession, SqlSchemaConstants.INDEXINFO, condition, new Object [] {table_catalog, table_schema, table_name, indexname}); 135 deleteColumns(serverSession); 136 } 137 138 private void deleteColumns(_ServerSession serverSession) throws DException { 139 for (int i = 0, columnCount = indexColumnDescriptors.size(); 140 i < columnCount; i++) { 141 IndexColumnDescriptor columnDescriptor = (IndexColumnDescriptor) 142 indexColumnDescriptors.get(i); 143 columnDescriptor.delete(serverSession); 144 } 145 } 146 147 148 public String getTableName() throws DException { 149 return new StringBuffer ().append(table_catalog).append(".").append( 150 table_schema).append(".").append(table_name).toString(); 151 } 152 153 public QualifiedIdentifier getQualifiedTable() throws DException { 154 return new QualifiedIdentifier(table_catalog, table_schema, table_name); 155 } 156 157 public void addIndexColumnDescriptor(IndexColumnDescriptor indexColumnDes) throws 158 DException { 159 if (indexColumnDescriptors == null) { 160 indexColumnDescriptors = new ArrayList(); 161 } 162 indexColumnDes.ordinalPosition = new Integer (++columnCount); 163 indexColumnDescriptors.add(indexColumnDes); 164 } 165 166 public int getDescriptorType() { 167 return INDEX_DESCRIPTOR; 168 } 169 } 170 | Popular Tags |