KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datadictionarysystem > ColumnCharacteristics


1 package com.daffodilwoods.daffodildb.server.datadictionarysystem;
2
3 import java.io.*;
4 import java.text.*;
5 import java.util.*;
6
7 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
8 import com.daffodilwoods.daffodildb.server.sql99.*;
9 import com.daffodilwoods.daffodildb.server.sql99.common.*;
10 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*;
11 import com.daffodilwoods.daffodildb.server.sql99.ddl.utility.*;
12 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
13 import com.daffodilwoods.daffodildb.utils.*;
14 /**
15  * Title:
16  * Description:
17  * Copyright: Copyright (c) 2001
18  * Company: Daffodil Software Pvt. Ltd.
19  * @author
20  * @version 1.0
21  */

22 import com.daffodilwoods.database.general.*;
23 import com.daffodilwoods.database.resource.*;
24 import com.daffodilwoods.database.utility.*;
25
26 public class ColumnCharacteristics implements _ColumnCharacteristics, Datatype /*,Externalizable*/ {
27
28    private PreparedStatementGetter preparedStatementGetter;
29
30    private QualifiedIdentifier tableName;
31
32    private int columnCount = 0;
33
34    private ColumnProperties[] columnPropertiesArray;
35
36    /* stores columnIndexes corresponding to columnNames */
37    private TreeMap columnIndexesMap;
38
39    private boolean searchedPrimaryKey;
40    private String JavaDoc[] primaryKeys;
41    private int[] primaryKeyIndexes;
42
43    private String JavaDoc table_Catalog;
44    private String JavaDoc table_Schema;
45    private String JavaDoc table_Name;
46    private short tableType;
47    private Collator collator;
48
49    private String JavaDoc country;
50    private String JavaDoc language;
51
52    public ColumnCharacteristics(QualifiedIdentifier tableName, PreparedStatementGetter preparedStatementGetter0, boolean addSystemFields) throws InitializeException, DException {
53       this.tableName = tableName;
54       preparedStatementGetter = preparedStatementGetter0;
55       setColumnProperties(addSystemFields);
56    }
57
58    /*
59     * return the index of passed columnName 0 if the column is first column
60     */

61    public int getColumnIndex(String JavaDoc columnName) throws DException {
62       if (columnName == null)
63          throw new IllegalColumnException("DSE3514", new String JavaDoc[] {columnName, tableName.getIdentifier()});
64       Integer JavaDoc index = (Integer JavaDoc) columnIndexesMap.get(columnName);
65       if (index == null) {
66          int dotIndex = columnName.lastIndexOf('.');
67          if (dotIndex != -1)
68             columnName = columnName.substring(dotIndex + 1);
69          index = (Integer JavaDoc) columnIndexesMap.get(columnName);
70          if (index == null)
71             throw new IllegalColumnException("DSE3514", new String JavaDoc[] {columnName, tableName.getIdentifier()});
72          else
73             return index.hashCode();
74       }
75       return index.hashCode();
76    }
77
78    public int[] getColumnIndexes(String JavaDoc[] columnNames) throws DException {
79       if (columnNames == null)
80          throw new IllegalColumnException("DSE749", (Object JavaDoc[])null);
81       int len = columnNames.length;
82       int[] columnIndexes = new int[len];
83       for (int i = 0; i < len; i++)
84          columnIndexes[i] = getColumnIndex(columnNames[i]);
85       return columnIndexes;
86    }
87
88    /*
89     * returns the columns present in the given table
90     */

91    public String JavaDoc[] getColumnNames() throws DException {
92       String JavaDoc[] columnNames = new String JavaDoc[columnCount];
93       for (int i = 0; i < columnCount; i++)
94          columnNames[i] = columnPropertiesArray[i].columnName;
95       return columnNames;
96    }
97
98    /*
99     * returns the columnName at the given postion
100     * Note :- 0 means first column
101     */

102    public String JavaDoc getColumnName(int columnIndex) throws DException {
103       try {
104          return columnPropertiesArray[columnIndex].columnName;
105       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
106          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(columnIndex), tableName.getIdentifier()});
107       }
108    }
109
110    /*
111     * returns the total number of columns in the table
112     */

113    public int getColumnCount() throws DException {
114       return columnCount;
115    }
116
117    /*
118     * returns the values of the given columnIndex in the form of byte[]
119     */

120
121    /*
122     * returns the bytes size of the column
123     */

124    public int getSize(int columnIndex) throws DException {
125       try {
126          return columnPropertiesArray[columnIndex].size;
127       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
128          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(columnIndex), tableName.getIdentifier()});
129       }
130    }
131
132    /*
133     * returns the type of the column
134     */

135    public int getColumnType(int columnIndex) throws DException {
136       try {
137          return columnPropertiesArray[columnIndex].type;
138       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
139          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(columnIndex), tableName.getIdentifier()});
140       }
141    }
142
143    /*
144     * return the precision of the given column.
145     */

146    public int getPrecision(int columnIndex) throws DException {
147       try {
148          return columnPropertiesArray[columnIndex].precision;
149       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
150          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(columnIndex), tableName.getIdentifier()});
151       }
152    }
153
154    /*
155     * returns the table related to the given table (i.e. the table which is referenced by
156      the given column )
157     */

158    public String JavaDoc getRelatedTable(int columnIndex) throws DException {
159       ColumnProperties columnProperties = columnPropertiesArray[columnIndex];
160       String JavaDoc columnName = columnProperties.columnName;
161       if (columnProperties.relatedTable == null || ! (columnProperties.relatedTable.equals("?")))
162          return columnProperties.relatedTable;
163       _SelectQueryIterator iterator = getIterator(preparedStatementGetter.getTablesForeignConstriaintExecuter(),
164                                                   getParametersToGetRelatedTable(tableName, columnName));
165       setRelatedTable(columnProperties, iterator);
166       return columnProperties.relatedTable;
167    }
168
169    public String JavaDoc getRelation(int columnIndex) throws DException {
170       ColumnProperties columnProperties = columnPropertiesArray[columnIndex];
171       if (columnProperties.relation == null || ! (columnProperties.relation.equals("?")))
172          return columnProperties.relation;
173       String JavaDoc referencedTable = getRelatedTable(columnIndex);
174       return columnProperties.relation;
175    }
176
177    public String JavaDoc[] getRelatedColumns(int columnIndex) throws DException {
178       ColumnProperties columnProperties = columnPropertiesArray[columnIndex];
179       if (columnProperties.relation == null || ! (columnProperties.relation.equals("?")))
180          return columnProperties.relatedColumns;
181       String JavaDoc referencedTable = getRelatedTable(columnIndex);
182       return columnProperties.relatedColumns;
183    }
184
185    public String JavaDoc[] getPrimaryKeys() throws DException {
186       if (!searchedPrimaryKey)
187          setPrimaryKeys();
188       return primaryKeys;
189    }
190
191    public void setPrimaryKeys() throws DException {
192       primaryKeys = new String JavaDoc[] {SystemFields.systemFields[SystemFields.rowId]};
193
194       searchedPrimaryKey = true;
195
196       try {
197          _SelectQueryIterator iterator = getIterator(preparedStatementGetter.getPrimaryKeysExecuter(), breakTableName(tableName));
198
199          ArrayList primaryKeysList = new ArrayList();
200          if (iterator.first()) {
201             do {
202                Object JavaDoc[] values = (Object JavaDoc[]) iterator.getObject();
203                primaryKeysList.add(values[0]);
204             } while (iterator.next());
205             primaryKeys = (String JavaDoc[]) primaryKeysList.toArray(new String JavaDoc[0]);
206          } else {
207             primaryKeys = new String JavaDoc[] {SystemFields.systemFields[SystemFields.rowId], };
208          }
209       } catch (Exception JavaDoc e) {
210          e.printStackTrace();
211
212          primaryKeys = new String JavaDoc[] {SystemFields.systemFields[SystemFields.rowId]};
213       }
214    }
215
216    public int[] getPrimaryConditionColumns() throws DException {
217       if (primaryKeyIndexes == null) {
218          getPrimaryKeys();
219          primaryKeyIndexes = getColumnIndexes(primaryKeys);
220       }
221       return primaryKeyIndexes;
222    }
223
224    private void setRelatedTable(ColumnProperties columnProperties, _SelectQueryIterator iterator) throws DException {
225       try {
226          Object JavaDoc[] values = null;
227          if (iterator.first()) {
228             Object JavaDoc[] constraintvalues = (Object JavaDoc[]) iterator.getObject();
229             int ordinalPosition = constraintvalues[3].hashCode();
230             _SelectQueryIterator relatedIterator = getIterator(preparedStatementGetter.getrelatedTableAndColumnExecuter(),
231                 new Object JavaDoc[] {constraintvalues[0], constraintvalues[1], constraintvalues[2]});
232             int index = 1;
233             relatedIterator.first();
234             do {
235                if (index == ordinalPosition) {
236                   values = (Object JavaDoc[]) relatedIterator.getObject();
237                }
238                index++;
239             } while (relatedIterator.next());
240
241          }
242          columnProperties.relatedTable = values == null ? null : values[0] + "."
243              + values[1] + "." + values[2];
244          columnProperties.relation = values == null ? null : values[3] + " = ?";
245          columnProperties.relatedColumns = values == null ? null : new String JavaDoc[] { (String JavaDoc) values[3]};
246       } catch (Exception JavaDoc e) {
247          e.printStackTrace();
248       }
249    }
250
251    private Object JavaDoc[] getParametersToGetRelatedTable(QualifiedIdentifier tableName, String JavaDoc columnName) throws DException {
252       Object JavaDoc[] parameters = new Object JavaDoc[4];
253       parameters[0] = tableName.catalog;
254       parameters[1] = tableName.schema;
255       parameters[2] = tableName.name;
256       parameters[3] = columnName;
257       return parameters;
258    }
259
260    private String JavaDoc[] breakTableName(QualifiedIdentifier tableName) throws DException {
261       String JavaDoc[] breakedTableName = new String JavaDoc[3];
262       breakedTableName[0] = tableName.catalog;
263       breakedTableName[1] = tableName.schema;
264       breakedTableName[2] = tableName.name;
265       return breakedTableName;
266    }
267
268    private void setColumnProperties(boolean addSystemFields) throws InitializeException, DException {
269       columnIndexesMap = new TreeMap(String.CASE_INSENSITIVE_ORDER);
270
271       ColumnProperties[] systemFieldsProperties = addSystemFields ? getSystemFieldsProperties()
272           : null;
273       int startIndex = addSystemFields ? systemFieldsProperties.length : 0;
274       ColumnProperties[] properties = isSystemTable() ? getSystemTablesColumnProperties()
275           : getColumnProperties();
276       if (systemFieldsProperties == null)
277          columnPropertiesArray = properties;
278       else if (tableType == TypeConstants.VIEW) {
279          columnPropertiesArray = properties;
280          columnCount = columnCount - startIndex;
281       } else {
282          int propertiesLen = properties.length;
283          boolean isrowIdColumn = false;
284          ArrayList propertiesList = new ArrayList();
285          for (int i = 0; i < propertiesLen; i++) {
286             isrowIdColumn = properties[i].columnName.equalsIgnoreCase(SystemFields.systemFields[SystemFields.rowId]);
287             if (isrowIdColumn) {
288                systemFieldsProperties[0] = properties[i];
289                columnCount--;
290             } else
291                propertiesList.add(properties[i]);
292          }
293          properties = (ColumnProperties[]) propertiesList.toArray(new ColumnProperties[0]);
294          propertiesLen = propertiesList.size();
295          columnPropertiesArray = new ColumnProperties[columnCount];
296          System.arraycopy(systemFieldsProperties, 0, columnPropertiesArray, 0, startIndex);
297          System.arraycopy(properties, 0, columnPropertiesArray, startIndex, propertiesLen);
298       }
299       for (int c = 0; c < columnCount; c++)
300          columnIndexesMap.put(columnPropertiesArray[c].columnName, new Integer JavaDoc(c));
301       if (primaryKeys != null) {
302          searchedPrimaryKey = true;
303       }
304    }
305
306    private ColumnProperties[] getSystemFieldsProperties() throws DException {
307       Object JavaDoc[][] systemFields = CharacteristicsConstants.systemFieldsProperties;
308       int noOfSystemFields = systemFields.length;
309       ColumnProperties[] systemFieldsProperties = new ColumnProperties[noOfSystemFields];
310       for (int i = 0; i < noOfSystemFields; i++) {
311          systemFieldsProperties[i] = new ColumnProperties();
312          systemFieldsProperties[i].columnName = (String JavaDoc) systemFields[i][0];
313          systemFieldsProperties[i].type = systemFields[i][1].hashCode();
314          systemFieldsProperties[i].size = systemFields[i][2].hashCode();
315          systemFieldsProperties[i].precision = systemFields[i][3].hashCode();
316          columnCount++;
317       }
318       return systemFieldsProperties;
319    }
320
321    private ColumnProperties[] getSystemTablesColumnProperties() throws DException {
322       Object JavaDoc[][] systemTablesColumns = SystemTablesCreator.getTableStructure(tableName);
323       return getSystemTableColumnsProperties(systemTablesColumns);
324    }
325
326    private ColumnProperties[] getSystemTableColumnsProperties(Object JavaDoc[][] systemTablesColumns) throws DException {
327       int noOfColumns = systemTablesColumns.length;
328       ColumnProperties[] systemTablesProperties = new ColumnProperties[noOfColumns];
329       for (int i = 0; i < noOfColumns; i++) {
330          systemTablesProperties[i] = new ColumnProperties();
331          systemTablesProperties[i].columnName = (String JavaDoc) systemTablesColumns[i][0];
332          systemTablesProperties[i].type = systemTablesColumns[i][1].hashCode();
333          int byteSize = systemTablesColumns[i][2].hashCode();
334          systemTablesProperties[i].precision = ColumnCharacteristicsUtilities.getPrecision(systemTablesProperties[i].type, byteSize);
335          boolean fixed = ( (Boolean JavaDoc) systemTablesColumns[i][3]).booleanValue();
336          systemTablesProperties[i].size = byteSize; //fixed ? byteSize : -1; ????
337
systemTablesProperties[i].domainCatalog = (String JavaDoc) systemTablesColumns[i][4];
338          systemTablesProperties[i].domainSchema = (String JavaDoc) systemTablesColumns[i][5];
339          systemTablesProperties[i].domainName = (String JavaDoc) systemTablesColumns[i][6];
340          columnCount++;
341       }
342       tableType = TypeConstants.TABLE;
343       collator = null; //Collator.getInstance(new Locale(SqlSchemaConstants.defaultCountryCode,SqlSchemaConstants.defaultLanguageCode));
344
primaryKeys = SystemTablesCreator.getPrimaryKeys(tableName);
345       return systemTablesProperties;
346    }
347
348    private ColumnProperties[] getColumnProperties() throws DException {
349       String JavaDoc[] breakedTableName = breakTableName(tableName);
350       _SelectQueryIterator columnIterator = getIterator(preparedStatementGetter.getcolumnExecuter(), breakedTableName);
351       if (!columnIterator.first()) {
352          throw new DException("DSE959", new Object JavaDoc[] {tableName.getIdentifier()});
353       }
354       ArrayList propertiesList = new ArrayList(10);
355       TreeMap identifierList = new TreeMap(String.CASE_INSENSITIVE_ORDER);
356       Object JavaDoc[] record = null;
357       do {
358          ColumnProperties columnProperties = new ColumnProperties();
359          record = (Object JavaDoc[]) columnIterator.getObject();
360
361          identifierList.put(record[SystemTablesFields.columns_dtd_identifier],
362                             record[SystemTablesFields.columns_ordinal_position]);
363
364          columnProperties.columnName = (String JavaDoc) record[SystemTablesFields.columns_column_name];
365          columnProperties.isNullable = ( (String JavaDoc) record[SystemTablesFields.columns_is_nullable]).equalsIgnoreCase("YES") ? 1 : 0;
366          columnProperties.domainCatalog = (String JavaDoc) record[SystemTablesFields.columns_domain_catalog];
367          columnProperties.isAutoIncrement = ( (String JavaDoc) record[SystemTablesFields.columns_is_autoIncrement]).equalsIgnoreCase("YES");
368          columnProperties.domainSchema = (String JavaDoc) record[SystemTablesFields.columns_domain_schema];
369          columnProperties.domainName = (String JavaDoc) record[SystemTablesFields.columns_domain_name];
370          columnCount++;
371          propertiesList.add(columnProperties);
372       } while (columnIterator.next());
373       _SelectQueryIterator iterator = getIterator(preparedStatementGetter.getDataTypeExecuter(), breakedTableName);
374       if (iterator.first()) {
375          do {
376             Object JavaDoc[] values = (Object JavaDoc[]) iterator.getObject();
377             String JavaDoc identifier = (String JavaDoc) values[SystemTablesFields.data_type_descriptor_dtd_identifier];
378             int columnIndex = identifierList.get(identifier).hashCode() - 1;
379             ColumnProperties columnProperties = (ColumnProperties) propertiesList.get(columnIndex);
380
381             int type = com.daffodilwoods.database.utility.TypeConverter.getDataBaseType( (String JavaDoc) values[SystemTablesFields.data_type_descriptor_data_type]);
382             int numPecision = values[SystemTablesFields.data_type_descriptor_numeric_precision] == null ? 0 :
383                 values[SystemTablesFields.data_type_descriptor_numeric_precision].hashCode();
384             int charLength = values[SystemTablesFields.data_type_descriptor_character_maximum_length] == null ? 0 :
385                 values[SystemTablesFields.data_type_descriptor_character_maximum_length].hashCode();
386             int decimal = values[SystemTablesFields.data_type_descriptor_numeric_scale] == null ? 0 :
387                 values[SystemTablesFields.data_type_descriptor_numeric_scale].hashCode();
388             int datePrecision = values[SystemTablesFields.data_type_descriptor_datetime_precision] == null ? 0 :
389                 values[SystemTablesFields.data_type_descriptor_datetime_precision].hashCode();
390             int intervalPrecision = values[SystemTablesFields.data_type_descriptor_interval_precision] == null ? 0 :
391                 values[SystemTablesFields.data_type_descriptor_interval_precision].hashCode();
392             boolean fixed = isFixed(type);
393             columnProperties.precision = GeneralUtility.getPrecision(charLength, numPecision, datePrecision, intervalPrecision);
394             columnProperties.type = type;
395             columnProperties.decimal = decimal;
396             int byteSize = GeneralUtility.getBytesCount(type, columnProperties.precision);
397             columnProperties.size = byteSize;
398          } while (iterator.next());
399       }
400       _SelectQueryIterator tableTypeAndCodesIterator = getIterator(preparedStatementGetter.getTableTypesAndCodesExecuter(), new Object JavaDoc[] {breakedTableName[0], breakedTableName[1], breakedTableName[2]});
401       if (tableTypeAndCodesIterator.first()) {
402          Object JavaDoc[] data = ( (Object JavaDoc[]) tableTypeAndCodesIterator.getObject());
403          String JavaDoc type = (String JavaDoc) data[0];
404          tableType = type.equalsIgnoreCase(SqlKeywords.VIEW) ? TypeConstants.VIEW : TypeConstants.TABLE;
405          if (data[1] != null) {
406             language = (String JavaDoc) data[1];
407             country = (String JavaDoc) data[2];
408             collator = Collator.getInstance(new Locale(language, country));
409          }
410       }
411       ColumnProperties[] cp = new ColumnProperties[propertiesList.size()];
412       return (ColumnProperties[]) propertiesList.toArray(cp);
413    }
414
415    public short getTableType() throws DException {
416       return tableType;
417    }
418
419    private boolean isFixed(int type) throws DException {
420       return! (type == ARRAY || type == BIGDECIMAL || type == VARCHAR ||
421                type == NUMERIC || type == DECIMAL || type == DEC ||
422                type == CHARACTERVARYING || type == CHARVARYING ||
423                type == BITVARYING || type == SUM ||
424                type == VARBINARY || type == REF || type == STRUCT);
425    }
426
427    private boolean isSystemTable() throws DException {
428       return P.indexOfIgnoreCase(SystemTablesCreator.tableNames, tableName.getIdentifier()) != -1 ||
429           tableName.equals(SystemTables.TABLEINFO) ||
430           tableName.equals(SystemTables.INDEXINFO) ||
431           tableName.equals(SystemTables.CLUSTERINFO) ||
432           tableName.equals(SystemTables.COLUMNINFO) ||
433           tableName.equals(SystemTables.DATABASEINFO);
434    }
435
436    /**/
437
438 // }*/
439

440    public String JavaDoc getTableName(int index) throws DException {
441       try {
442          String JavaDoc check = columnPropertiesArray[index].domainCatalog;
443       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
444          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(index), tableName.getIdentifier()});
445       }
446       return tableName.name;
447    }
448
449    public int getScale(int columnIndex) throws DException {
450       try {
451          return columnPropertiesArray[columnIndex].decimal;
452       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
453          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(columnIndex), tableName.getIdentifier()});
454       }
455
456    }
457
458    public String JavaDoc getSchemaName(int columnIndex) throws DException {
459       try {
460          String JavaDoc check = columnPropertiesArray[columnIndex].domainCatalog;
461       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
462          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(columnIndex), tableName.getIdentifier()});
463       }
464       return (breakTableName(tableName))[1];
465
466    }
467
468    public String JavaDoc getCatalogName(int columnIndex) throws DException {
469       try {
470          String JavaDoc check = columnPropertiesArray[columnIndex].domainCatalog;
471       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
472          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(columnIndex), tableName.getIdentifier()});
473       }
474       return (breakTableName(tableName))[0];
475    }
476
477    public int isNullable(int columnIndex) throws DException {
478       try {
479          return columnPropertiesArray[columnIndex].isNullable;
480       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
481          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(columnIndex), tableName.getIdentifier()});
482       }
483    }
484
485    public String JavaDoc getColumnLabel(int index) throws DException {
486       return getColumnName(index);
487    }
488
489    public String JavaDoc getDomainCatalog(int index) throws DException {
490       try {
491          return columnPropertiesArray[index].domainCatalog;
492       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
493          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(index), tableName.getIdentifier()});
494       }
495    }
496
497    public String JavaDoc getDomainSchema(int index) throws DException {
498       try {
499          return columnPropertiesArray[index].domainSchema;
500       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
501          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(index), tableName.getIdentifier()});
502       }
503    }
504
505    public String JavaDoc getDomainName(int index) throws DException {
506       try {
507          return columnPropertiesArray[index].domainName;
508       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
509          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(index), tableName.getIdentifier()});
510       }
511    }
512
513    public int[] getDomainColumnIndexes() throws DException {
514       int[] domainIndexes = new int[columnCount];
515       int j = 0;
516       for (int i = 0; i < columnCount; i++)
517          if (! (columnPropertiesArray[i].domainName == null || columnPropertiesArray[i].domainName.equals(""))) {
518             domainIndexes[j++] = i;
519          }
520       if (j == 0)
521          return null;
522       int[] temp = new int[j];
523       System.arraycopy(domainIndexes, 0, temp, 0, j);
524       return temp;
525    }
526
527    public Collator getCollator() throws DException {
528       return collator;
529    }
530
531    public String JavaDoc getCountry() throws DException {
532       return country;
533    }
534
535    public String JavaDoc getLanguage() throws DException {
536       return language;
537    }
538
539    /* public void writeExternal(ObjectOutput out) throws IOException{
540            out.writeObject(tableName);
541            out.writeInt(columnCount);
542            out.writeObject(columnPropertiesArray);
543            out.writeObject(columnIndexesMap);
544            out.writeBoolean(searchedPrimaryKey);
545            out.writeObject(primaryKeys);
546            out.writeObject(primaryKeyIndexes);
547            out.writeObject(primaryConitionColumns);
548            out.writeObject(primaryCondition);
549            out.writeObject(recordConitionColumns);
550            out.writeObject(recordCondition);
551            out.writeObject(table_Catalog);
552            out.writeObject(table_Schema);
553            out.writeObject(table_Name);
554            out.writeObject(new Short(tableType));
555       }
556        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException{
557          tableName =(QualifiedIdentifier)in.readObject();
558          columnCount = in.readInt();
559          columnPropertiesArray = (ColumnProperties[])in.readObject();
560          columnIndexesMap = (TreeMap)in.readObject();
561          searchedPrimaryKey = in.readBoolean();
562          primaryKeys = (String[])in.readObject();
563          primaryKeyIndexes = (int[])in.readObject();
564          primaryConitionColumns = (String[])in.readObject();
565          primaryCondition = (_UBVE)in.readObject();
566          recordConitionColumns = (String[])in.readObject();
567          recordCondition = (_UBVE)in.readObject();
568          table_Catalog = (String)in.readObject();
569          table_Schema = (String)in.readObject();
570          table_Name = (String)in.readObject();
571          tableType = ((Short)in.readObject()).shortValue();
572        }*/

573
574    /* private CbCzufIboemfs getByteHandler(int type,int size) throws DException{
575        CCzufIboemfsGbdupsz byteHandlerFactory = CCzufIboemfsGbdupsz.getByteHandlerFactory();
576        switch (type ){
577          case BINARY :
578                        return byteHandlerFactory.getBinaryHandler(size);
579          case VARBINARY :
580                        return byteHandlerFactory.getVarBinaryHandler(size);
581          case CHARVARYING :
582          case CHARACTERVARYING :
583          case BITVARYING :
584          case VARCHAR :
585                        return byteHandlerFactory.getVariableStringHandler(size);
586          case BIT :
587          case CHAR :
588          case CHARACTER :
589                        return byteHandlerFactory.getStringHandler(size,' ');
590          case BOOLEAN :
591                        return byteHandlerFactory.getBooleanHandler();
592          case TIME :
593                        return byteHandlerFactory.getTimeHandler();
594          case TIMESTAMP :
595                        return byteHandlerFactory.getTimeStampHandler();
596          case DATE :
597                        return byteHandlerFactory.getDateHandler();
598          case FLOAT :
599          case DOUBLEPRECISION :
600          case DOUBLE :
601                        return byteHandlerFactory.getDoubleHandler();
602          case REAL :
603                        return byteHandlerFactory.getFloatHandler();
604          case INT :
605          case INTEGER :
606                        return byteHandlerFactory.getIntHandler();
607          case LONG :
608          case BIGINT :
609          case MODULE :
610                        return byteHandlerFactory.getLongHandler();
611          case SMALLINT :
612          case SHORT :
613                        return byteHandlerFactory.getShortHandler();
614          case DEC :
615          case DECIMAL :
616          case NUMERIC :
617          case BIGDECIMAL :
618                        return byteHandlerFactory.getBigDecimalHandler();
619          case BINARYLARGEOBJECT :
620          case LONGVARBINARY :
621          case BLOB :
622                        return byteHandlerFactory.getBlobHandler();
623          case TINYINT :
624          case BYTE :
625                        return byteHandlerFactory.getByteObjectHandler();
626          case CHARACTERLARGEOBJECT :
627          case LONGVARCHAR :
628          case CHARLARGEOBJECT :
629          case CLOB :
630                        return byteHandlerFactory.getClobHandler();
631        }
632        throw new DException( "DSE515", new Object[]{new Integer(type)});
633       }*/

634
635    /*public CbCzufIboemfs getByteHandler(int columnIndex) throws DException{
636      try{
637         return columnPropertiesArray[columnIndex].byteHandler;
638      } catch (ArrayIndexOutOfBoundsException e ){
639          throw new IllegalColumnException("DSE3514",new Object[] {new Integer(columnIndex),tableName.getIdentifier()});
640      }
641         }*/

642
643    public String JavaDoc getQualifiedTableName(int index) throws DException {
644       return tableName.getIdentifier();
645    }
646
647
648    class ColumnProperties implements Serializable {
649       public String JavaDoc columnName;
650
651       public int type = -1;
652
653       public int size = -2;
654
655       public int decimal = 0;
656
657       public int precision = 0;
658
659       public int isNullable = 0;
660
661       public String JavaDoc relatedTable = "?";
662
663       public String JavaDoc relation = "?";
664
665       public String JavaDoc[] relatedColumns = null;
666
667       public String JavaDoc domainCatalog;
668       public String JavaDoc domainSchema;
669       public String JavaDoc domainName;
670       public boolean isAutoIncrement;
671       public String JavaDoc schemaName;
672       public String JavaDoc catalogName;
673       public int columnIndex;
674       public String JavaDoc columnLabel;
675       public int columnPrecision;
676       public QualifiedIdentifier QualifiedTableName;
677       public int columnScale;
678       public String JavaDoc tableName;
679
680
681       public ColumnProperties() throws DException {
682       }
683
684       public ColumnProperties(_ColumnCharacteristics cc, int columnIndex0) throws DException {
685          catalogName = cc.getCatalogName(columnIndex0);
686          schemaName = cc.getSchemaName(columnIndex0);
687          columnName = cc.getColumnName(columnIndex0);
688          isAutoIncrement = cc.isAutoIncrement(columnIndex0);
689          isNullable = cc.isNullable(columnIndex0);
690          size = cc.getSize(columnIndex0);
691          type = cc.getColumnType(columnIndex0);
692          columnIndex = cc.getColumnIndex(cc.getColumnName(columnIndex0));
693          columnLabel = cc.getColumnLabel(columnIndex0);
694          columnPrecision = cc.getPrecision(columnIndex0);
695          tableName = cc.getTableName(columnIndex0);
696          QualifiedTableName = new QualifiedIdentifier(catalogName, schemaName, tableName);
697          columnScale = cc.getScale(columnIndex0);
698          relatedTable = cc.getRelatedTable(columnIndex0);
699          relation = cc.getRelation(columnIndex0);
700          relatedColumns = cc.getRelatedColumns(columnIndex0);
701       }
702    }
703
704    private _SelectQueryIterator getIterator(_Executer executer, Object JavaDoc[] parameters) throws DException {
705       return (_SelectQueryIterator) executer.executeForFresh(parameters);
706    }
707
708    public boolean isAutoIncrement(int columnIndex) throws DException {
709       try {
710          return columnPropertiesArray[columnIndex].isAutoIncrement;
711       } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
712          throw new IllegalColumnException("DSE3514", new Object JavaDoc[] {new Integer JavaDoc(columnIndex), tableName.getIdentifier()});
713       }
714    }
715
716    public _ColumnCharacteristics getCCFromIndexes(_ColumnCharacteristics cc, int offset, int[] columnIndexes) throws DException {
717       int columnCount = columnIndexes.length;
718       ColumnProperties[] columnProperties = new ColumnProperties[columnCount];
719       ColumnProperties cp = null;
720       for (int i = 0; i < columnCount; i++) {
721          int columnIndex = columnIndexes[i];
722          cp = new ColumnProperties(cc, columnIndex);
723          columnProperties[i] = cp;
724       }
725       return new SelectedColumnCharacteristics(columnProperties, cp.QualifiedTableName);
726    }
727
728 /* public ColumnCharacteristics(ColumnProperties[] columnProperties, QualifiedIdentifier tableName0) {
729       this.columnPropertiesArray = columnProperties;
730       columnCount = columnProperties.length;
731       tableName = tableName0;
732    }*/

733 }
734
Popular Tags