KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem;
2
3 import java.text.*;
4 import java.util.*;
5
6 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
7 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility;
8 import com.daffodilwoods.daffodildb.server.datasystem.utility.*;
9 import com.daffodilwoods.daffodildb.utils.*;
10 import com.daffodilwoods.daffodildb.utils.byteconverter.*;
11 import com.daffodilwoods.daffodildb.utils.field.*;
12 import com.daffodilwoods.database.resource.*;
13 import com.daffodilwoods.database.utility.*;
14
15 /**
16  * It has all the information of columns like column types, columnSizes,columnNames etc.It has the power
17  * of converting Object into bytes and bytes into Object by using byte handlers of corresponding datatypes
18  */

19 public class TableCharacteristics implements _TableCharacteristics,Datatype{
20
21     /**
22      * all column Names of table
23      */

24   private String JavaDoc[] columnNames;
25
26     /**
27      * byteHandler to convert bytes into Object and vice versa
28      */

29   private CbCzufIboemfs [] byteHandler;
30
31     /**
32      * Types of all columns in table
33      */

34    private int[] columnTypes;
35
36     /**
37      * Size of all columns in Table
38      */

39    private int [] columnSizes;
40
41     /**
42      * total number of columns in table
43      */

44    private int columnCount;
45
46     /**
47      * whether column is of blob clob or not
48      */

49    private boolean[] blobClob;
50    /**
51     * Whether column is fixed or not.
52     */

53    private boolean [] isFixedColumn;
54
55     /**
56      * List having all blob clob columns in table
57      */

58     private ArrayList blobClobList;
59
60     private Collator collator;
61     /**
62      * strat addresses for blob clob columns.
63      */

64     private int[] startAddrsesses;
65
66     public TableCharacteristics(String JavaDoc[] columnNames1,int [] columnTypes1,int [] columnSizes1,boolean[] blobClob0,ArrayList blobClobList0,boolean [] fixedColumn0,int[] startAddrsesses0) {
67         columnNames = columnNames1;
68         columnTypes = columnTypes1;
69         columnSizes = columnSizes1;
70         columnCount = columnNames.length;
71         blobClob = blobClob0;
72         blobClobList = blobClobList0;
73         isFixedColumn = fixedColumn0;
74         startAddrsesses = startAddrsesses0;
75     }
76     /**
77      * It returns that passed index of column is blob clob or not.
78      *
79      * @param index int - index of column.
80      * @return boolean - true if column index passed is blob clob else false.
81      */

82     public boolean isBlobClob(int index) {
83         return blobClob[index];
84     }
85     /**
86      * It stores information of all column of table and ifo of every column name,
87      * type, size,index in table.
88      */

89     Object JavaDoc[][] columnInfo ;
90
91     public TableCharacteristics(String JavaDoc [] columnNames1,int [] columnTypes1,int [] columnSizes1) throws DException{
92         columnNames = columnNames1;
93         columnTypes = columnTypes1;
94         columnSizes = columnSizes1;
95         columnCount = columnNames.length;
96         byteHandler = new CbCzufIboemfs[columnCount];
97         for(int i = 0 ; i < columnCount ; i++ )
98             byteHandler[i] = ByteHandler.getByteHandler(columnTypes[i],columnSizes[i],null);
99         columnInfo = new Object JavaDoc[columnCount][4];
100         for( int i = 0 ; i < columnCount ; i++ ){
101             columnInfo[i][0] = columnNames[i];
102             columnInfo[i][1] = new Long JavaDoc(columnTypes[i]);
103             columnInfo[i][2] = new Long JavaDoc(columnSizes[i]);
104             columnInfo[i][3] = new Long JavaDoc(i);
105         }
106         int len = columnTypes.length;
107         isFixedColumn = new boolean[len];
108         for (int i = 0; i < len; i++) {
109             isFixedColumn[i] = Utility.isFixed(columnTypes[i]);
110         }
111     }
112     /**
113      * It returns column informations of the table.
114      *
115      * @return Object columnInfo.
116      */

117     public Object JavaDoc getColumnInformation() {
118         ColumnInformation ci = new ColumnInformation();
119         if(columnInfo == null){
120           columnInfo = new Object JavaDoc[columnCount][4];
121           for( int i = 0 ; i < columnCount ; i++ ){
122               columnInfo[i][0] = columnNames[i];
123               columnInfo[i][1] = new Long JavaDoc(columnTypes[i]);
124               columnInfo[i][2] = new Integer JavaDoc(columnSizes[i]);
125               columnInfo[i][3] = new Long JavaDoc(i);
126           }
127         }
128         ci.setObjects(columnInfo);
129         return ci;
130     }
131
132
133     /**
134      *
135      * @return int - number of columns of table.
136      */

137     public int getColumnCount() {
138         return columnCount;
139     }
140
141     /**
142      *
143      * @return String[] - names of columns of table.
144      */

145     public String JavaDoc[] getColumnNames() {
146             return columnNames;
147     }
148     /**
149      *
150      * @return int[] - column's size of the table.
151      */

152     public int[] getColumnSizes(){
153         return columnSizes;
154     }
155     /**
156      *
157      * @return int[] - columns size of table.
158      */

159     public int[] getColumnTypes() {
160             return columnTypes;
161     }
162
163
164     public int getMemoryUsage(Object JavaDoc[] values){
165         int memoryUsage = 0 ;
166         return memoryUsage ;
167     }
168
169     /**
170      * Returns index of column in Table corresponding to column Name
171      *
172      * @param columnName whose index in table is required
173      *
174      * @return index of column in Table corresponding to column Name
175      *
176      * @throws DException if column name does not exist in Table
177      */

178
179     public int getIndexForColumnName(String JavaDoc columnName) throws DException{
180         for(int i = 0,len = columnNames.length ; i < len ; i++)
181             if( columnName.equalsIgnoreCase(columnNames[i]))
182                 return i;
183         throw new DException("DSE256",new Object JavaDoc[] {columnName});
184     }
185
186     public String JavaDoc toString() {
187         return " columnNames == "+P.print(columnNames)+" columnNames == "+P.print(columnSizes)+" columnNames == "+P.print(columnTypes)+" HashCode == "+hashCode();
188     }
189
190     /**
191      * Returns array of data type of columns corresponding to specified indexes
192      *
193      * @param indexes whose data types are required
194      *
195      * @return array of data type of columns corresponding to specified indexes
196      *
197      */

198
199     public int[] getColumnTypes(int[] indexes) {
200         int len = indexes.length;
201         int[] types = new int[len];
202         for(int i = 0; i < len ; i++)
203             types[i] = columnTypes[indexes[i]];
204         return types;
205     }
206     /**
207      *
208      * @return int - column type of passed index of table column's.
209      */

210     public int getColumnType(int index) {
211         return columnTypes[index];
212     }
213     /**
214      *
215      * @return int size of blobclob list it is greater than zero if it is a blob clob table.
216      */

217     public int isBlobClobTable(){
218         return blobClobList.size();
219     }
220
221
222
223     /**
224      * To check is this column is fixed or not whoose index is passed to it.
225      *
226      * @param index int - index of column in table.
227      * @return boolean - true if column is fixed otherwise false.
228      */

229     public boolean isFixedColumn(int index){
230         return isFixedColumn[index];
231     }
232     /**
233      * @return int size of column whose indeex is passed.
234      */

235     public int getColumnSize(int index){
236         return columnSizes[index];
237     }
238     /**
239      * @return CbCzufIboemfs - byte handler corresponding to column whoose index is passed
240      * to convert bytes into objects or vice versa.
241      */

242     public CbCzufIboemfs getHandler(int index){
243         return byteHandler[index];
244     }
245
246     /**
247      * Converts bytes of given column index into Object and returns
248      * @param columnIndex index of Column in table
249      * @param bytes bytes which has to convert into Objects
250      * @return Object corresponding to given bytes
251      */

252
253     public Object JavaDoc getObject(int columnIndex,BufferRange bytes)throws DException{
254             try{
255                 return byteHandler[columnIndex].getObject(bytes,columnTypes[columnIndex]);
256             }catch(Exception JavaDoc ex) {
257                 throw new RuntimeException JavaDoc(" <<<<<<<<<<<<<<<<< CHECK THE PROBLEM >>>>>>>>>>>>>>>>>> "+hashCode());
258             }
259     }
260
261     /**
262      * converts bytes of all columns into Object and returns
263      * @param bytes bytes of record
264      * @return Object corresponding to bytes
265      */

266
267     public Object JavaDoc getObject(BufferRange[] bytes)throws DException {
268             int len = bytes.length ;
269             Object JavaDoc [] values = new Object JavaDoc[len];
270             for(int i = 0 ; i < len ; i++)
271                 values[i] = getObject(i,bytes[i]);
272             return values;
273     }
274
275     /**
276      * Converts bytes of given columns into Objects
277      * @param column indexes whose bytes have to convert into Objects
278      * @param bytes which has to convert into Objects
279      * @return Object corresponding to bytes
280      */

281
282     public Object JavaDoc getObject(int[] columns,BufferRange[] bytes)throws DException{
283       int len = columns.length;
284        Object JavaDoc[] values = new Object JavaDoc[len];
285        for(int i = 0 ; i < len ; i++)
286            values[i] = getObject(columns[i],bytes[i]);
287        return values;
288     }
289     /**
290      * Retuns bufferrange of value passed to it.
291      *
292      * @param columnIndex int - not used.
293      * @param values Object - whose bufferrange is needed.
294      * @throws DException
295      * @return BufferRange - bufferrange of passed object.
296      */

297     public BufferRange getBufferRange(int columnIndex, Object JavaDoc values) throws DException {
298             return ((FieldBase)values).getBufferRange();
299     }
300     /**
301      * Retuns bufferrange[] of values[] passed to it.
302      *
303      * @param columnIndexes int[] - not used
304      * @param values Object[] - whose bufferrange is to be required.
305      * @throws DException
306      * @return BufferRange[] - bufferrange of values passed to it.
307      */

308     public BufferRange[] getBufferRange(int[] columnIndexes, Object JavaDoc[] values) throws DException {
309           int len = values.length ;
310           BufferRange[] columnBytes = new BufferRange[len];
311           for(int i = 0 ; i < len ; i++)
312                 columnBytes[i] = ((FieldBase)values[i]).getBufferRange();
313             return columnBytes;
314     }
315     /**
316      * Retuns bufferrange[] of values[] passed to it.
317      *
318      * @param values Object[] - whose bufferrange is to be required.
319      * @throws DException
320      * @return BufferRange[] - bufferrange of values passed to it.
321      */

322
323     public BufferRange[] getBufferRange(Object JavaDoc[] values) throws DException {
324           int len = values.length ;
325           BufferRange[] columnBytes = new BufferRange[len];
326             for(int i = 0 ; i < len ; i++)
327                 columnBytes[i] = ((FieldBase)values[i]).getBufferRange();
328             return columnBytes;
329     }
330     /**
331      * Sets collator.
332      * @param collator0 Collator
333      * @throws DException
334      */

335     public void setCollator(Collator collator0) throws DException{
336         collator = collator0;
337         byteHandler = new CbCzufIboemfs[columnCount];
338         for(int i = 0 ; i < columnCount ; i++ )
339             byteHandler[i] = ByteHandler.getByteHandler(columnTypes[i],columnSizes[i],collator);
340     }
341     /**
342      * @return Collator
343      */

344     public Collator getCollator() {
345         return collator;
346     }
347     /**
348      * @return int[] startAddress of all blob clob columns.
349      */

350     public int[] getStartAddressesOfBlobColumns() {
351         return startAddrsesses;
352     }
353 }
354
Popular Tags