1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem; 2 3 8 9 import java.util.*; 10 11 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 12 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.*; 13 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 14 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility; 15 import com.daffodilwoods.daffodildb.server.serversystem.*; 16 import com.daffodilwoods.daffodildb.utils.*; 17 import com.daffodilwoods.daffodildb.utils.comparator.*; 18 import com.daffodilwoods.database.general.*; 19 import com.daffodilwoods.database.resource.*; 20 21 class TableCharacteristicsGenerator implements Datatype,DatabaseConstants{ 22 23 26 private TableManager tableManager; 27 28 29 32 private static ByteComparator nameComparator= new ByteComparator(new boolean[] {true,true,true},new SuperComparator[] {GetByteComparator.stringComparator,GetByteComparator.stringComparator,GetByteComparator.stringComparator}); 33 34 public TableCharacteristicsGenerator(TableManager tableManager0) { 35 tableManager = tableManager0; 36 } 37 38 44 45 private Object [] getTableCharacteristics(Object [][] tableStructure,boolean isSystemTable) throws DException { 46 TableProperties tableProperties = new TableProperties(); 47 tableProperties.columnCount = tableStructure.length; 48 int columnCount = tableProperties.columnCount; 49 String [] columnNames = new String [columnCount]; 50 int [] columnTypes = new int [columnCount]; 51 int [] columnSizes = new int [columnCount]; 52 int[] startAddresses = new int[columnCount]; 53 boolean [] blobClob = new boolean [columnCount]; 54 boolean [] fixedColumns= new boolean[columnCount]; 55 tableProperties.fixed = new boolean[columnCount]; 56 tableProperties.size = new int[columnCount]; 57 tableProperties.columnType = new int[columnCount]; 58 tableProperties.variableColumns = 0; 59 tableProperties.recordSize = 0; 60 ArrayList blobClobList = new ArrayList(); 61 for(int i = 0 ; i < columnCount;i++){ 62 tableProperties.size[i] = tableStructure[i][2].hashCode(); 63 tableProperties.columnType[i] = tableStructure[i][1].hashCode(); 64 columnNames[i] = (String )tableStructure[i][0]; 65 columnTypes[i] = tableStructure[i][1].hashCode(); 66 columnSizes[i] = tableStructure[i][2].hashCode(); 67 blobClob[i] = Utility.isBlobClob(tableStructure[i][1].hashCode()); 68 if(Utility.isBlobClob(tableStructure[i][1].hashCode())){ 69 blobClobList.add(new Integer (i)); 70 } 71 fixedColumns[i] = tableProperties.fixed[i] = Utility.isFixed(tableStructure[i][1].hashCode()); 72 if(tableProperties.fixed[i]) 73 tableProperties.recordSize+= tableProperties.size[i]; 74 else 75 tableProperties.variableColumns++; 76 startAddresses[i] = isSystemTable ? -1 : tableStructure[i][4].hashCode(); 77 } 78 tableProperties.fixedTable = tableProperties.variableColumns == 0; 79 return new Object [] {new TableCharacteristics(columnNames,columnTypes,columnSizes,blobClob,blobClobList,fixedColumns,startAddresses), tableProperties}; 80 } 81 88 Object [] getTableCharacteristicsForUserTable(BufferRange[] bytes) throws DException { 89 return getTableCharacteristics(getTableStructure(bytes),false); 90 } 91 98 Object [] getTableCharacteristicsForSystemTable(QualifiedIdentifier tableName) throws DException{ 99 Object [][] ob = tableName.name.endsWith("TEMP") ? Utility.getIndexTableStructure() : SystemTableInformation.getTableStructure(tableName); 100 return getTableCharacteristics(ob,true); 101 } 102 103 108 109 private Object [][] getTableStructure(BufferRange[] bytesOfTableName)throws DException { 110 _DataTable columnInfoTable = (_DataTable)tableManager.getTable(SystemTables.COLUMNINFO); 111 _TableCharacteristics tableCharacteristicsOfColumnInfo = columnInfoTable.getTableCharacteristics(); 112 DatabaseUserTableIterator columnInfoIterator = (DatabaseUserTableIterator)columnInfoTable.getIterator(); 113 ArrayList columnInfo = new ArrayList(); 114 _Index btree = tableManager.getIndexOnColumnInfo(); if(columnInfoIterator.first()){ 116 try { 117 tableManager.seek(btree,bytesOfTableName); 118 } 119 catch (DException ex) { 120 if(!ex.getDseCode().equalsIgnoreCase("DSE2037")) 121 throw ex; 122 _IndexKey btreeKey = (_IndexKey)ex.getParameters()[0]; 123 columnInfoIterator.move(btreeKey.getValue()); 124 boolean flag = true; 125 int[] cols = new int[] {3,4,5,6,7}; 126 Object [] fieldbase; 127 do{ 128 fieldbase = Utility.convertIntoFieldBase((Object [])tableCharacteristicsOfColumnInfo.getObject( cols,(BufferRange[])columnInfoIterator.getColumnValues(cols))); 129 columnInfo.add(fieldbase); 130 131 flag = columnInfoIterator.next(); 132 133 if(flag){ 134 BufferRange[] array = (BufferRange[])columnInfoIterator.getColumnValues(new int[] {0,1,2}); 135 flag = nameComparator.compare(bytesOfTableName,array) == 0; 136 } 137 }while(flag); 138 int len = columnInfo.size(); 139 Object [][] columnInfoObject = new Object [len][]; 140 141 for (int i = 0 ; i < len ; i++) { 142 columnInfoObject[i] = (Object [])columnInfo.get(i); 143 } 144 145 return columnInfoObject; 146 } 147 } 148 columnInfoIterator.show(); 149 btree.showBTree(); 150 throw new DException("DSE959",new Object [] {bytesOfTableName}); 151 } 152 public Object [] getTableCharacteristicsFromColumnInformation(Object columnInformation,boolean isSystemTable,Long [] blobClobColumnStartAddresses) throws DException { 153 ColumnInformation columnInfo = (ColumnInformation)columnInformation; 154 Object [][] columns = columnInfo.info ; 155 TableProperties tableProperties = new TableProperties(); 156 tableProperties.columnCount = columns.length ; 157 int columnCount = tableProperties.columnCount; 158 String [] columnNames = new String [columnCount]; 159 int [] columnTypes = new int [columnCount]; 160 int [] columnSizes = new int [columnCount]; 161 int[] startAddresses = new int[columnCount]; 162 boolean [] blobClob = new boolean [columnCount]; 163 boolean [] fixedColumns= new boolean[columnCount]; 164 tableProperties.fixed = new boolean[columnCount]; 165 tableProperties.size = new int[columnCount]; 166 tableProperties.columnType = new int[columnCount]; 167 tableProperties.variableColumns = 0; 168 tableProperties.recordSize = 0; 169 ArrayList blobClobList = new ArrayList(); 170 176 int index = 0; 177 for(int i = 0 ; i < columnCount;i++){ 178 tableProperties.size[i] = ((Integer )columns[i][2]).intValue() ; 179 tableProperties.columnType[i] = ((Long )columns[i][1]).intValue() ; 180 columnNames[i] = (String )columns[i][0]; 181 columnTypes[i] = tableProperties.columnType[i]; 182 columnSizes[i] = tableProperties.size[i]; 183 blobClob[i] = Utility.isBlobClob(columnTypes[i]); 184 if(blobClob[i]){ 185 blobClobList.add(new Integer (i)); 186 startAddresses[i] = isSystemTable ? -1 : blobClobColumnStartAddresses[index++].intValue() ; 187 }else 188 startAddresses[i] = isSystemTable ? -1 : 0 ; 189 fixedColumns[i] = tableProperties.fixed[i] = Utility.isFixed(columnTypes[i]); 190 if(tableProperties.fixed[i]) 191 tableProperties.recordSize+= tableProperties.size[i]; 192 else 193 tableProperties.variableColumns++; 194 } 195 tableProperties.fixedTable = tableProperties.variableColumns == 0; 196 return new Object [] {new TableCharacteristics(columnNames,columnTypes,columnSizes,blobClob,blobClobList,fixedColumns,startAddresses), tableProperties}; 197 } 198 199 200 } 201 | Popular Tags |