Source Code Cross Referenced for TableElement.java in  » IDE-Netbeans » db » org » netbeans » modules » dbschema » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » db » org.netbeans.modules.dbschema 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.dbschema;
043:
044:        import java.util.ArrayList;
045:        import java.util.ResourceBundle;
046:        import java.text.MessageFormat;
047:
048:        /** Describes an entire database table.
049:         */
050:        public final class TableElement extends DBElement implements 
051:                ColumnElementHolder, ColumnPairElementHolder {
052:            /** Constant indicating that the table is a real table.
053:             * @see #isTableOrView
054:             */
055:            public static final boolean TABLE = true;
056:
057:            /** Constant indicating that the table is a view.
058:             * @see #isTableOrView
059:             */
060:            public static final boolean VIEW = false;
061:
062:            /** the schema to which this table element belongs */
063:            private transient SchemaElement declaringSchema;
064:
065:            /** Creates a new table element represented in memory.
066:             */
067:            public TableElement() {
068:                this (new Memory(), null);
069:            }
070:
071:            /** Createa a table element.
072:             * @param impl the pluggable implementation
073:             * @param declaringSchema the schema to which this element belongs
074:             */
075:            public TableElement(Impl impl, SchemaElement declaringSchema) {
076:                super (impl);
077:                this .declaringSchema = declaringSchema;
078:            }
079:
080:            /** Returns the implementation for the table.
081:             * @return implementation for the table
082:             */
083:            final Impl getTableImpl() {
084:                return (Impl) getElementImpl();
085:            }
086:
087:            /** Returns the TableElement object associated with the given name and with the given schema.
088:             * @param name the table name
089:             * @param schema the schema
090:             * @return the TableElement object for the given table name in the given schema
091:             */
092:            public static TableElement forName(String name, SchemaElement schema) {
093:                int pos = name.lastIndexOf(".");
094:                if (pos == -1)
095:                    return null;
096:                else
097:                    name = name.substring(pos + 1);
098:
099:                TableElement[] tes = schema.getTables();
100:                for (int i = 0; i < tes.length; i++)
101:                    if (tes[i].getName().getName().trim().equals(name))
102:                        return tes[i];
103:
104:                return null;
105:            }
106:
107:            /** Returns the TableElement object associated with the given name.
108:             * @param name the table name
109:             * @return the TableElement object for the given table name
110:             */
111:            public static TableElement forName(String name) /* 4_ea throws DBException */{
112:                int index = name.lastIndexOf("."); //NOI18N
113:
114:                if (index == -1) {
115:                    if (Boolean.getBoolean("netbeans.debug.exceptions")) // NOI18N
116:                        System.out
117:                                .println(ResourceBundle
118:                                        .getBundle(
119:                                                "org.netbeans.modules.dbschema.resources.Bundle")
120:                                        .getString("FullyQualifiedName")); //NOI18N
121:                    return null;
122:                }
123:
124:                SchemaElement se = SchemaElement.forName(name.substring(0,
125:                        index));
126:
127:                if (se == null)
128:                    // 4_ea            throw new DBException(bundle.getString("SchemaNotFound"));
129:                    return null;
130:                else
131:                    return TableElement.forName(name, se);
132:            }
133:
134:            /** Sets whether this is really a table, or a view.
135:             * @param isTable one of {@link #TABLE} or {@link #VIEW}
136:             * @throws DBException if impossible
137:             */
138:            public void setTableOrView(boolean isTable) throws DBException {
139:                getTableImpl().setTableOrView(isTable);
140:            }
141:
142:            /** Tests whether this is a table, or a view.
143:             * @return one of {@link #TABLE} or {@link #VIEW}
144:             */
145:            public boolean isTableOrView() {
146:                return getTableImpl().isTableOrView();
147:            }
148:
149:            /** Tests whether this is really a table.
150:             * @return <code>true</code> if so
151:             * @see #isTableOrView
152:             */
153:            public boolean isTable() {
154:                return getTableImpl().isTableOrView();
155:            }
156:
157:            /** Test whether this is a view.
158:             * @return <code>true</code> if so
159:             * @see #isTableOrView
160:             */
161:            public boolean isView() {
162:                return !getTableImpl().isTableOrView();
163:            }
164:
165:            // ==================== schema section ==========================
166:
167:            /* This should be automatically synchronized
168:             * when a TableElement is added to the schema. */
169:
170:            /** Gets the declaring schema. 
171:             * @return the schema that owns this table element
172:             */
173:            public final SchemaElement getDeclaringSchema() {
174:                return declaringSchema;
175:            }
176:
177:            /** Sets the declaring schema. 
178:             * @param se the schema that owns this table element
179:             */
180:            public final void setDeclaringSchema(SchemaElement se) {
181:                if (declaringSchema == null)
182:                    declaringSchema = se;
183:            }
184:
185:            //================== Columns ===============================
186:
187:            /** Adds a new column to the table.
188:             * @param el the column to add
189:             * @throws DBException if impossible
190:             */
191:            public void addColumn(ColumnElement el) throws DBException {
192:                addColumns(new ColumnElement[] { el });
193:            }
194:
195:            /** Adds some new columns to the table.
196:             * @param els the columns to add
197:             * @throws DBException if impossible
198:             */
199:            public void addColumns(final ColumnElement[] els)
200:                    throws DBException {
201:                for (int i = 0; i < els.length; i++) {
202:                    if (getColumn(els[i].getName()) != null)
203:                        throwAddException("FMT_EXC_AddColumn", els[i]); //NOI18N
204:                    if (els[i].getDeclaringTable() == null)
205:                        els[i].setDeclaringTable(this );
206:                }
207:                getTableImpl().changeColumns(els, Impl.ADD);
208:            }
209:
210:            /** Removes a column from the table.
211:             * @param el the column to remove
212:             * @throws DBException if impossible
213:             */
214:            public void removeColumn(ColumnElement el) throws DBException {
215:                removeColumns(new ColumnElement[] { el });
216:            }
217:
218:            /** Removes some columns from the table.
219:             * @param els the columns to remove
220:             * @throws DBException if impossible
221:             */
222:            public void removeColumns(final ColumnElement[] els)
223:                    throws DBException {
224:                getTableImpl().changeColumns(els, Impl.REMOVE);
225:            }
226:
227:            /** Sets the columns for this table.
228:             * Previous columns are removed.
229:             * @param els the new columns
230:             * @throws DBException if impossible
231:             */
232:            public void setColumns(ColumnElement[] els) throws DBException {
233:                getTableImpl().changeColumns(els, Impl.SET);
234:            }
235:
236:            /** Gets all columns in this table.
237:             * @return the columns
238:             */
239:            public ColumnElement[] getColumns() {
240:                return getTableImpl().getColumns();
241:            }
242:
243:            /** Finds a column by name.
244:             * @param name the name of the column for which to look
245:             * @return the element or <code>null</code> if not found
246:             */
247:            public ColumnElement getColumn(DBIdentifier name) {
248:                return getTableImpl().getColumn(name);
249:            }
250:
251:            //================== Indexes ===============================
252:
253:            /** Adds a new index to the table.
254:             * @param el the index to add
255:             * @throws DBException if impossible
256:             */
257:            public void addIndex(IndexElement el) throws DBException {
258:                addIndexes(new IndexElement[] { el });
259:            }
260:
261:            /** Adds some new indexes to the table.
262:             * @param els the indexes to add
263:             * @throws DBException if impossible
264:             */
265:            public void addIndexes(final IndexElement[] els) throws DBException {
266:                for (int i = 0; i < els.length; i++) {
267:                    if (getIndex(els[i].getName()) != null)
268:                        throwAddException("FMT_EXC_AddColumn", els[i]); //NOI18N
269:                    if (els[i].getDeclaringTable() == null)
270:                        els[i].setDeclaringTable(this );
271:                }
272:
273:                getTableImpl().changeIndexes(els, Impl.ADD);
274:            }
275:
276:            /** Removesan index from the table.
277:             * @param el the index to remove
278:             * @throws DBException if impossible
279:             */
280:            public void removeIndex(IndexElement el) throws DBException {
281:                removeIndexes(new IndexElement[] { el });
282:            }
283:
284:            /** Removes some indexes from the table.
285:             * @param els the indexes to remove
286:             * @throws DBException if impossible
287:             */
288:            public void removeIndexes(final IndexElement[] els)
289:                    throws DBException {
290:                getTableImpl().changeIndexes(els, Impl.REMOVE);
291:            }
292:
293:            /** Sets the indexes for this table.
294:             * Previous indexes are removed.
295:             * @param els the new indexes
296:             * @throws DBException if impossible
297:             */
298:            public void setIndexes(IndexElement[] els) throws DBException {
299:                getTableImpl().changeIndexes(els, Impl.SET);
300:            }
301:
302:            /** Gets all indexes in this table.
303:             * @return the indexes
304:             */
305:            public IndexElement[] getIndexes() {
306:                return getTableImpl().getIndexes();
307:            }
308:
309:            /** Finds an index by name.
310:             * @param name the name of the index for which to look
311:             * @return the element or <code>null</code> if not found
312:             */
313:            public IndexElement getIndex(DBIdentifier name) {
314:                return getTableImpl().getIndex(name);
315:            }
316:
317:            //================== Keys (Unique, Primary, and Foreign) =================
318:
319:            /** Adds a new key to the table.
320:             *  @param el the key to add
321:             * @throws DBException if impossible
322:             */
323:            public void addKey(KeyElement el) throws DBException {
324:                addKeys(new KeyElement[] { el });
325:            }
326:
327:            /** Adds some new keys to the table.
328:             *  @param els the keys to add
329:             * @throws DBException if impossible
330:             */
331:            public void addKeys(final KeyElement[] els) throws DBException {
332:                for (int i = 0; i < els.length; i++) {
333:                    if (getKey(els[i].getName()) != null)
334:                        throwAddException("FMT_EXC_AddColumn", els[i]); //NOI18N
335:                    if (els[i].getDeclaringTable() == null)
336:                        els[i].setDeclaringTable(this );
337:                    if (els[i] instanceof  UniqueKeyElement)
338:                        if (((UniqueKeyElement) els[i]).getAssociatedIndex() == null) {
339:                            IndexElement ie = new IndexElement();
340:                            try {
341:                                ie.setName(els[i].getName());
342:                                ie.setColumns(els[i].getColumns());
343:                                this .addIndex(ie);
344:                            } catch (DBException exc) {
345:                                exc.printStackTrace();
346:                            }
347:                            ((UniqueKeyElement) els[i]).setAssociatedIndex(ie);
348:                        }
349:                }
350:
351:                getTableImpl().changeKeys(els, Impl.ADD);
352:            }
353:
354:            /** Removes a key from the table.
355:             *  @param el the key to remove
356:             * @throws DBException if impossible
357:             */
358:            public void removeKey(KeyElement el) throws DBException {
359:                removeKeys(new KeyElement[] { el });
360:            }
361:
362:            /** Removes some keys from the table.
363:             *  @param els the keys to remove
364:             * @throws DBException if impossible
365:             */
366:            public void removeKeys(final KeyElement[] els) throws DBException {
367:                getTableImpl().changeKeys(els, Impl.REMOVE);
368:            }
369:
370:            /** Sets the keys for this table.
371:             * Previous keys are removed.
372:             * @param els the new keys
373:             * @throws DBException if impossible
374:             */
375:
376:            public void setKeys(KeyElement[] els) throws DBException {
377:                getTableImpl().changeKeys(els, Impl.SET);
378:            }
379:
380:            /** Gets all keys in this table.
381:             * @return the keys
382:             */
383:            public KeyElement[] getKeys() {
384:                return getTableImpl().getKeys();
385:            }
386:
387:            /** Finds a key by name.
388:             * @param name the name of the key for which to look
389:             * @return the element or <code>null</code> if not found
390:             */
391:            public KeyElement getKey(DBIdentifier name) {
392:                return getTableImpl().getKey(name);
393:            }
394:
395:            // key convenience methods
396:
397:            /** Gets all keys in this table of the given subtype.
398:             * @param subtype the type of the key classes
399:             * @return the keys of the given subtype or <code>null</code> if not found
400:             */
401:            private ArrayList getKeys(Class subtype) {
402:                KeyElement[] keys = getKeys();
403:
404:                if (keys == null)
405:                    return null;
406:
407:                int i, count = keys.length;
408:                ArrayList subKeys = new ArrayList(count);
409:
410:                for (i = 0; i < count; i++) {
411:                    KeyElement key = keys[i];
412:
413:                    if (subtype.isInstance(key))
414:                        subKeys.add(key);
415:                }
416:
417:                return subKeys;
418:            }
419:
420:            /** Gets all foreign keys in this table.
421:             * @return the foreign keys or <code>null</code> if not found
422:             */
423:            public ForeignKeyElement[] getForeignKeys() {
424:                ArrayList keys = getKeys(ForeignKeyElement.class);
425:
426:                if (keys == null)
427:                    return null;
428:
429:                int count = keys.size();
430:
431:                return ((ForeignKeyElement[]) keys
432:                        .toArray(new ForeignKeyElement[count]));
433:            }
434:
435:            /** Finds a foreign key by name.
436:             * @param name the name of the foreign key for which to look
437:             * @return the foreign key or <code>null</code> if not found
438:             */
439:            public ForeignKeyElement getForeignKey(DBIdentifier name) {
440:                ForeignKeyElement[] fks = getForeignKeys();
441:                int i, count = fks.length;
442:
443:                for (i = 0; i < count; i++) {
444:                    ForeignKeyElement fk = fks[i];
445:
446:                    if (name.equals(fk.getName()))
447:                        return fk;
448:                }
449:
450:                return null;
451:            }
452:
453:            /** Gets all unique keys in this table.
454:             * @return the unique keys or <code>null</code> if not found
455:             */
456:            public UniqueKeyElement[] getUniqueKeys() {
457:                ArrayList keys = getKeys(UniqueKeyElement.class);
458:
459:                if (keys == null)
460:                    return null;
461:
462:                return ((UniqueKeyElement[]) keys
463:                        .toArray(new UniqueKeyElement[keys.size()]));
464:            }
465:
466:            /** Finds a unique key by name.
467:             * @param name the name of the unique key for which to look
468:             * @return the unique key or <code>null</code> if not found
469:             */
470:            public UniqueKeyElement getUniqueKey(DBIdentifier name) {
471:                UniqueKeyElement[] uks = getUniqueKeys();
472:                int i, count = uks.length;
473:
474:                for (i = 0; i < count; i++) {
475:                    UniqueKeyElement uk = uks[i];
476:
477:                    if (name.equals(uk.getName()))
478:                        return uk;
479:                }
480:
481:                return null;
482:            }
483:
484:            /** Finds the primary key.
485:             * @return the primary key or <code>null</code> if not found
486:             */
487:            public UniqueKeyElement getPrimaryKey() {
488:                UniqueKeyElement[] uks = getUniqueKeys();
489:
490:                if (uks == null)
491:                    return null;
492:
493:                for (int i = 0; i < uks.length; i++) {
494:                    UniqueKeyElement uk = uks[i];
495:
496:                    if (uk.isPrimaryKey())
497:                        return uk;
498:                }
499:
500:                return null;
501:            }
502:
503:            // end key convenience methods
504:
505:            /** This method just throws localized exception. It is used during
506:             * adding class element, which already exists in source.
507:             * @param formatKey The message format key to localized bundle.
508:             * @param element The element which can't be added
509:             * @exception DBException is alway thrown from this method.
510:             */
511:            private void throwAddException(String formatKey,
512:                    DBMemberElement element) throws DBException {
513:                // MessageFormat format = new MessageFormat(ElementFormat.bundle.getString(formatKey));
514:                String msg = /*format.format(new Object[] { */element
515:                        .getName().getName();// });
516:                throw new DBException(msg);
517:            }
518:
519:            /** Returns a string representation of the object.
520:             * @return a string representation of the object.
521:             */
522:            public String toString() {
523:                if (getName() != null)
524:                    return getName().toString();
525:                else
526:                    return null;
527:            }
528:
529:            /** Adds a new column pair to the holder.
530:             * @param pair the pair to add
531:             * @throws DBException if impossible
532:             */
533:            public void addColumnPair(ColumnPairElement pair)
534:                    throws DBException {
535:                addColumnPairs(new ColumnPairElement[] { pair });
536:            }
537:
538:            /** Adds some new column pairs to the holder.
539:             * @param pairs the column pairs to add
540:             * @throws DBException if impossible
541:             */
542:            public void addColumnPairs(ColumnPairElement[] pairs)
543:                    throws DBException {
544:                for (int i = 0; i < pairs.length; i++) {
545:                    if (getColumnPair(pairs[i].getName()) != null)
546:                        throwAddException("FMT_EXC_AddColumn", pairs[i]); //NOI18N
547:                    if (pairs[i].getDeclaringTable() == null)
548:                        pairs[i].setDeclaringTable(this );
549:                }
550:                getTableImpl().changeColumnPairs(pairs, Impl.ADD);
551:            }
552:
553:            /** Removes a column pair from the holder.
554:             * @param pair the column pair to remove
555:             * @throws DBException if impossible
556:             */
557:            public void removeColumnPair(ColumnPairElement pair)
558:                    throws DBException {
559:                removeColumnPairs(new ColumnPairElement[] { pair });
560:            }
561:
562:            /** Removes some column pairs from the holder.
563:             * @param pairs the column pairs to remove
564:             * @throws DBException if impossible
565:             */
566:            public void removeColumnPairs(ColumnPairElement[] pairs)
567:                    throws DBException {
568:                getTableImpl().changeColumnPairs(pairs, Impl.REMOVE);
569:            }
570:
571:            /** Sets the column pairs for this holder.
572:             * Previous column pairs are removed.
573:             * @param pairs the new column pairs
574:             * @throws DBException if impossible
575:             */
576:            public void setColumnPairs(ColumnPairElement[] pairs)
577:                    throws DBException {
578:                getTableImpl().changeColumnPairs(pairs, Impl.SET);
579:            }
580:
581:            /** Gets all column pairs in this holder.
582:             * @return the column pairs
583:             */
584:            public ColumnPairElement[] getColumnPairs() {
585:                return getTableImpl().getColumnPairs();
586:            }
587:
588:            /** Finds a column pair by name.
589:             * @param name the name of the column pair for which to look
590:             * @return the column pair or <code>null</code> if not found
591:             */
592:            public ColumnPairElement getColumnPair(DBIdentifier name) {
593:                return getTableImpl().getColumnPair(name);
594:            }
595:
596:            /** Finds a database member element by name.
597:             * @param name the name of the database member element for which to look
598:             * @return the database member element or <code>null</code> if not found
599:             */
600:            public DBMemberElement getMember(DBIdentifier name) {
601:                int index = name.getName().indexOf(";"); //NOI18N
602:
603:                if (index == -1)
604:                    //column
605:                    return getColumn(name);
606:                else
607:                    //column pair
608:                    return getColumnPair(name);
609:            }
610:
611:            /** Pluggable behaviour for table elements.
612:             * @see TableElement
613:             */
614:            public static interface Impl extends DBElement.Impl {
615:                /** Sets whether this is really a table, or a view.
616:                 * @param isTable one of {@link #TABLE} or {@link #VIEW}
617:                 * @throws DBException if impossible
618:                 */
619:                public void setTableOrView(boolean isTable) throws DBException;
620:
621:                /** Tests whether this is a table, or a view.
622:                 * @return one of {@link #TABLE} or {@link #VIEW}
623:                 */
624:                public boolean isTableOrView();
625:
626:                /** Changes the set of columns.
627:                 * @param elems the columns to change
628:                 * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
629:                 * @exception DBException if the action cannot be handled
630:                 */
631:                public void changeColumns(ColumnElement[] elems, int action)
632:                        throws DBException;
633:
634:                /** Gets all columns.
635:                 * @return the columns
636:                 */
637:                public ColumnElement[] getColumns();
638:
639:                /** Finds a column by name.
640:                 * @param name the name for which to look
641:                 * @return the column, or <code>null</code> if it does not exist
642:                 */
643:                public ColumnElement getColumn(DBIdentifier name);
644:
645:                /** Changes the set of indexes.
646:                 * @param elems the indexes to change
647:                 * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
648:                 * @exception DBException if the action cannot be handled
649:                 */
650:                public void changeIndexes(IndexElement[] elems, int action)
651:                        throws DBException;
652:
653:                /** Gets all indexes.
654:                 * @return the indexes
655:                 */
656:                public IndexElement[] getIndexes();
657:
658:                /** Finds an index by name.
659:                 * @param name the name for which to look
660:                 * @return the index, or <code>null</code> if it does not exist
661:                 */
662:                public IndexElement getIndex(DBIdentifier name);
663:
664:                /** Changes the set of keys.
665:                 * @param elems the keys to change
666:                 * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
667:                 * @exception DBException if the action cannot be handled
668:                 */
669:                public void changeKeys(KeyElement[] elems, int action)
670:                        throws DBException;
671:
672:                /** Gets all keys.
673:                 * @return the keys
674:                 */
675:                public KeyElement[] getKeys();
676:
677:                /** Finds a key by name.
678:                 * @param name the name for which to look
679:                 * @return the key, or <code>null</code> if it does not exist
680:                 */
681:                public KeyElement getKey(DBIdentifier name);
682:
683:                /** Changes the set of column pairs.
684:                 * @param pairs the column pairs to change
685:                 * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
686:                 * @exception DBException if the action cannot be handled
687:                 */
688:                public void changeColumnPairs(ColumnPairElement[] pairs,
689:                        int action) throws DBException;
690:
691:                /** Gets all column pairs.
692:                 * @return the column pairs
693:                 */
694:                public ColumnPairElement[] getColumnPairs();
695:
696:                /** Finds a column pair by name.
697:                 * @param name the name for which to look
698:                 * @return the column pair, or <code>null</code> if it does not exist
699:                 */
700:                public ColumnPairElement getColumnPair(DBIdentifier name);
701:            }
702:
703:            /** Memory based implementation of the element factory.
704:             */
705:            static final class Memory extends DBElement.Memory implements  Impl {
706:                /** is table or view */
707:                private boolean _isTable;
708:
709:                /** collection of columns */
710:                private DBMemoryCollection.Column columns;
711:
712:                /** collection of indexes */
713:                private DBMemoryCollection.Index indexes;
714:
715:                /** collection of keys */
716:                private DBMemoryCollection.Key keys;
717:
718:                /** collection of column pairs */
719:                private DBMemoryCollection.ColumnPair pairs;
720:
721:                /** Default constructor.
722:                 */
723:                public Memory() {
724:                    super ();
725:                    _isTable = true;
726:                }
727:
728:                /** Copy constructor.
729:                 * @param el element to copy from
730:                 */
731:                public Memory(TableElement el) {
732:                    super (el);
733:                    _isTable = el.isTableOrView();
734:                }
735:
736:                /** Sets whether this is really a table, or a view.
737:                 * @param isTable one of {@link #TABLE} or {@link #VIEW}
738:                 * @throws DBException if impossible
739:                 */
740:                public void setTableOrView(boolean isTable) {
741:                    boolean old = _isTable;
742:
743:                    _isTable = isTable;
744:                    firePropertyChange(PROP_TABLE_OR_VIEW,
745:                            Boolean.valueOf(old), Boolean.valueOf(isTable));
746:                }
747:
748:                /** Tests whether this is a table, or a view.
749:                 * @return one of {@link #TABLE} or {@link #VIEW}
750:                 */
751:                public boolean isTableOrView() {
752:                    return _isTable;
753:                }
754:
755:                /** Changes set of columns.
756:                 * @param elems elements to change
757:                 * @param action the action to do
758:                 * @exception SourceException if the action cannot be handled
759:                 */
760:                public synchronized void changeColumns(ColumnElement[] elems,
761:                        int action) throws DBException {
762:                    initColumns();
763:                    columns.change(elems, action);
764:                }
765:
766:                /** Gets all columns
767:                 * @return the columns
768:                 */
769:                public synchronized ColumnElement[] getColumns() {
770:                    initColumns();
771:                    return (ColumnElement[]) columns.getElements();
772:                }
773:
774:                /** Finds a column with given name.
775:                 * @param name the name of column for which to look
776:                 * @return the element or null if column with such name does not exist
777:                 */
778:                public synchronized ColumnElement getColumn(DBIdentifier name) {
779:                    initColumns();
780:                    return (ColumnElement) columns.getElement(name);
781:                }
782:
783:                /** Initializes the collection of columns.
784:                 */
785:                void initColumns() {
786:                    if (columns == null)
787:                        columns = new DBMemoryCollection.Column(this );
788:                }
789:
790:                /** Changes set of indexes.
791:                 * @param elems elements to change
792:                 * @param action the action to do
793:                 * @exception SourceException if the action cannot be handled
794:                 */
795:                public synchronized void changeIndexes(IndexElement[] elems,
796:                        int action) throws DBException {
797:                    initIndexes();
798:                    indexes.change(elems, action);
799:                }
800:
801:                /** Gets all indexes.
802:                 * @return the indexes
803:                 */
804:                public synchronized IndexElement[] getIndexes() {
805:                    initIndexes();
806:                    return (IndexElement[]) indexes.getElements();
807:                }
808:
809:                /** Finds an index with given name.
810:                 * @param name the name of index for which to look
811:                 * @return the element or null if index with such name does not exist
812:                 */
813:                public synchronized IndexElement getIndex(DBIdentifier name) {
814:                    initIndexes();
815:                    return (IndexElement) indexes.getElement(name);
816:                }
817:
818:                /** Initializes the collection of indexes.
819:                 */
820:                void initIndexes() {
821:                    if (indexes == null)
822:                        indexes = new DBMemoryCollection.Index(this );
823:                }
824:
825:                /** Changes set of keys.
826:                 * @param elems elements to change
827:                 * @param action the action to do
828:                 * @exception SourceException if the action cannot be handled
829:                 */
830:                public synchronized void changeKeys(KeyElement[] elems,
831:                        int action) throws DBException {
832:                    initKeys();
833:                    keys.change(elems, action);
834:                }
835:
836:                /** Gets all keys.
837:                 * @return the keys
838:                 */
839:                public synchronized KeyElement[] getKeys() {
840:                    initKeys();
841:                    return (KeyElement[]) keys.getElements();
842:                }
843:
844:                /** Finds a key with given name.
845:                 * @param name the name of key for which to look
846:                 * @return the element or null if key with such name does not exist
847:                 */
848:                public synchronized KeyElement getKey(DBIdentifier name) {
849:                    initKeys();
850:                    return (KeyElement) keys.getElement(name);
851:                }
852:
853:                /** Initializes the collection of keys.
854:                 */
855:                void initKeys() {
856:                    if (keys == null)
857:                        keys = new DBMemoryCollection.Key(this );
858:                }
859:
860:                /** Getter for the associated table
861:                 * @return the table element for this impl
862:                 */
863:                final TableElement getTableElement() {
864:                    return (TableElement) _element;
865:                }
866:
867:                /** Gets all column pairs.
868:                 * @return the column pairs
869:                 */
870:                public synchronized ColumnPairElement[] getColumnPairs() {
871:                    initColumnPairs();
872:                    return (ColumnPairElement[]) pairs.getElements();
873:                }
874:
875:                /** Finds a column pair with given name.
876:                 * @param name the name of column pair for which to look
877:                 * @return the column pair or null if key with such name does not exist
878:                 */
879:                public synchronized ColumnPairElement getColumnPair(
880:                        DBIdentifier name) {
881:                    initColumnPairs();
882:                    return (ColumnPairElement) pairs.getElement(name);
883:                }
884:
885:                /** Changes set of column pairs.
886:                 * @param pairs elements to change
887:                 * @param action the action to do
888:                 * @exception SourceException if the action cannot be handled
889:                 */
890:                public synchronized void changeColumnPairs(
891:                        ColumnPairElement[] pairs, int action)
892:                        throws DBException {
893:                    initColumnPairs();
894:                    this .pairs.change(pairs, action);
895:                }
896:
897:                /** Initializes the collection of column pairs.
898:                 */
899:                void initColumnPairs() {
900:                    if (pairs == null)
901:                        pairs = new DBMemoryCollection.ColumnPair(this);
902:                }
903:            }
904:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.