KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datasystem > persistentsystem > TableCharacteristicsGenerator


1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem;
2
3 /**
4  * It makes the tableCharacteristics For all the Tables. It gets all columnInformation of Table From
5  * ColumnInfo System Table.
6
7  */

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     /**
24      * To get ColumnInfo System Table and Btree on ColumnInfo System Table
25      */

26     private TableManager tableManager;
27
28
29     /**
30      * To compare name of tables
31      */

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     /**
39      * Initializes tableCharacteristics and tableProperties according to given tableStructure and returns
40      *
41      * @param tableStructure column Information of Table
42      * @return array of tableCharacteristics and tableProperties
43      */

44
45     private Object JavaDoc[] getTableCharacteristics(Object JavaDoc[][] tableStructure,boolean isSystemTable) throws DException {
46         TableProperties tableProperties = new TableProperties();
47         tableProperties.columnCount = tableStructure.length;
48         int columnCount = tableProperties.columnCount;
49         String JavaDoc [] columnNames = new String JavaDoc[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 JavaDoc)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 JavaDoc(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 JavaDoc[] {new TableCharacteristics(columnNames,columnTypes,columnSizes,blobClob,blobClobList,fixedColumns,startAddresses), tableProperties};
80     }
81     /**
82      * It returns table charcteristics of the table name passed as bytes.
83      *
84      * @param bytes BufferRange[] - tableName whoose characteristics is to be geted.
85      * @throws DException
86      * @return Object[] - table charcteristics of the table name passed as bytes.
87      */

88     Object JavaDoc [] getTableCharacteristicsForUserTable(BufferRange[] bytes) throws DException {
89         return getTableCharacteristics(getTableStructure(bytes),false);
90     }
91     /**
92      * It checks that system table of memory or of file and than gets its stucture
93      * according to it if table name ends with temp than it is for memory.
94      * @param tableName QualifiedIdentifier - tableName whoose table characteristics to be needed.
95      * @throws DException
96      * @return Object[] - table Characteristics.
97      */

98     Object JavaDoc[] getTableCharacteristicsForSystemTable(QualifiedIdentifier tableName) throws DException{
99         Object JavaDoc[][] ob = tableName.name.endsWith("TEMP") ? Utility.getIndexTableStructure() : SystemTableInformation.getTableStructure(tableName);
100         return getTableCharacteristics(ob,true);
101     }
102
103     /**
104      * returns Tablestructure of table from ColumnInfo SystemTable
105      * @param bytesOfTableName whose structure is required
106      * @return tableStructure of Table
107      */

108
109     private Object JavaDoc[][] 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();//tableManager.getIndex(SystemTables.COLUMNINFO);
115
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 JavaDoc[] fieldbase;
127                 do{
128                      fieldbase = Utility.convertIntoFieldBase((Object JavaDoc[])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 JavaDoc[][] columnInfoObject = new Object JavaDoc[len][];
140
141                 for (int i = 0 ; i < len ; i++) {
142                     columnInfoObject[i] = (Object JavaDoc[])columnInfo.get(i);
143                 }
144
145                 return columnInfoObject;
146             }
147         }
148         columnInfoIterator.show();
149         btree.showBTree();
150         throw new DException("DSE959",new Object JavaDoc[] {bytesOfTableName});
151     }
152     public Object JavaDoc[] getTableCharacteristicsFromColumnInformation(Object JavaDoc columnInformation,boolean isSystemTable,Long JavaDoc[] blobClobColumnStartAddresses) throws DException {
153         ColumnInformation columnInfo = (ColumnInformation)columnInformation;
154         Object JavaDoc[][] columns = columnInfo.info ;
155               TableProperties tableProperties = new TableProperties();
156               tableProperties.columnCount = columns.length ;
157               int columnCount = tableProperties.columnCount;
158               String JavaDoc [] columnNames = new String JavaDoc[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               /* columnInfo[i][0] = columnNames[i];
171                 columnInfo[i][1] = new Long(columnTypes[i]);
172                 columnInfo[i][2] = new Integer(columnSizes[i]);
173                 columnInfo[i][3] = new Long(i);
174
175                */

176               int index = 0;
177               for(int i = 0 ; i < columnCount;i++){
178                   tableProperties.size[i] = ((Integer JavaDoc)columns[i][2]).intValue() ;
179                   tableProperties.columnType[i] = ((Long JavaDoc)columns[i][1]).intValue() ;
180                   columnNames[i] = (String JavaDoc)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 JavaDoc(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 JavaDoc[] {new TableCharacteristics(columnNames,columnTypes,columnSizes,blobClob,blobClobList,fixedColumns,startAddresses), tableProperties};
197           }
198
199
200 }
201
Popular Tags