KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > TableElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.dbschema;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25
26 /** Describes an entire database table.
27  */

28 public final class TableElement extends DBElement implements ColumnElementHolder, ColumnPairElementHolder {
29     /** Constant indicating that the table is a real table.
30      * @see #isTableOrView
31      */

32     public static final boolean TABLE = true;
33
34     /** Constant indicating that the table is a view.
35      * @see #isTableOrView
36      */

37     public static final boolean VIEW = false;
38
39     /** the schema to which this table element belongs */
40     private transient SchemaElement declaringSchema;
41
42     /** Creates a new table element represented in memory.
43      */

44     public TableElement() {
45         this(new Memory(), null);
46     }
47
48     /** Createa a table element.
49      * @param impl the pluggable implementation
50      * @param declaringSchema the schema to which this element belongs
51      */

52     public TableElement(Impl impl, SchemaElement declaringSchema) {
53         super(impl);
54         this.declaringSchema = declaringSchema;
55     }
56
57     /** Returns the implementation for the table.
58      * @return implementation for the table
59      */

60     final Impl getTableImpl() {
61         return (Impl) getElementImpl();
62     }
63
64     /** Returns the TableElement object associated with the given name and with the given schema.
65      * @param name the table name
66      * @param schema the schema
67      * @return the TableElement object for the given table name in the given schema
68      */

69     public static TableElement forName(String JavaDoc name, SchemaElement schema) {
70         int pos = name.lastIndexOf(".");
71         if (pos == -1)
72             return null;
73         else
74             name = name.substring(pos + 1);
75         
76         TableElement[] tes = schema.getTables();
77         for (int i = 0; i < tes.length; i++)
78             if (tes[i].getName().getName().trim().equals(name))
79                 return tes[i];
80
81         return null;
82     }
83
84     /** Returns the TableElement object associated with the given name.
85      * @param name the table name
86      * @return the TableElement object for the given table name
87      */

88     public static TableElement forName(String JavaDoc name) /* 4_ea throws DBException */ {
89         int index = name.lastIndexOf("."); //NOI18N
90

91         if (index == -1) {
92             if (Boolean.getBoolean("netbeans.debug.exceptions")) // NOI18N
93
System.out.println(ResourceBundle.getBundle("org.netbeans.modules.dbschema.resources.Bundle").getString("FullyQualifiedName")); //NOI18N
94
return null;
95         }
96         
97         SchemaElement se = SchemaElement.forName(name.substring(0, index));
98         
99         if (se == null)
100 // 4_ea throw new DBException(bundle.getString("SchemaNotFound"));
101
return null;
102         else
103             return TableElement.forName(name, se);
104     }
105
106     /** Sets whether this is really a table, or a view.
107      * @param isTable one of {@link #TABLE} or {@link #VIEW}
108      * @throws DBException if impossible
109      */

110     public void setTableOrView(boolean isTable) throws DBException {
111             getTableImpl().setTableOrView(isTable);
112     }
113
114     /** Tests whether this is a table, or a view.
115      * @return one of {@link #TABLE} or {@link #VIEW}
116      */

117     public boolean isTableOrView() {
118             return getTableImpl().isTableOrView();
119   }
120
121     /** Tests whether this is really a table.
122      * @return <code>true</code> if so
123      * @see #isTableOrView
124      */

125     public boolean isTable() {
126             return getTableImpl().isTableOrView();
127   }
128
129     /** Test whether this is a view.
130      * @return <code>true</code> if so
131      * @see #isTableOrView
132      */

133     public boolean isView() {
134             return !getTableImpl().isTableOrView();
135   }
136
137     // ==================== schema section ==========================
138

139     /* This should be automatically synchronized
140     * when a TableElement is added to the schema. */

141   
142     /** Gets the declaring schema.
143      * @return the schema that owns this table element
144      */

145     public final SchemaElement getDeclaringSchema() {
146         return declaringSchema;
147     }
148
149     /** Sets the declaring schema.
150      * @param se the schema that owns this table element
151      */

152     public final void setDeclaringSchema(SchemaElement se) {
153         if (declaringSchema == null)
154             declaringSchema = se;
155     }
156
157     //================== Columns ===============================
158

159     /** Adds a new column to the table.
160      * @param el the column to add
161      * @throws DBException if impossible
162      */

163     public void addColumn(ColumnElement el) throws DBException {
164         addColumns(new ColumnElement[] {el});
165     }
166
167     /** Adds some new columns to the table.
168      * @param els the columns to add
169      * @throws DBException if impossible
170      */

171     public void addColumns(final ColumnElement[] els) throws DBException {
172         for (int i = 0; i < els.length; i++) {
173             if (getColumn(els[i].getName()) != null)
174                 throwAddException("FMT_EXC_AddColumn", els[i]); //NOI18N
175
if (els[i].getDeclaringTable() == null)
176                 els[i].setDeclaringTable(this);
177         }
178         getTableImpl().changeColumns(els, Impl.ADD);
179     }
180
181     /** Removes a column from the table.
182      * @param el the column to remove
183      * @throws DBException if impossible
184      */

185     public void removeColumn(ColumnElement el) throws DBException {
186         removeColumns(new ColumnElement[] {el});
187     }
188
189     /** Removes some columns from the table.
190      * @param els the columns to remove
191      * @throws DBException if impossible
192      */

193     public void removeColumns(final ColumnElement[] els) throws DBException {
194             getTableImpl().changeColumns(els, Impl.REMOVE);
195     }
196
197     /** Sets the columns for this table.
198      * Previous columns are removed.
199      * @param els the new columns
200      * @throws DBException if impossible
201      */

202     public void setColumns(ColumnElement[] els) throws DBException {
203             getTableImpl().changeColumns(els, Impl.SET);
204     }
205
206     /** Gets all columns in this table.
207      * @return the columns
208      */

209     public ColumnElement[] getColumns() {
210             return getTableImpl().getColumns();
211     }
212
213     /** Finds a column by name.
214      * @param name the name of the column for which to look
215      * @return the element or <code>null</code> if not found
216      */

217     public ColumnElement getColumn(DBIdentifier name) {
218             return getTableImpl().getColumn(name);
219     }
220
221     //================== Indexes ===============================
222

223     /** Adds a new index to the table.
224      * @param el the index to add
225      * @throws DBException if impossible
226      */

227     public void addIndex(IndexElement el) throws DBException {
228         addIndexes(new IndexElement[] {el});
229     }
230
231     /** Adds some new indexes to the table.
232      * @param els the indexes to add
233      * @throws DBException if impossible
234      */

235     public void addIndexes(final IndexElement[] els) throws DBException {
236         for (int i = 0; i < els.length; i++) {
237             if (getIndex(els[i].getName()) != null)
238                 throwAddException("FMT_EXC_AddColumn", els[i]); //NOI18N
239
if (els[i].getDeclaringTable() == null)
240                 els[i].setDeclaringTable(this);
241         }
242
243         getTableImpl().changeIndexes(els, Impl.ADD);
244     }
245
246     /** Removesan index from the table.
247      * @param el the index to remove
248      * @throws DBException if impossible
249      */

250     public void removeIndex(IndexElement el) throws DBException {
251         removeIndexes(new IndexElement[] {el});
252     }
253
254     /** Removes some indexes from the table.
255      * @param els the indexes to remove
256      * @throws DBException if impossible
257      */

258     public void removeIndexes(final IndexElement[] els) throws DBException {
259         getTableImpl().changeIndexes(els, Impl.REMOVE);
260     }
261
262     /** Sets the indexes for this table.
263      * Previous indexes are removed.
264      * @param els the new indexes
265      * @throws DBException if impossible
266      */

267     public void setIndexes(IndexElement[] els) throws DBException {
268         getTableImpl().changeIndexes(els, Impl.SET);
269     }
270
271     /** Gets all indexes in this table.
272      * @return the indexes
273      */

274     public IndexElement[] getIndexes() {
275         return getTableImpl().getIndexes();
276     }
277
278     /** Finds an index by name.
279      * @param name the name of the index for which to look
280      * @return the element or <code>null</code> if not found
281      */

282     public IndexElement getIndex(DBIdentifier name) {
283         return getTableImpl().getIndex(name);
284     }
285
286     //================== Keys (Unique, Primary, and Foreign) =================
287

288     /** Adds a new key to the table.
289      * @param el the key to add
290      * @throws DBException if impossible
291      */

292     public void addKey(KeyElement el) throws DBException {
293         addKeys(new KeyElement[]{el});
294     }
295
296     /** Adds some new keys to the table.
297      * @param els the keys to add
298      * @throws DBException if impossible
299      */

300     public void addKeys(final KeyElement[] els) throws DBException {
301         for (int i = 0; i < els.length; i++) {
302             if (getKey(els[i].getName()) != null)
303                 throwAddException("FMT_EXC_AddColumn", els[i]); //NOI18N
304
if (els[i].getDeclaringTable() == null)
305                 els[i].setDeclaringTable(this);
306             if (els[i] instanceof UniqueKeyElement)
307                 if (((UniqueKeyElement) els[i]).getAssociatedIndex() == null) {
308                     IndexElement ie = new IndexElement();
309                     try {
310                         ie.setName(els[i].getName());
311                         ie.setColumns(els[i].getColumns());
312                         this.addIndex(ie);
313                     } catch (DBException exc) {
314                         exc.printStackTrace();
315                     }
316                     ((UniqueKeyElement) els[i]).setAssociatedIndex(ie);
317                 }
318         }
319     
320         getTableImpl().changeKeys(els, Impl.ADD);
321     }
322
323     /** Removes a key from the table.
324      * @param el the key to remove
325      * @throws DBException if impossible
326      */

327     public void removeKey(KeyElement el) throws DBException {
328         removeKeys(new KeyElement[] {el});
329     }
330
331     /** Removes some keys from the table.
332      * @param els the keys to remove
333      * @throws DBException if impossible
334      */

335     public void removeKeys(final KeyElement[] els) throws DBException {
336             getTableImpl().changeKeys(els, Impl.REMOVE);
337     }
338
339     /** Sets the keys for this table.
340      * Previous keys are removed.
341      * @param els the new keys
342      * @throws DBException if impossible
343      */

344
345     public void setKeys(KeyElement[] els) throws DBException {
346             getTableImpl().changeKeys(els, Impl.SET);
347     }
348
349     /** Gets all keys in this table.
350      * @return the keys
351      */

352     public KeyElement[] getKeys() {
353             return getTableImpl().getKeys();
354     }
355
356     /** Finds a key by name.
357      * @param name the name of the key for which to look
358      * @return the element or <code>null</code> if not found
359      */

360     public KeyElement getKey(DBIdentifier name) {
361             return getTableImpl().getKey(name);
362     }
363
364     // key convenience methods
365

366     /** Gets all keys in this table of the given subtype.
367      * @param subtype the type of the key classes
368      * @return the keys of the given subtype or <code>null</code> if not found
369      */

370     private ArrayList JavaDoc getKeys(Class JavaDoc subtype) {
371         KeyElement[] keys = getKeys();
372
373         if (keys == null)
374             return null;
375
376         int i, count = keys.length;
377         ArrayList JavaDoc subKeys = new ArrayList JavaDoc(count);
378
379         for (i = 0; i < count; i++) {
380             KeyElement key = keys[i];
381
382             if (subtype.isInstance(key))
383                 subKeys.add(key);
384         }
385
386         return subKeys;
387     }
388
389     /** Gets all foreign keys in this table.
390      * @return the foreign keys or <code>null</code> if not found
391      */

392     public ForeignKeyElement[] getForeignKeys() {
393         ArrayList JavaDoc keys = getKeys(ForeignKeyElement.class);
394         
395         if (keys == null)
396             return null;
397
398         int count = keys.size();
399
400         return ((ForeignKeyElement[]) keys.toArray(new ForeignKeyElement[count]));
401     }
402
403     /** Finds a foreign key by name.
404      * @param name the name of the foreign key for which to look
405      * @return the foreign key or <code>null</code> if not found
406      */

407     public ForeignKeyElement getForeignKey(DBIdentifier name) {
408         ForeignKeyElement[] fks = getForeignKeys();
409         int i, count = fks.length;
410         
411         for (i = 0; i < count; i++) {
412             ForeignKeyElement fk = fks[i];
413
414             if (name.equals(fk.getName()))
415                 return fk;
416         }
417
418         return null;
419     }
420     
421     /** Gets all unique keys in this table.
422      * @return the unique keys or <code>null</code> if not found
423      */

424     public UniqueKeyElement[] getUniqueKeys() {
425         ArrayList JavaDoc keys = getKeys(UniqueKeyElement.class);
426
427         if (keys == null)
428             return null;
429
430         return ((UniqueKeyElement[]) keys.toArray(new UniqueKeyElement[keys.size()]));
431     }
432
433     /** Finds a unique key by name.
434      * @param name the name of the unique key for which to look
435      * @return the unique key or <code>null</code> if not found
436      */

437     public UniqueKeyElement getUniqueKey(DBIdentifier name) {
438         UniqueKeyElement[] uks = getUniqueKeys();
439         int i, count = uks.length;
440         
441         for (i = 0; i < count; i++) {
442             UniqueKeyElement uk = uks[i];
443
444             if (name.equals(uk.getName()))
445                 return uk;
446         }
447
448         return null;
449     }
450
451     /** Finds the primary key.
452      * @return the primary key or <code>null</code> if not found
453      */

454     public UniqueKeyElement getPrimaryKey() {
455         UniqueKeyElement[] uks = getUniqueKeys();
456
457         if (uks == null)
458             return null;
459
460         for (int i = 0; i < uks.length; i++) {
461             UniqueKeyElement uk = uks[i];
462
463             if (uk.isPrimaryKey())
464                 return uk;
465         }
466
467         return null;
468     }
469
470     // end key convenience methods
471

472     /** This method just throws localized exception. It is used during
473      * adding class element, which already exists in source.
474      * @param formatKey The message format key to localized bundle.
475      * @param element The element which can't be added
476      * @exception DBException is alway thrown from this method.
477      */

478     private void throwAddException(String JavaDoc formatKey, DBMemberElement element) throws DBException {
479         // MessageFormat format = new MessageFormat(ElementFormat.bundle.getString(formatKey));
480
String JavaDoc msg = /*format.format(new Object[] { */element.getName().getName();// });
481
throw new DBException(msg);
482     }
483     
484     /** Returns a string representation of the object.
485      * @return a string representation of the object.
486      */

487     public String JavaDoc toString() {
488         if (getName() != null)
489             return getName().toString();
490         else
491             return null;
492     }
493
494     /** Adds a new column pair to the holder.
495      * @param pair the pair to add
496      * @throws DBException if impossible
497      */

498     public void addColumnPair(ColumnPairElement pair) throws DBException {
499         addColumnPairs(new ColumnPairElement[] {pair});
500     }
501
502     /** Adds some new column pairs to the holder.
503      * @param pairs the column pairs to add
504      * @throws DBException if impossible
505      */

506     public void addColumnPairs(ColumnPairElement[] pairs) throws DBException {
507         for (int i = 0; i < pairs.length; i++) {
508             if (getColumnPair(pairs[i].getName()) != null)
509                 throwAddException("FMT_EXC_AddColumn", pairs[i]); //NOI18N
510
if (pairs[i].getDeclaringTable() == null)
511                 pairs[i].setDeclaringTable(this);
512         }
513         getTableImpl().changeColumnPairs(pairs, Impl.ADD);
514     }
515     
516     /** Removes a column pair from the holder.
517      * @param pair the column pair to remove
518      * @throws DBException if impossible
519      */

520     public void removeColumnPair(ColumnPairElement pair) throws DBException {
521         removeColumnPairs(new ColumnPairElement[] {pair});
522     }
523     
524     /** Removes some column pairs from the holder.
525      * @param pairs the column pairs to remove
526      * @throws DBException if impossible
527      */

528     public void removeColumnPairs(ColumnPairElement[] pairs) throws DBException {
529         getTableImpl().changeColumnPairs(pairs, Impl.REMOVE);
530     }
531     
532     /** Sets the column pairs for this holder.
533      * Previous column pairs are removed.
534      * @param pairs the new column pairs
535      * @throws DBException if impossible
536      */

537     public void setColumnPairs(ColumnPairElement[] pairs) throws DBException {
538         getTableImpl().changeColumnPairs(pairs, Impl.SET);
539     }
540     
541     /** Gets all column pairs in this holder.
542      * @return the column pairs
543      */

544     public ColumnPairElement[] getColumnPairs() {
545         return getTableImpl().getColumnPairs();
546     }
547     
548     /** Finds a column pair by name.
549      * @param name the name of the column pair for which to look
550      * @return the column pair or <code>null</code> if not found
551      */

552     public ColumnPairElement getColumnPair(DBIdentifier name) {
553         return getTableImpl().getColumnPair(name);
554     }
555
556     /** Finds a database member element by name.
557      * @param name the name of the database member element for which to look
558      * @return the database member element or <code>null</code> if not found
559      */

560     public DBMemberElement getMember(DBIdentifier name) {
561         int index = name.getName().indexOf(";"); //NOI18N
562

563         if (index == -1)
564             //column
565
return getColumn(name);
566         else
567             //column pair
568
return getColumnPair(name);
569     }
570     
571     /** Pluggable behaviour for table elements.
572      * @see TableElement
573      */

574     public static interface Impl extends DBElement.Impl {
575         /** Sets whether this is really a table, or a view.
576          * @param isTable one of {@link #TABLE} or {@link #VIEW}
577          * @throws DBException if impossible
578          */

579         public void setTableOrView(boolean isTable) throws DBException;
580
581         /** Tests whether this is a table, or a view.
582          * @return one of {@link #TABLE} or {@link #VIEW}
583          */

584         public boolean isTableOrView();
585
586         /** Changes the set of columns.
587         * @param elems the columns to change
588         * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
589         * @exception DBException if the action cannot be handled
590         */

591         public void changeColumns(ColumnElement[] elems, int action) throws DBException;
592
593         /** Gets all columns.
594         * @return the columns
595         */

596         public ColumnElement[] getColumns();
597
598         /** Finds a column by name.
599         * @param name the name for which to look
600         * @return the column, or <code>null</code> if it does not exist
601         */

602         public ColumnElement getColumn(DBIdentifier name);
603
604         /** Changes the set of indexes.
605         * @param elems the indexes to change
606         * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
607         * @exception DBException if the action cannot be handled
608         */

609         public void changeIndexes(IndexElement[] elems, int action) throws DBException;
610
611         /** Gets all indexes.
612         * @return the indexes
613         */

614         public IndexElement[] getIndexes();
615
616         /** Finds an index by name.
617         * @param name the name for which to look
618         * @return the index, or <code>null</code> if it does not exist
619         */

620         public IndexElement getIndex(DBIdentifier name);
621
622         /** Changes the set of keys.
623         * @param elems the keys to change
624         * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
625         * @exception DBException if the action cannot be handled
626         */

627         public void changeKeys(KeyElement[] elems, int action) throws DBException;
628
629         /** Gets all keys.
630         * @return the keys
631         */

632         public KeyElement[] getKeys();
633
634         /** Finds a key by name.
635         * @param name the name for which to look
636         * @return the key, or <code>null</code> if it does not exist
637         */

638         public KeyElement getKey(DBIdentifier name);
639         
640         /** Changes the set of column pairs.
641         * @param pairs the column pairs to change
642         * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
643         * @exception DBException if the action cannot be handled
644         */

645         public void changeColumnPairs(ColumnPairElement[] pairs, int action) throws DBException;
646         
647         /** Gets all column pairs.
648         * @return the column pairs
649         */

650         public ColumnPairElement[] getColumnPairs();
651
652         /** Finds a column pair by name.
653         * @param name the name for which to look
654         * @return the column pair, or <code>null</code> if it does not exist
655         */

656         public ColumnPairElement getColumnPair(DBIdentifier name);
657     }
658
659     /** Memory based implementation of the element factory.
660      */

661     static final class Memory extends DBElement.Memory implements Impl {
662         /** is table or view */
663         private boolean _isTable;
664
665         /** collection of columns */
666         private DBMemoryCollection.Column columns;
667
668         /** collection of indexes */
669         private DBMemoryCollection.Index indexes;
670
671         /** collection of keys */
672         private DBMemoryCollection.Key keys;
673         
674         /** collection of column pairs */
675         private DBMemoryCollection.ColumnPair pairs;
676
677         /** Default constructor.
678          */

679         public Memory() {
680             super();
681             _isTable = true;
682         }
683
684         /** Copy constructor.
685          * @param el element to copy from
686          */

687         public Memory(TableElement el) {
688             super(el);
689             _isTable = el.isTableOrView();
690         }
691
692         /** Sets whether this is really a table, or a view.
693          * @param isTable one of {@link #TABLE} or {@link #VIEW}
694          * @throws DBException if impossible
695          */

696         public void setTableOrView(boolean isTable) {
697             boolean old = _isTable;
698
699             _isTable = isTable;
700             firePropertyChange(PROP_TABLE_OR_VIEW, Boolean.valueOf(old), Boolean.valueOf(isTable));
701         }
702
703         /** Tests whether this is a table, or a view.
704          * @return one of {@link #TABLE} or {@link #VIEW}
705          */

706         public boolean isTableOrView() {
707             return _isTable;
708         }
709
710         /** Changes set of columns.
711          * @param elems elements to change
712          * @param action the action to do
713          * @exception SourceException if the action cannot be handled
714          */

715         public synchronized void changeColumns(ColumnElement[] elems, int action) throws DBException {
716             initColumns();
717             columns.change(elems, action);
718         }
719
720         /** Gets all columns
721          * @return the columns
722          */

723         public synchronized ColumnElement[] getColumns() {
724             initColumns();
725             return (ColumnElement[]) columns.getElements();
726         }
727
728         /** Finds a column with given name.
729          * @param name the name of column for which to look
730          * @return the element or null if column with such name does not exist
731          */

732         public synchronized ColumnElement getColumn(DBIdentifier name) {
733             initColumns();
734             return (ColumnElement) columns.getElement(name);
735         }
736
737         /** Initializes the collection of columns.
738          */

739         void initColumns() {
740             if (columns == null)
741                 columns = new DBMemoryCollection.Column(this);
742         }
743
744         /** Changes set of indexes.
745          * @param elems elements to change
746          * @param action the action to do
747          * @exception SourceException if the action cannot be handled
748          */

749         public synchronized void changeIndexes(IndexElement[] elems, int action) throws DBException {
750             initIndexes();
751             indexes.change(elems, action);
752         }
753
754         /** Gets all indexes.
755          * @return the indexes
756          */

757         public synchronized IndexElement[] getIndexes() {
758             initIndexes();
759             return (IndexElement[]) indexes.getElements();
760         }
761
762         /** Finds an index with given name.
763          * @param name the name of index for which to look
764          * @return the element or null if index with such name does not exist
765          */

766         public synchronized IndexElement getIndex(DBIdentifier name) {
767             initIndexes();
768             return (IndexElement) indexes.getElement(name);
769         }
770
771         /** Initializes the collection of indexes.
772          */

773         void initIndexes() {
774             if (indexes == null)
775                 indexes = new DBMemoryCollection.Index(this);
776         }
777         
778         /** Changes set of keys.
779          * @param elems elements to change
780          * @param action the action to do
781          * @exception SourceException if the action cannot be handled
782          */

783         public synchronized void changeKeys(KeyElement[] elems, int action) throws DBException {
784             initKeys();
785             keys.change(elems, action);
786         }
787
788         /** Gets all keys.
789          * @return the keys
790          */

791         public synchronized KeyElement[] getKeys() {
792             initKeys();
793             return (KeyElement[]) keys.getElements();
794         }
795
796         /** Finds a key with given name.
797          * @param name the name of key for which to look
798          * @return the element or null if key with such name does not exist
799          */

800         public synchronized KeyElement getKey(DBIdentifier name) {
801             initKeys();
802             return (KeyElement) keys.getElement(name);
803         }
804
805         /** Initializes the collection of keys.
806          */

807         void initKeys() {
808             if (keys == null)
809                 keys = new DBMemoryCollection.Key(this);
810         }
811
812         /** Getter for the associated table
813          * @return the table element for this impl
814          */

815         final TableElement getTableElement() {
816             return (TableElement) _element;
817         }
818         
819         /** Gets all column pairs.
820          * @return the column pairs
821          */

822         public synchronized ColumnPairElement[] getColumnPairs() {
823             initColumnPairs();
824             return (ColumnPairElement[]) pairs.getElements();
825         }
826         
827         /** Finds a column pair with given name.
828          * @param name the name of column pair for which to look
829          * @return the column pair or null if key with such name does not exist
830          */

831         public synchronized ColumnPairElement getColumnPair(DBIdentifier name) {
832             initColumnPairs();
833             return (ColumnPairElement) pairs.getElement(name);
834         }
835         
836         /** Changes set of column pairs.
837          * @param pairs elements to change
838          * @param action the action to do
839          * @exception SourceException if the action cannot be handled
840          */

841         public synchronized void changeColumnPairs(ColumnPairElement[] pairs, int action) throws DBException {
842             initColumnPairs();
843             this.pairs.change(pairs, action);
844         }
845         
846         /** Initializes the collection of column pairs.
847          */

848         void initColumnPairs() {
849             if (pairs == null)
850                 pairs = new DBMemoryCollection.ColumnPair(this);
851         }
852     }
853 }
854
Popular Tags