KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > ddl > descriptors > TableDescriptor


1 package com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
6 import com.daffodilwoods.daffodildb.server.serversystem.*;
7 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem.*;
8 import com.daffodilwoods.daffodildb.server.sql99.*;
9 import com.daffodilwoods.daffodildb.server.sql99.common.*;
10 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
11 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
12 import com.daffodilwoods.database.general.*;
13 import com.daffodilwoods.database.resource.*;
14
15 public class TableDescriptor extends Descriptor {
16    /**
17     * constraintMap variable contain constraints of a table at time of creation OR alter table.
18                 constraintMap variable used for restrict the end user to add multiple primary/unique key constraint in an existing table OR at the time of table creation. */

19    public HashMap constraintMap = new HashMap();
20
21    /**
22     * If any existing table is altered then isAlterTable variable contain true value otherwise it contains false.
23     * isAlterTable variable used for restrict the end user to add multiple primary/unique key constraint at the time of alter table. */

24    public boolean isAlterTable;
25
26 // * from columns system table according to schema qualified table name. */
27

28 // * from dataTypeDescriptor system table according to schema qualified table name and object_type. */
29

30    /**
31     * CONSTRAINT TABLES_PRIMARY_KEY
32     * PRIMARY KEY ( TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME ),
33     *
34     * CONSTRAINT TABLES_FOREIGN_KEY_SCHEMATA
35     * FOREIGN KEY ( TABLE_CATALOG, TABLE_SCHEMA )
36     * REFERENCES SCHEMATA,
37     */

38    public String JavaDoc table_catalog;
39    public String JavaDoc table_schema;
40    public String JavaDoc table_name;
41
42    /**
43     * 1. NOT NULL
44     * 2. CHECK ( TABLE_TYPE IN ( 'BASE TABLE', 'VIEW', 'GLOBAL TEMPORARY', 'LOCAL TEMPORARY' ) ),
45     * Only 'BASE TABLE' and 'VIEW' value Supported.
46     */

47    public String JavaDoc table_type;
48
49    /**
50     * Feature not supported. Related to User Defined Type so Values are null
51     */

52    public String JavaDoc self_referencing_column_name;
53    public String JavaDoc reference_generation;
54
55    /**
56     * User Defined Type not supported so Values are null
57     */

58    public String JavaDoc user_defined_type_catalog;
59    public String JavaDoc user_defined_type_schema;
60    public String JavaDoc user_defined_type_name;
61
62    /**
63     * CommitAction Feature not supported so Values are null
64     */

65    public String JavaDoc commitAction;
66
67    /**
68     * Country_code variable contains country_code which is specified by the end user at the time of table creation.
69     * If end user not specified the country_code then defaultCountryCode is US. */

70    public String JavaDoc country_code;
71
72    /**
73     * Language_code variable contains language_code which is specified by the end user at the time of table creation.
74     * If end user not specified the language_code then defaultLanguageCode is en. */

75    public String JavaDoc language_code;
76
77    /**
78     * class variables
79     */

80
81    /** @todo schema descriptor should not be here */
82    public SchemaDescriptor schemaDescriptor;
83
84    private int columnCount = 0;
85    private TreeMap columnDescriptors = new TreeMap(String.CASE_INSENSITIVE_ORDER);
86    private TreeMap columnConstraintDescriptors = new TreeMap(String.CASE_INSENSITIVE_ORDER);
87    private boolean flag = false;
88    public ArrayList indexesList;
89
90    /**
91     * Contains the truth(true/false) value related to primary key. */

92    public boolean primarKeyCreated;
93
94    /**
95     * Contains the truth(true/false) value for autoincrement column. */

96    private boolean isAutoIncrementAlreadyDefined;
97
98    public TableDescriptor() { /*String table_catalog0, String table_schema0, String table_name0) throws DException {
99                               table_catalog = table_catalog0;
100                               table_name = table_name0;
101                               table_schema = table_schema0; */

102     }
103
104    public TableDescriptor(String JavaDoc table_catalog0, String JavaDoc table_schema0,
105                           String JavaDoc table_name0) throws DException {
106       table_catalog = table_catalog0;
107       table_name = table_name0;
108       table_schema = table_schema0;
109    }
110
111    /**
112     * Load method tries to load the all information (Such as table_catalog, table_schema, table_name, table_type,
113     * self_referencing_column_name, reference_generation, user_defined_type_catalog, user_defined_type_schema,
114     * user_defined_type_name, commitAction, country_code, language_code) from tables system table according to
115     * schema qualified table name. If no information found for schema qualified table name then it throws DException. */

116    public void load(_ServerSession serverSession) throws DException {
117       DataDictionary dd = (DataDictionary) serverSession.getDataDictionary();
118       _SelectQueryIterator iter = (_SelectQueryIterator) dd.getPreparedStatementGetter().
119           getTablesTableExecuter().executeForFresh( (Object JavaDoc[]) getParameters());
120       if (!iter.first()) {
121          throw new DException("DSE959", new Object JavaDoc[] {getQualifiedTableName()});
122       }
123       Object JavaDoc[] obj = (Object JavaDoc[]) iter.getObject();
124       table_type = (String JavaDoc) obj[SystemTablesFields.tables_table_type];
125       self_referencing_column_name = (String JavaDoc) obj[SystemTablesFields.
126           tables_self_referencing_column_name];
127       reference_generation = (String JavaDoc) obj[SystemTablesFields.
128           tables_reference_generation];
129       commitAction = (String JavaDoc) obj[SystemTablesFields.tables_commitAction];
130       country_code = (String JavaDoc) obj[SystemTablesFields.tables_country_code];
131       language_code = (String JavaDoc) obj[SystemTablesFields.tables_language_code];
132       loadColumnDescriptors(serverSession);
133    }
134
135    /**
136     * LoadColumnDescriptors method load all information (Such as table_catalog, table_schema, table_name, column_name, ordinal_position, dtd_identifier, domain_catalog,
137     * domain_schema, domain_name, column_default, isNullable, isSelfReferencing, isAutoIncrement) from columns system table according to schema qualified table name.
138     * If any information found for schema qualified table name then this method tries to load all information (Such as object_catalog, object_schema, object_name,
139     * object_type, dtd_identifier, data_Type, character_maximum_length, character_octet_length, collation_catalog, collation_schema, collation_name, numeric_precision,
140     * numeric_precision_radix, numeric_scal, datatime_precision, interval_type, interval_precision, user_defined_type_catalog, user_defined_type_schema, user_defined_type_name,
141     * scope_catalog, scope_schema, scope_name, maximum_cardinality) from dataTypeDescriptor system table according to schema qualified table name and object_type.
142     * If no information found for schema qualified table name and object_type then it throws DException. */

143    public void loadColumnDescriptors(_ServerSession serverSession) throws
144        DException {
145       _SelectQueryIterator columnsIterator = (_SelectQueryIterator) ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getColumnsExecuter().executeForFresh(getParameters());
146       if (columnsIterator.first()) {
147          _SelectQueryIterator dataTypeIterator = (_SelectQueryIterator) ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getDataTypeExecuter().executeForFresh(getParameters());
148          if (!dataTypeIterator.first()) {
149             throw new DException("DSE310", null);
150          }
151          boolean flag = false;
152          do {
153             columnCount++;
154             ColumnDescriptor columnDescriptor = new ColumnDescriptor();
155             columnDescriptor.tableDescriptor = this;
156             columnDescriptor.loadDataFromRecord(columnsIterator);
157             DataTypeDescriptor dataTypeDescriptor = new DataTypeDescriptor();
158             dataTypeDescriptor.loadDataFromRecord(dataTypeIterator);
159             columnDescriptor.dataTypeDescriptor = dataTypeDescriptor;
160             columnDescriptors.put(columnDescriptor.column_name.toLowerCase(),
161                                   columnDescriptor);
162             boolean boo = columnsIterator.next();
163             flag = dataTypeIterator.next();
164             if (boo ^ flag) {
165                throw new DException("DSE5017", null);
166             }
167          } while (flag);
168       }
169    }
170
171    /*public void save(_ServerSession serverSession) throws DException{
172      save((UserSession)connection.getUserSession());
173      if( table_catalog.equalsIgnoreCase("system") )
174         table_type = "System Table";
175      Object[] columnValues = new Object[]{table_catalog,table_schema,table_name,
176         table_type,self_referencing_column_name,reference_generation,
177                     user_defined_type_catalog,user_defined_type_schema,user_defined_type_name,commitAction};
178      Object recordId = SqlSchemaConstants.insert(connection,
179                               SqlSchemaConstants.tables_TableName,columnValues);
180        } */

181
182    /**
183     * Save all the information(Such as table_catalog, table_schema, table_name, table_type, self_referencing_column_name, reference_generation,
184     * user_defined_type_catalog, user_defined_type_schema, user_defined_type_name, commitAction, country_code, language_code)
185     * of a particular table in tables system table at the time of table creation. If such information is already exists in system table
186     * then it throws PrimaryConstraintException. */

187    public void save(_ServerSession serverSession) throws DException {
188       if ( (!table_type.equalsIgnoreCase(SqlKeywords.VIEW)) &&
189           table_catalog.equalsIgnoreCase("system")) {
190          table_type = "System Table";
191       }
192       Object JavaDoc[] columnValues = new Object JavaDoc[] {
193           table_catalog, table_schema, table_name,
194           table_type, self_referencing_column_name, reference_generation,
195           user_defined_type_catalog, user_defined_type_schema,
196           user_defined_type_name, commitAction, country_code, language_code};
197       try {
198          SqlSchemaConstants.insert(serverSession,
199                                    SqlSchemaConstants.tables_TableName, null,
200                                    columnValues);
201       } catch (PrimaryConstraintException de) {
202          DException tde = new DException("DSE1135", new Object JavaDoc[] {getTableName()});
203          throw tde;
204       } catch (SizeMisMatchException de) {
205          if (de.getDseCode().equals("DSE773")) {
206             DException tde = new DException("DSE8103", null);
207             throw tde;
208          }
209       } catch (DException de) {
210          if (de.getDseCode().equals("DSE1255")) {
211             DException tde = new DException("DSE1135", new Object JavaDoc[] {getTableName()});
212             throw tde;
213          }
214          if (de.getDseCode().equals("DSE773")) {
215             DException tde = new DException("DSE8103", null);
216             throw tde;
217          }
218          throw de;
219       }
220    }
221
222    /**
223     * Returns the schema qualified table name as a string. */

224    public String JavaDoc getTableName() {
225       return table_catalog + "." + table_schema + "." + table_name;
226    }
227
228    /**
229     * Returns the schema qualified table name as a QualifiedIdentifier. */

230    public QualifiedIdentifier getQualifiedTableName() {
231       return new QualifiedIdentifier(table_catalog, table_schema, table_name);
232    }
233
234    /*public boolean is_Table_Referenced_From_Views(DConnection connection) throws DException{
235         return is_Table_Referenced_From_Views((UserSession)connection.getUserSession());
236      }*/

237
238    /**
239     * Returns the information (Such as Such as view_catalog, view_schema, view_name) according to schema qualified
240     * table name.If no information found for schema qualified table name then it returns null. */

241    public QualifiedIdentifier isTableReferencedFromViews(_ServerSession serverSession) throws DException {
242       _Executer viewTableUsageExecuter = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getViewTableUsageExecuter();
243       _SelectQueryIterator iterator = (_SelectQueryIterator) viewTableUsageExecuter.execute(new Object JavaDoc[] {table_catalog, table_schema, table_name});
244       if (!iterator.first()) {
245          return null;
246       }
247       Object JavaDoc[] data = (Object JavaDoc[]) iterator.getObject();
248       return new QualifiedIdentifier( (String JavaDoc) data[0], (String JavaDoc) data[1], (String JavaDoc) data[2]);
249    }
250
251    /**
252     * Returns the information (Such as trigger_catalog, trigger_schema, trigger_name) according to schema qualified
253     * table name.If no information found for schema qualified table name then it returns null. */

254    public QualifiedIdentifier isTableReferencedFromTriggers(_ServerSession serverSession) throws DException {
255       _Executer triggerTableUsageExecuter = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getTriggerTableUsageExecuter();
256       _SelectQueryIterator iterator = (_SelectQueryIterator) triggerTableUsageExecuter.execute(new Object JavaDoc[] {table_catalog, table_schema, table_name});
257       if (!iterator.first()) {
258          return null;
259       }
260       Object JavaDoc[] data = (Object JavaDoc[]) iterator.getObject();
261       return new QualifiedIdentifier( (String JavaDoc) data[0], (String JavaDoc) data[1], (String JavaDoc) data[2]);
262    }
263
264    /**
265     * Returns the information (Such as constraint_catalog, constraint_schema, constraint_name) according to schema qualified
266     * table name which presents in check_table_usage system table and not present in table_constraints system table. If no
267     * information found for schema qualified table name then it returns null. */

268    public QualifiedIdentifier isTableReferencedFromCheckConstraints(_ServerSession serverSession) throws DException {
269
270       _Executer tableReferencedCheckConstraintExecuter = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getTableReferencedCheckConstraintExecuter();
271       _SelectQueryIterator iterator = (_SelectQueryIterator) tableReferencedCheckConstraintExecuter.execute(new Object JavaDoc[] {table_catalog, table_schema, table_name, table_catalog, table_schema, table_name});
272       if (!iterator.first()) {
273          return null;
274       }
275       Object JavaDoc[] data = (Object JavaDoc[]) iterator.getObject();
276       return new QualifiedIdentifier( (String JavaDoc) data[0], (String JavaDoc) data[1],
277                                      (String JavaDoc) data[2]);
278    }
279
280    /**
281     * Returns the information (Such as referential_constraints_constraint_catalog, referential_constraints_constraint_schema,
282     * referential_constraints_constraint_name) according to schema qualified table name and constraint_type.
283     * If no information found for schema qualified table name and constraint_type then it returns null. */

284    public QualifiedIdentifier isTableReferencedFromReferentialConstraints(
285        _ServerSession serverSession) throws DException {
286       PreparedStatementGetter psg = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter();
287       _Executer referentialConstraintExecuter = psg.getReferentialConstraintExecuter();
288       _SelectQueryIterator iterator = (_SelectQueryIterator) referentialConstraintExecuter.execute(new Object JavaDoc[] {table_catalog, table_schema, table_name});
289       if (!iterator.first()) {
290          return null;
291       }
292       String JavaDoc catalog, schema, name = null;
293       _Executer executer = psg.getConstraintExecuter();
294       do {
295          Object JavaDoc[] data = (Object JavaDoc[]) iterator.getObject();
296          catalog = (String JavaDoc) data[SystemTablesFields.
297              referential_constraints_constraint_catalog];
298          schema = (String JavaDoc) data[SystemTablesFields.
299              referential_constraints_constraint_schema];
300          name = (String JavaDoc) data[SystemTablesFields.
301              referential_constraints_constraint_name];
302          _SelectQueryIterator iter = (_SelectQueryIterator) executer.execute(new Object JavaDoc[] {catalog,
303              schema, name});
304          iter.first();
305          Object JavaDoc[] values = (Object JavaDoc[]) iter.getObject(); ;
306          if (! (table_name.equalsIgnoreCase( (String JavaDoc) values[SystemTablesFields.
307                                             table_constraints_table_name])
308                 &&
309                 table_schema.equalsIgnoreCase( (String JavaDoc) values[SystemTablesFields.
310                                               table_constraints_table_schema])
311                 &&
312                 table_catalog.equalsIgnoreCase( (String JavaDoc) values[SystemTablesFields.
313                                                table_constraints_table_catalog]))) {
314             return new QualifiedIdentifier(catalog, schema, name);
315          }
316       } while (iterator.next());
317       return null;
318    }
319
320    /**
321     * Remove the columnDescriptor and update the ordinal position of the remaining columns. */

322    public void removeColumnDescriptor(ColumnDescriptor columnDescriptor,
323                                       _ServerSession serverSession) throws DException {
324       columnDescriptors.remove(columnDescriptor.column_name);
325       columnCount--;
326       int columnPosition = columnDescriptor.ordinal_position;
327       /* String query = "Update "+SqlSchemaConstants.columns_TableName+" set ordinal_position = ordinal_position-1 where ordinal_position > ? and table_catalog = ? and table_schema = ? and table_name = ? ";
328            String query = "Select ordinal_position from "+SqlSchemaConstants.columns_TableName+" where ordinal_position > ? and table_catalog = ? and table_schema = ? and table_name = ? ";
329            _Executer executer = (_Executer)serverSession.getGlobalSession().executeQueryParameterised(query,0);
330            _Iterator iter = (_Iterator)executer.execute(new Object[]{new Integer(columnPosition), table_catalog, table_schema, table_name});*/

331
332       Iterator iterator = columnDescriptors.values().iterator();
333       ArrayList columnDescriptorsToBeUpdated = new ArrayList();
334       while (iterator.hasNext()) {
335          ColumnDescriptor columnDescriptor1 = (ColumnDescriptor) iterator.next();
336          if (columnDescriptor1.ordinal_position > columnPosition) {
337             columnDescriptor1.ordinal_position--;
338             columnDescriptorsToBeUpdated.add(columnDescriptor1);
339          }
340       }
341       int checkColumnposition = columnPosition;
342       while (columnDescriptorsToBeUpdated.size() != 0) {
343          for (int i = 0; i < columnDescriptorsToBeUpdated.size(); i++) {
344             ColumnDescriptor columnDescriptor1 = (ColumnDescriptor)
345                 columnDescriptorsToBeUpdated.get(i);
346             if (columnDescriptor1.ordinal_position == checkColumnposition) {
347                columnDescriptor1.update(serverSession,
348                                         new int[] {SystemTablesFields.
349                                         columns_ordinal_position}
350                                         ,
351                                         new Object JavaDoc[] {new Integer JavaDoc(columnDescriptor1.
352                    ordinal_position)});
353                checkColumnposition++;
354                columnDescriptorsToBeUpdated.remove(i);
355                break;
356             }
357          }
358       }
359    }
360
361    /**
362     * Returns the schema qualified table name. */

363    private String JavaDoc[] getParameters() throws DException {
364       return new String JavaDoc[] {table_catalog, table_schema, table_name};
365    }
366
367    /**
368     * Set the true value for auto increment column. */

369    public void setAutoIncrement() {
370       isAutoIncrementAlreadyDefined = true;
371    }
372
373    /**
374     * Return the true value if auto increment column is present in an existing table otherwise it returns false value. */

375    public boolean isAutoIncrementColumnPresent() {
376       return isAutoIncrementAlreadyDefined;
377    }
378
379    /**
380     * Return all columns name of a particular table */

381    public String JavaDoc[] getColumnNames() throws DException {
382       Iterator columnsIterator = columnDescriptors.keySet().iterator();
383       String JavaDoc[] columnNames = new String JavaDoc[columnCount];
384       int i = 0;
385       while (columnsIterator.hasNext()) {
386          columnNames[i++] = (String JavaDoc) columnsIterator.next();
387       }
388       return columnNames;
389    }
390
391    /**
392     * Save the columns information in system table through ColumnDescriptor's save method at the time of table creation. */

393    public void saveColumns(_ServerSession serverSession) throws DException {
394       Iterator iterator = columnDescriptors.values().iterator();
395       while (iterator.hasNext()) {
396          ColumnDescriptor cd = (ColumnDescriptor) iterator.next();
397          cd.save(serverSession);
398       }
399    }
400
401    /**
402     * Returns the int value 1 for table_descriptor*/

403    public int getDescriptorType() {
404       return TABLE_DESCRIPTOR;
405    }
406
407    /**
408     * Returns the number of columns of a particular table */

409    public int getColumnCount() {
410       return columnCount;
411    }
412
413    /**
414     * Remove the all information of a particular table (Such as columns, datatypes and constraints etc...) from tables system table */

415    public void delete(_ServerSession serverSession) throws DException {
416       booleanvalueexpression condition = ( (DataDictionary) serverSession.getDataDictionary()).
417           getPreparedStatementGetter().getTablesTableCondition();
418       super.delete(serverSession, SqlSchemaConstants.tables_TableName, condition,
419                    new Object JavaDoc[] {table_catalog, table_schema, table_name});
420       deleteColumns(serverSession);
421       deleteConstraints(serverSession);
422    }
423
424    /**
425     * Delete all columns information of a particular table from system table through delete method of ColumnDescriptor. */

426    public void deleteColumns(_ServerSession serverSession) throws DException {
427       Iterator iterator = columnDescriptors.values().iterator();
428       while (iterator.hasNext()) {
429          ColumnDescriptor columnDescriptor = (ColumnDescriptor) iterator.next();
430          columnDescriptor.delete(serverSession);
431       }
432    }
433
434    /**
435     * Delete all constraints information of a particular table from system table through delete method of TableConstraintDescriptor. */

436    public void deleteConstraints(_ServerSession serverSession) throws DException {
437       _Executer deleteConstraintExecuter = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getDeleteConstraintExecuter();
438       _SelectQueryIterator retIter = (_SelectQueryIterator) deleteConstraintExecuter.execute(new Object JavaDoc[] {table_catalog, table_schema, table_name});
439       if (retIter.first()) {
440          do {
441             TableConstraintDescriptor constraint = new TableConstraintDescriptor();
442             constraint.loadDataFromRecord(retIter, serverSession);
443             constraint.delete(serverSession);
444          } while (retIter.next());
445       }
446    }
447
448    /**
449     * Add column desriptor of a particular column in TreeMap(columnDescriptors). */

450    public void addColumnDescriptor(ColumnDescriptor columnDescriptor) throws
451        DException {
452       String JavaDoc columnName = columnDescriptor.column_name.toLowerCase();
453       Object JavaDoc oldObject = columnDescriptors.put(columnName, columnDescriptor);
454       if (oldObject != null) {
455          throw new DException("DSE250", new Object JavaDoc[] {columnName, getQualifiedTableName().toString()});
456       }
457       columnDescriptor.ordinal_position = ++columnCount;
458    }
459
460    /**
461     * Returns column desriptor for a particular column. If number of columns equals 0 then this method throws DException. */

462    public ColumnDescriptor getColumnDescriptor(String JavaDoc columnName) throws DException {
463       ColumnDescriptor column = (ColumnDescriptor) columnDescriptors.get(columnName.toLowerCase());
464       if (column != null) {
465          return column;
466       }
467       if (columnCount == 0) {
468          throw new DException("DSE301", new Object JavaDoc[] {columnName});
469       }
470       throw new DException("DSE255", new Object JavaDoc[] {columnName,
471                            getQualifiedTableName().toString()});
472    }
473
474    /**
475     * Check the existance of columns in a particular table. If all columns found then returns -1 */

476    public int isTableColumns(Object JavaDoc[] columns) throws DException {
477       for (int i = 0; i < columns.length; i++) {
478          String JavaDoc columnName = (String JavaDoc) columns[i];
479          if (columnDescriptors.get(columnName) == null) {
480             return i;
481          }
482       }
483       return -1;
484    }
485
486    /**
487     * Load the schema information through schemaDescriptor's load method. */

488    public void loadSchemaDescriptor(_ServerSession serverSession) throws DException {
489       if (schemaDescriptor == null) {
490          schemaDescriptor = new SchemaDescriptor();
491       }
492       if (schemaDescriptor.catalog_name == null) {
493          schemaDescriptor.catalog_name = table_catalog;
494       }
495       if (schemaDescriptor.schema_name == null) {
496          schemaDescriptor.schema_name = table_schema;
497       }
498       schemaDescriptor.load(serverSession);
499    }
500
501    /**
502     * Add index name in ArrayList(indexesList) */

503    public void addIndexName(String JavaDoc indexName) throws DException {
504       if (indexesList == null) {
505          indexesList = new ArrayList();
506       }
507       indexesList.add(indexName);
508    }
509
510    /**
511     * Returns column descriptor's arrayList of a particular table.*/

512    public ArrayList get_all_column_descriptors() throws DException {
513       ArrayList list = new ArrayList();
514       Iterator iter = columnDescriptors.values().iterator();
515       while (iter.hasNext()) {
516          list.add(iter.next());
517       }
518       return list;
519    }
520
521
522    /**
523     * Add foreign key constraint column descriptor and column name in TreeMap(columnConstraintDescriptors). */

524    public void addConstraintColumnDescriptor(ColumnDescriptor columnDes) throws
525        DException {
526       columnConstraintDescriptors.put(columnDes.column_name, columnDes);
527       flag = true;
528    }
529
530    /** @todo
531     * The method commented below will be used when Table Key work is to be done
532     * */

533    /* public void saveConstraintColumns(_ServerSession serverSession) throws
534          DException {
535        ColumnDescriptor colDes = new ColumnDescriptor();
536        Iterator it = columnConstraintDescriptors.values().iterator();
537        while (it.hasNext()) {
538          colDes = (ColumnDescriptor) it.next();
539          addColumnDescriptor(colDes);
540          colDes.save(serverSession);
541        }
542      }*/

543    /**
544     * Returns the information (Such as Such as routine_catalog, routine_schema, routine_name) according to schema qualified
545     * table name.If no information found for schema qualified table name then it returns null. */

546    public QualifiedIdentifier isTableReferencedFromRoutines(_ServerSession serverSession) throws DException {
547       _Executer routineTableUsageExecuter = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getRoutineTableUsageExecuter();
548       _SelectQueryIterator iterator = (_SelectQueryIterator) routineTableUsageExecuter.execute(new Object JavaDoc[] {table_catalog, table_schema, table_name});
549       if (!iterator.first()) {
550          return null;
551       }
552       Object JavaDoc[] data = (Object JavaDoc[]) iterator.getObject();
553       return new QualifiedIdentifier( (String JavaDoc) data[0], (String JavaDoc) data[1], (String JavaDoc) data[2]);
554    }
555 }
556
Popular Tags