KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > resultsetmetadata > AllColumnRowReader


1 package com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
6 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
7 import com.daffodilwoods.daffodildb.server.sql99.common.*;
8 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*;
10 import com.daffodilwoods.daffodildb.utils.comparator.*;
11 import com.daffodilwoods.daffodildb.utils.field.*;
12 import com.daffodilwoods.database.general.*;
13 import com.daffodilwoods.database.general.TypeConverter;
14 import com.daffodilwoods.database.resource.*;
15 import com.daffodilwoods.database.utility.*;
16
17 /**
18  * It represents row reader in case when resultset is of UPDATABLE type.
19  * It allows user to read the row returned by the resultset of select query as
20  * well as provide the facility of performing modifications through the
21  * resultset taken on the select query.
22  * <p>Title: </p>
23  * <p>Description: </p>
24  * <p>Copyright: Copyright (c) 2003</p>
25  * <p>Company: </p>
26  * @author unascribed
27  * @version 1.0
28  */

29
30 public class AllColumnRowReader implements _AllColumnRowReader, _RowReader {
31
32    /**
33     * Represents the position of selected columns in row returned by resultset.
34     */

35
36    protected int[] selectColumnMapping;
37
38    /**
39     * Represents the position of key columns in row returned by resultset.
40     */

41
42    protected int[] keyColumnMapping;
43
44    /**
45     * Represents the mapping of table, its characteristics and its start
46     * position in the row.
47     */

48
49    protected Object JavaDoc[][] tableDetailsCCMapping; // 0 - tableDetails , 1 - CC , 2 - startposition
50

51    /**
52     * Represents the length of row.
53     */

54
55    protected int allColumnLength;
56
57    /**
58     * Represents the mapping of functional columns and its position in the row.
59     */

60
61    protected Object JavaDoc[][] functionalKeyColumnMapping;
62
63    /**
64     * Represents the characteristics of selected columns.
65     */

66
67    protected _ColumnCharacteristics selectColumnCharacteristics;
68
69    /**
70     * Represents the key column information of select query.
71     */

72
73    protected SelectKeyColumnInformation selectKeyColumnInformation;
74
75    /**
76     * Represents the name of first table involved in 'from clause'.
77     */

78
79    protected String JavaDoc firstName;
80
81    /**
82     * Represents the chained columns.
83     */

84
85    protected ForeignKeyColumns[] columns;
86
87    /**
88     * Represents all key column information present in select query.
89     */

90
91    protected _KeyColumnInformation[] keyColumnInformation;
92
93    /**
94     * Represents the selected columns of select query.
95     */

96
97    protected ColumnDetails[] selectListColumnDetails;
98
99    /**
100     * Initializes the mapping of selected columns and its position in the row.
101     * Initializes the mapping of key columns and its position in the row.
102     * Initializes the key column information of select query.
103     * @param selectColumnDetails
104     * @param keyColumnInformation
105     * @param functionalKeyColumnMapping1
106     * @param tableDetailsCCMapping1
107     * @param allColumnLength1
108     * @param selectColumnCharacteristics1
109     * @param columns0
110     * @param isAggregateAndNoGroup
111     * @throws DException
112     */

113    public AllColumnRowReader(ColumnDetails[] selectColumnDetails, _KeyColumnInformation[] keyColumnInformation, Object JavaDoc[][] functionalKeyColumnMapping1, Object JavaDoc[][] tableDetailsCCMapping1, int allColumnLength1, _ColumnCharacteristics selectColumnCharacteristics1, ForeignKeyColumns[] columns0, boolean isAggregateAndNoGroup) throws DException {
114       tableDetailsCCMapping = tableDetailsCCMapping1;
115       selectListColumnDetails = selectColumnDetails;
116       functionalKeyColumnMapping = functionalKeyColumnMapping1;
117       this.keyColumnInformation = keyColumnInformation;
118       initializeSelectColumnMapping(selectColumnDetails, functionalKeyColumnMapping, tableDetailsCCMapping);
119
120       initializeKeyColumnMapping(keyColumnInformation, functionalKeyColumnMapping, tableDetailsCCMapping);
121
122       allColumnLength = allColumnLength1;
123       selectColumnCharacteristics = selectColumnCharacteristics1;
124       selectKeyColumnInformation = new SelectKeyColumnInformation(keyColumnInformation, keyColumnMapping, isAggregateAndNoGroup);
125       columns = columns0;
126    }
127
128    /**
129     * Initializes the mapping of key columns and its position in the row.
130     * Initializes the key column information of select query.
131     * @param keyColumnInformation1
132     * @param functionalKeyColumnMapping1
133     * @param tableDetailsCCMapping1
134     * @param allColumnLength1
135     * @param selectColumnCharacteristics1
136     * @param firstName1
137     * @param isAggregateAndNoGroup
138     * @throws DException
139     */

140
141    public AllColumnRowReader(_KeyColumnInformation[] keyColumnInformation1, Object JavaDoc[][] functionalKeyColumnMapping1, Object JavaDoc[][] tableDetailsCCMapping1, int allColumnLength1, _ColumnCharacteristics selectColumnCharacteristics1, String JavaDoc firstName1, boolean isAggregateAndNoGroup) throws DException {
142       tableDetailsCCMapping = tableDetailsCCMapping1;
143       functionalKeyColumnMapping = functionalKeyColumnMapping1;
144       keyColumnInformation = keyColumnInformation1;
145       initializeKeyColumnMapping(keyColumnInformation1, functionalKeyColumnMapping1, tableDetailsCCMapping1);
146       allColumnLength = allColumnLength1;
147       selectColumnCharacteristics = selectColumnCharacteristics1;
148       selectKeyColumnInformation = new SelectKeyColumnInformation(keyColumnInformation, keyColumnMapping, isAggregateAndNoGroup);
149       firstName = firstName1;
150    }
151
152    /**
153     * This method is used to obtain the key present in row.
154     * @param row
155     * @return
156     * @throws DException
157     */

158
159    public Object JavaDoc getKey(Object JavaDoc row) throws DException {
160       return selectKeyColumnInformation.getKey(row);
161    }
162
163    /**
164     * This method is used to obtain array of int from the arraylist which
165     * contains Integer objects.
166     * @param aList
167     * @return
168     */

169
170    protected int[] getIntArrayFromList(ArrayList aList) {
171       Object JavaDoc[] object = aList.toArray();
172       int length = object.length;
173       int[] result = new int[length];
174       for (int i = 0; i < length; i++) {
175          result[i] = object[i].hashCode();
176       }
177       return result;
178    }
179
180    /**
181     * This method is used to obtain order specification of key columns.
182     * @param keyColumnInformation
183     * @return
184     * @throws DException
185     */

186
187    private boolean[] getOrderSpecification(_KeyColumnInformation[] keyColumnInformation) throws DException {
188       int length = keyColumnInformation.length;
189       boolean[] result = new boolean[length];
190       for (int i = 0; i < length; i++) {
191          result[i] = keyColumnInformation[i].getOrderSpecification();
192       }
193       return result;
194    }
195
196    /**
197     * This method initializes the mapping of selected columns and its position
198     * in the row. Selected columns may be either functional columns or normal
199     * columns of table. So appropriate mapping is used to find out the position.
200     * @param selectColumnDetails
201     * @param functionalKeyColumnMapping
202     * @param tableDetailsCCMapping
203     * @throws DException
204     */

205
206    private void initializeSelectColumnMapping(ColumnDetails[] selectColumnDetails, Object JavaDoc[][] functionalKeyColumnMapping, Object JavaDoc[][] tableDetailsCCMapping) throws DException {
207       int length = selectColumnDetails.length;
208       selectColumnMapping = new int[length];
209       for (int i = 0; i < length; i++) {
210          try {
211             TableDetails tableDetails = selectColumnDetails[i].getTableDetails();
212             selectColumnMapping[i] = (tableDetails == null ||
213                                       selectColumnDetails[i].getTableAliasArray() != null) ?
214                 getIndexFromFunctionalMapping(selectColumnDetails[i],
215                                               functionalKeyColumnMapping)
216                 : getIndexFromCC(selectColumnDetails[i], tableDetails);
217          } catch (DException ex) {
218             throw ex;
219          }
220       }
221    }
222
223    /**
224     * This method initializes the mapping of key columns and its position
225     * in the row. Key columns may be either functional columns or normal
226     * columns of table. So appropriate mapping is used to find out the position.
227     * @param keyColumnInformation
228     * @param functionalKeyColumnMapping
229     * @param tableDetailsCCMapping
230     * @throws DException
231     */

232
233    private void initializeKeyColumnMapping(_KeyColumnInformation[] keyColumnInformation, Object JavaDoc[][] functionalKeyColumnMapping, Object JavaDoc[][] tableDetailsCCMapping) throws DException {
234       int length = keyColumnInformation.length;
235       keyColumnMapping = new int[length];
236       for (int i = 0; i < length; i++) {
237          ColumnDetails columnDetails = keyColumnInformation[i].getColumnDetails();
238          TableDetails tableDetail = columnDetails.getTableDetails();
239          keyColumnMapping[i] = (tableDetail == null || columnDetails.getTableAliasArray() != null) ?
240              getIndexFromFunctionalMapping(columnDetails, functionalKeyColumnMapping)
241              : getIndexFromCC(columnDetails, tableDetail);
242       }
243    }
244
245    /**
246     * This method is used to find out the index of column. If passed column is
247     * normal column of table then its position is returned from the
248     * characteristics. If column is functional, its position is returned from
249     * functional mapping.
250     * @param columnDetails
251     * @param tableDetails
252     * @return
253     * @throws DException
254     */

255
256    private int getIndexFromCCActual(ColumnDetails columnDetails, TableDetails tableDetails) throws DException {
257       if (tableDetails == null || columnDetails.getTableAliasArray() != null) {
258          return getIndexFromFunctionalMapping(columnDetails, functionalKeyColumnMapping);
259       }
260       int length = tableDetailsCCMapping.length; // To Confirm CC gives index including the index of systemFields
261
for (int i = 0; i < length; i++) {
262          if (tableDetails == tableDetailsCCMapping[i][0]) {
263             return ( (_ColumnCharacteristics) tableDetailsCCMapping[i][1]).getColumnIndex(columnDetails.getOriginalColumn());
264          }
265       }
266       throw new DException("DSE3514", new Object JavaDoc[] {columnDetails.getColumn(), tableDetails.getNameOfTable()});
267    }
268
269    /**
270     * This method is used to find out the position of column from table. Also it
271     * calculates the position of that column in the row returned by resultset
272     * with the help of start position of values of that table in the row.
273     * @param columnDetails
274     * @param tableDetails
275     * @return
276     * @throws DException
277     */

278
279    private int getIndexFromCC(ColumnDetails columnDetails, TableDetails tableDetails) throws DException {
280       /*dst*/
281       int length = tableDetailsCCMapping.length; // To Confirm CC gives index including the index of systemFields
282
QualifiedIdentifier tableName = tableDetails.getQualifiedIdentifier();
283          for (int i = 0; i < length; i++) {
284            QualifiedIdentifier tblName = ((TableDetails)tableDetailsCCMapping[i][0]).getQualifiedIdentifier();
285             if (tableName.equals(tblName) ){
286                int ii = ( (_ColumnCharacteristics) tableDetailsCCMapping[i][1]).getColumnIndex(columnDetails.getColumn()) + tableDetailsCCMapping[i][2].hashCode();
287                return ii;
288             }
289          }
290          throw new DException("DSE3514", new Object JavaDoc[] {columnDetails.getColumn(), tableDetails.getNameOfTable()});
291          /*dend*/
292    }
293
294    /**
295     * This method is used to find out the index of functional column from mapping
296     * of functional columns.
297     * @param columnDetails
298     * @param functionalKeyColumnMapping
299     * @return
300     * @throws DException
301     */

302
303    private int getIndexFromFunctionalMapping(ColumnDetails columnDetails, Object JavaDoc[][] functionalKeyColumnMapping) throws DException {
304       int length = functionalKeyColumnMapping.length;
305       for (int i = 0; i < length; i++) {
306          if (columnDetails.getAppropriateColumn().equalsIgnoreCase( ( (ColumnDetails) functionalKeyColumnMapping[i][0]).getAppropriateColumn())) {
307             return functionalKeyColumnMapping[i][1].hashCode();
308          }
309       }
310       throw new DException("DSE3515", new Object JavaDoc[] {columnDetails.getColumn()});
311    }
312
313    /**
314     * Returns the blank row for select query. The length is equivalent to sum
315     * of number of columns present in all tables and number of functional columns
316     * present in select.
317     * @return
318     * @throws DException
319     */

320
321    public Object JavaDoc getBlankRow() throws DException {
322       return new Object JavaDoc[allColumnLength];
323    }
324
325    /**
326     * Sets the value of passed column represented by index in the passed row.
327     * @param columnIndex represents the index of selected column.
328     * @param value
329     * @param row
330     * @throws DException
331     */

332
333    public void setObject(int columnIndex, Object JavaDoc value, Object JavaDoc row) throws DException {
334       /*dst*/
335       if (value instanceof FieldBase) {
336             ( (Object JavaDoc[]) row)[selectColumnMapping[columnIndex - 1] - 1] = value;
337          } else {
338             ( (FieldBase) ( (Object JavaDoc[]) row)[selectColumnMapping[columnIndex - 1] - 1]).setObject(value);
339          }
340          /*dend*/
341    }
342
343    /**
344     * Sets the value of passed column represented by name in the passed row.
345     * @param columnName
346     * @param value
347     * @param row
348     * @throws DException
349     */

350
351    public void setObject(String JavaDoc columnName, Object JavaDoc value, Object JavaDoc row) throws DException {
352       int columnIndex = selectColumnCharacteristics.getColumnIndex(columnName);
353       setObject(columnIndex, value, row);
354    }
355
356    /**
357     * Sets the value of passed column of table at appropriate position in the
358     * row.
359     * @param tableInfo
360     * @param columnIndex
361     * @param value
362     * @param row
363     * @throws DException
364     */

365
366    public void setObject(_TableInfo tableInfo, int columnIndex, Object JavaDoc value, Object JavaDoc row) throws DException {
367       int index = getStartingIndex(tableInfo) + columnIndex;
368       if (value instanceof FieldBase) {
369          ( (Object JavaDoc[]) row)[index - 1] = value;
370       } else {
371          ( (FieldBase) ( (Object JavaDoc[]) row)[index - 1]).setObject(value);
372       }
373    }
374
375    /**
376     * Sets the value of columns at passed indexes from old row to new row.
377     * @param oldRow
378     * @param newRow
379     * @param columnIndexes
380     * @throws DException
381     */

382
383    public void setObjects(Object JavaDoc oldRow, Object JavaDoc newRow, int[] columnIndexes) throws DException {
384       for (int i = 0; i < columnIndexes.length; i++) {
385          int columnIndex = selectColumnMapping[columnIndexes[i] - 1] - 1;
386          ( (Object JavaDoc[]) oldRow)[columnIndex] = ( (Object JavaDoc[]) newRow)[columnIndex];
387       }
388    }
389
390    /**
391     * It is used to obtain the value of column of passed table at passed index
392     * from the passed row.
393     * @param tableInfo
394     * @param columnIndex
395     * @param row
396     * @return
397     * @throws DException
398     */

399
400    public Object JavaDoc getObject(_TableInfo tableInfo, int columnIndex, Object JavaDoc row) throws DException {
401       int index = getStartingIndex(tableInfo) + columnIndex;
402       return ( (Object JavaDoc[]) row)[index - 1];
403    }
404
405    /**
406     * It is used to obtain the value of column of passed table from the passed
407     * row.
408     * @param tableInfo
409     * @param columnName
410     * @param row
411     * @return
412     * @throws DException
413     */

414
415    public Object JavaDoc getObject(_TableInfo tableInfo, String JavaDoc columnName, Object JavaDoc row) throws DException {
416       /*dst*/
417       int index = getStartingIndex(tableInfo);
418          TableDetails td = getTableDetail(tableInfo);
419          index += td.getColumnCharacteristics().getColumnIndex(columnName);
420          return ( (Object JavaDoc[]) row)[index - 1];
421          /*dend*/
422    }
423
424    /**
425     * Used to find out the starting position of value of passed table in the
426     * row returned by resultset.
427     * @param tableInfo
428     * @return
429     * @throws DException
430     */

431
432    private int getStartingIndex(_TableInfo tableInfo) throws DException {
433       int length = tableDetailsCCMapping.length;
434       for (int i = 0; i < length; i++) {
435          TableDetails table = (TableDetails) tableDetailsCCMapping[i][0];
436          if (table.hashCode() == tableInfo.getUniqueID()) {
437             return tableDetailsCCMapping[i][2].hashCode();
438          }
439       }
440       throw new DException("DSE3516", new Object JavaDoc[] {tableInfo});
441    }
442
443    /**
444     * Returns the table details for passed tableInfo.
445     * @param tableInfo
446     * @return
447     * @throws DException
448     */

449
450    private TableDetails getTableDetail(_TableInfo tableInfo) throws DException {
451       /*dst*/
452       int length = tableDetailsCCMapping.length;
453          for (int i = 0; i < length; i++) {
454             TableDetails td = ( (TableDetails) tableDetailsCCMapping[i][0]);
455             if (td.hashCode() == tableInfo.getUniqueID()) {
456                return td;
457             }
458          }
459          throw new DException("DSE3516", new Object JavaDoc[] {tableInfo});
460          /*dend*/
461    }
462
463    /**
464     * Returns a comparator to compare the value of keys for different rows. It
465     * is used to place the row at appropriate position at client side.
466     * @return
467     * @throws DException
468     */

469
470
471    public SuperComparator getComparator() throws DException {
472       return selectKeyColumnInformation.getComparator();
473    }
474
475    /**
476     * It is used to obtain the indexes of primary condition columns.
477     * @return
478     * @throws DException
479     */

480
481    public int[] getPrimaryConditionColumns() throws DException {
482       return selectColumnCharacteristics.getPrimaryConditionColumns();
483    }
484
485    /**
486     * It returns the values of primary key condition's columns from the row.
487     * @param row
488     * @return
489     * @throws DException
490     */

491
492    public Object JavaDoc[] getPrimaryKeyConditionalColumnValues(Object JavaDoc[] row) throws DException {
493       int[] primaryIndexes = selectColumnCharacteristics.getPrimaryConditionColumns();
494       int length = primaryIndexes.length;
495       Object JavaDoc[] values = new Object JavaDoc[length];
496       for (int i = 0; i < length; i++) {
497          values[i] = row[primaryIndexes[i] - 1];
498       }
499       return values;
500    }
501
502    /**
503     * Used to obtain the positions of key columns in the row.
504     * @return
505     * @throws DException
506     */

507
508    public int[] getKeyColumnIndexes() throws DException {
509       return keyColumnMapping;
510    }
511
512    /**
513     * This method is never called.
514     * @return
515     * @throws DException
516     */

517
518    public String JavaDoc getFirstTableName() throws DException {
519       throw new UnsupportedOperationException JavaDoc("Method getFirstTableName() Not Supported");
520    }
521
522    /**
523     * This method is used to return the value of column represented by index
524     * from the row.
525     * @param index represents the index of selected column.
526     * @param row
527     * @return
528     * @throws DException
529     */

530
531    public Object JavaDoc getObject(int index, Object JavaDoc row) throws DException {
532       try {
533          Object JavaDoc o = ( (Object JavaDoc[]) row)[selectColumnMapping[index - 1] - 1];
534          if (o instanceof FieldBase) {
535             o = ( (FieldBase) o).getObject();
536          }
537          return o;
538       } catch (ArrayIndexOutOfBoundsException JavaDoc ex) {
539          throw ex;
540       }
541    }
542
543    /**
544     * Returns the position of functional column in the row.
545     * @param column
546     * @return
547     * @throws DException
548     */

549
550    public int getIndexOfFunctionalColumn(ColumnDetails column) throws DException {
551       return getIndexFromFunctionalMapping(column, functionalKeyColumnMapping);
552    }
553
554    /**
555     * Returns the clone of passed row.
556     * @param row
557     * @return
558     * @throws DException
559     */

560
561    public Object JavaDoc getRowClone(Object JavaDoc row) throws DException {
562       Object JavaDoc[] arr = (Object JavaDoc[]) row;
563       Object JavaDoc[] clonedRow = new Object JavaDoc[arr.length];
564       System.arraycopy(arr, 0, clonedRow, 0, arr.length);
565       return clonedRow;
566    }
567
568    /**
569     * Returns the name of key columns.
570     * @return
571     * @throws DException
572     */

573
574    public String JavaDoc[] getKeyColumns() throws DException {
575       ArrayList keyColumns = new ArrayList();
576       int len = keyColumnInformation.length;
577       for (int j = 0; j < len; j++) {
578          keyColumns.add(keyColumnInformation[j].getUniqueQualifiedName());
579       }
580       return (String JavaDoc[]) keyColumns.toArray(new String JavaDoc[0]);
581    }
582
583    /**
584     * Returns the column name at passed index for passed table.
585     * @param tableInfo
586     * @param index
587     * @return
588     * @throws DException
589     */

590
591    public String JavaDoc getColumnName(_TableInfo tableInfo, int index) throws DException {
592       return getTableDetail(tableInfo).getColumnCharacteristics().getColumnName(index);
593    }
594
595    /**
596     * This method is used to update the value of hasRecord column in the row.
597     * @param row
598     * @param value
599     * @throws DException
600     */

601
602    public void updateHasRecordColumns(Object JavaDoc row, Object JavaDoc value) throws DException {
603       for (int i = 0, length = selectListColumnDetails.length; i < length; i++) {
604          if (selectListColumnDetails[i].getType() == ColumnDetails.HAS_RECORD) {
605             setObject(i, value, row);
606          }
607       }
608    }
609
610    /**
611     * Returns the position of selected columns in the row.A
612     * @return
613     */

614
615    public int[] getSelectedColumnMapping() {
616       return selectColumnMapping;
617    }
618
619    /**
620     * The following methods are used for MATERIALIZED views.
621     */

622
623    public String JavaDoc getQueryForTable(QualifiedIdentifier tableName) throws DException {
624       StringBuffer JavaDoc query = new StringBuffer JavaDoc();
625       query.append("Create table \"").append(tableName.catalog)
626           .append("\".\"").append(tableName.schema)
627           .append("\".\"").append(tableName.name).append("\" ( ");
628       int len = tableDetailsCCMapping.length;
629       for (int j = 0; j < len; j++) {
630          String JavaDoc tableNm = ( (TableDetails) tableDetailsCCMapping[j][0]).getUnderscoreTableName();
631          _ColumnCharacteristics cc = (_ColumnCharacteristics) tableDetailsCCMapping[j][1];
632          int columnCount = cc.getColumnCount();
633          for (int i = 0; i < columnCount; i++) {
634             if (i != 0 || j != 0) {
635                query.append(",");
636             }
637             String JavaDoc column = cc.getColumnName(i);
638             int type = cc.getColumnType(i);
639             int size = cc.getSize(i);
640             int precision = cc.getPrecision(i);
641             int scale = cc.getScale(i);
642             String JavaDoc subString = getColumnDefinition(tableNm, column, type, size, precision, scale);
643             query.append(subString);
644          }
645       }
646       if (functionalKeyColumnMapping != null) {
647          for (int i = 0; i < functionalKeyColumnMapping.length; i++) {
648             query.append(" , ");
649             ColumnDetails fnCD = (ColumnDetails) functionalKeyColumnMapping[i][0];
650             String JavaDoc name = fnCD.getAliasName();
651             name = name == null ? fnCD.getAppropriateColumn() : name;
652             int type = fnCD.getDatatype();
653             int size = fnCD.getSize();
654             String JavaDoc functionalColumnDefinition = getColumnDefinition(null, name, type, size, -1, -1);
655             query.append(functionalColumnDefinition);
656          }
657       }
658       query.append(" ) ");
659
660       return query.toString();
661    }
662
663 /* Method Commented by Kaushik on 11/08/2004 as part of code review
664     private String getColumnDefinition(String table_name, String column_name, int type, int precision, int scale) throws DException {
665       String columnDefinition = table_name + "_" + column_name + " " + TypeConverter.getDataBaseTypeName(type);
666       if (type == Datatype.CHAR || type == Datatype.CHARACTER ||
667           type == Datatype.BINARY || type == Datatype.BIT ||
668           type == Datatype.BLOB || type == Datatype.BINARYLARGEOBJECT ||
669           type == Datatype.LONGVARBINARY || type == Datatype.CLOB ||
670           type == Datatype.CHARACTERLARGEOBJECT || type == Datatype.CHARLARGEOBJECT ||
671           type == Datatype.LONGVARCHAR || type == Datatype.VARCHAR || type == Datatype.CHARACTERVARYING ||
672           type == Datatype.CHARVARYING || type == Datatype.VARBINARY || type == Datatype.BIT || type == Datatype.BITVARYING ||
673           type == Datatype.FLOAT) {
674          columnDefinition += "(" + precision + ")";
675       } else if (type == Datatype.NUMERIC || type == Datatype.DEC || type == Datatype.DECIMAL ||
676                  type == Datatype.FLOAT || type == Datatype.BIGDECIMAL) {
677          columnDefinition += "(" + precision + "," + scale + ")";
678       }
679       return columnDefinition;
680    }
681 */

682    private String JavaDoc getColumnDefinition(String JavaDoc table_name, String JavaDoc column_name, int type, int size, int precision, int scale) throws DException {
683       String JavaDoc columnDefinition = table_name != null ?
684           table_name + "_" + column_name :
685           column_name;
686       columnDefinition = "\"" + columnDefinition + "\" " + TypeConverter.getDataBaseTypeName(type);
687       if (type == Datatype.CHAR || type == Datatype.CHARACTER ||
688           type == Datatype.BINARY || type == Datatype.BIT ||
689           type == Datatype.VARCHAR || type == Datatype.CHARACTERVARYING ||
690           type == Datatype.CHARVARYING || type == Datatype.VARBINARY ||
691           type == Datatype.BITVARYING) {
692          columnDefinition += "(" + size + ")";
693
694       }
695       if (precision != -1) {
696          if (type == Datatype.NUMERIC || type == Datatype.DEC || type == Datatype.DECIMAL ||
697              type == Datatype.FLOAT || type == Datatype.BIGDECIMAL || type == Datatype.DOUBLE) {
698             columnDefinition += "(" + precision;
699             if (scale != -1) {
700                columnDefinition += "," + scale;
701             }
702             columnDefinition += ")";
703          }
704       }
705       return columnDefinition;
706    }
707
708 }
709
Popular Tags