Source Code Cross Referenced for DBTableImpl.java in  » IDE-Netbeans » sql.project » org » netbeans » modules » jdbcwizard » builder » dbmodel » impl » 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 » sql.project » org.netbeans.modules.jdbcwizard.builder.dbmodel.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms of the Common Development
003:         * and Distribution License (the License). You may not use this file except in
004:         * compliance with the License.
005:         * 
006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007:         * or http://www.netbeans.org/cddl.txt.
008:         * 
009:         * When distributing Covered Code, include this CDDL Header Notice in each file
010:         * and include the License file at http://www.netbeans.org/cddl.txt.
011:         * If applicable, add the following below the CDDL Header, with the fields
012:         * enclosed by brackets [] replaced by your own identifying information:
013:         * "Portions Copyrighted [year] [name of copyright owner]"
014:         * 
015:         * The Original Software is NetBeans. The Initial Developer of the Original
016:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017:         * Microsystems, Inc. All Rights Reserved.
018:         */
019:
020:        /*
021:         * 
022:         * Copyright 2005 Sun Microsystems, Inc.
023:         * 
024:         * Licensed under the Apache License, Version 2.0 (the "License");
025:         * you may not use this file except in compliance with the License.
026:         * You may obtain a copy of the License at
027:         * 
028:         * 	http://www.apache.org/licenses/LICENSE-2.0
029:         * 
030:         * Unless required by applicable law or agreed to in writing, software
031:         * distributed under the License is distributed on an "AS IS" BASIS,
032:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
033:         * See the License for the specific language governing permissions and
034:         * limitations under the License.
035:         * 
036:         */
037:        package org.netbeans.modules.jdbcwizard.builder.dbmodel.impl;
038:
039:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.DatabaseModel;
040:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBTable;
041:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.DBColumn;
042:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.PrimaryKey;
043:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.ForeignKey;
044:        import org.netbeans.modules.jdbcwizard.builder.dbmodel.Index;
045:
046:        import java.util.ArrayList;
047:        import java.util.Collection;
048:        import java.util.Collections;
049:        import java.util.Comparator;
050:        import java.util.HashSet;
051:        import java.util.Iterator;
052:        import java.util.List;
053:        import java.util.Map;
054:        import java.util.HashMap;
055:        import java.util.Set;
056:
057:        import java.util.ResourceBundle;
058:
059:        import org.openide.util.NbBundle;
060:
061:        /**
062:         * Reference implementation for interface com.stc.model.database.DBTable
063:         * 
064:         * @author
065:         */
066:        public class DBTableImpl implements  DBTable, Cloneable, Comparable {
067:
068:            /* Log4J category string */
069:            private static final String LOG_CATEGORY = DBTableImpl.class
070:                    .getName();
071:
072:            /** table name. */
073:            protected String name;
074:
075:            /** user-defined description */
076:            protected String description;
077:
078:            /** schema to which this table belongs. */
079:            protected String schema;
080:
081:            /** catalog to which this table belongs. */
082:            protected String catalog;
083:
084:            /** Type of this table, these are "TABLE" or "VIEW" */
085:            protected String type = null;
086:
087:            /** DatabaseModelImpl instance that "owns" this table. */
088:            protected DatabaseModel parent;
089:
090:            /** Map of column metadata. */
091:            protected Map columns;
092:
093:            /**
094:             * Map of columns in the order the driver returns them. Order preserving to keep both JCE and
095:             * BPEL editors show the otd in the same way.
096:             */
097:            protected ArrayList columnsInTableOrder;
098:
099:            /** PrimaryKey for this table; may be null. */
100:            protected PrimaryKeyImpl primaryKey;
101:
102:            /** Map of names to ForeignKey instances for this table; may be empty. */
103:            protected Map foreignKeys;
104:
105:            /** Map of names to Index instances for this table; may be empty. */
106:            protected Map indexes;
107:
108:            /**
109:             * Java name of this table; not in DatabaseModel but supplied as courtesy for WSDL
110:             */
111:            protected String javaName;
112:
113:            private final HashMap jdbcTypeMap = new HashMap();
114:
115:            private final HashMap sqlTypeMap = new HashMap();
116:
117:            /** editable */
118:            protected boolean editable = true;
119:
120:            /** selected */
121:            protected boolean selected = false;
122:
123:            /* No-arg constructor; initializes Collections-related member variables. */
124:            private DBTableImpl() {
125:                this .columns = new HashMap();
126:                this .foreignKeys = new HashMap();
127:                this .indexes = new HashMap();
128:                this .columnsInTableOrder = new ArrayList();
129:                this .initJDBCTypeMap();
130:            }
131:
132:            /**
133:             * Creates a new instance of DBTableImpl with the given name.
134:             * 
135:             * @param aName name of new DBTable instance
136:             * @param aSchema schema of new DBTable instance; may be null
137:             * @param aCatalog catalog of new DBTable instance; may be null
138:             */
139:            public DBTableImpl(final String aName, final String aSchema,
140:                    final String aCatalog) {
141:                this ();
142:
143:                this .name = aName != null ? aName.trim() : null;
144:                this .schema = aSchema != null ? aSchema.trim() : null;
145:                this .catalog = aCatalog != null ? aCatalog.trim() : null;
146:            }
147:
148:            /**
149:             * Creates a new instance of DBTableImpl with the given name.
150:             * 
151:             * @param aName name of new DBTable instance
152:             * @param aSchema schema of new DBTable instance; may be null
153:             * @param aCatalog catalog of new DBTable instance; may be null
154:             * @param aType type of new DBTable instance;
155:             */
156:            public DBTableImpl(final String aName, final String aSchema,
157:                    final String aCatalog, final String aType) {
158:                this ();
159:
160:                this .name = aName != null ? aName.trim() : null;
161:                this .schema = aSchema != null ? aSchema.trim() : null;
162:                this .catalog = aCatalog != null ? aCatalog.trim() : null;
163:                this .type = aType != null ? aType.trim() : null;
164:            }
165:
166:            /**
167:             * Creates a new instance of DBTableImpl, cloning the contents of the given DBTable
168:             * implementation instance.
169:             * 
170:             * @param src DBTable instance to be cloned
171:             */
172:            public DBTableImpl(final DBTable src) {
173:                this ();
174:
175:                if (src == null) {
176:                    final ResourceBundle cMessages = NbBundle
177:                            .getBundle(DBTableImpl.class);
178:
179:                    throw new IllegalArgumentException(cMessages
180:                            .getString("ERROR_NULL_DBTABLE")
181:                            + "ERROR_NULL_DBTABLE");// NO
182:                    // i18n
183:                }
184:
185:                this .copyFrom(src);
186:            }
187:
188:            /*
189:             * Implementation of DBTable interface.
190:             */
191:
192:            /**
193:             * @see com.stc.model.database.DBTable#getName
194:             */
195:            public String getName() {
196:                return this .name;
197:            }
198:
199:            /**
200:             * @see com.stc.model.database.DBTable#getDescription
201:             */
202:            public String getDescription() {
203:                return this .description;
204:            }
205:
206:            /**
207:             * @see com.stc.model.database.DBTable#getSchema
208:             */
209:            public String getSchema() {
210:                return this .schema;
211:            }
212:
213:            /**
214:             * @see com.stc.model.database.DBTable#getCatalog
215:             */
216:            public String getCatalog() {
217:                return this .catalog;
218:            }
219:
220:            /**
221:             * @see com.stc.model.database.DBTable#getType
222:             */
223:            public String getType() {
224:                return this .type;
225:            }
226:
227:            /**
228:             * @see com.stc.model.database.DBTable#getColumns
229:             */
230:            public Map getColumns() {
231:                return this .columns;
232:            }
233:
234:            /**
235:             * @see com.stc.model.database.DBTable#getColumnList
236:             */
237:            public List getColumnList() {
238:                final List list = new ArrayList();
239:                list.addAll(this .columns.values());
240:                return list;
241:            }
242:
243:            /**
244:             * Map of columns in the order the driver returns them. Order preserving to keep both JCE and
245:             * BPEL editors show the otd in the same way.
246:             */
247:            public List getColumnListInTablelOrder() {
248:                return this .columnsInTableOrder;
249:            }
250:
251:            /**
252:             * @see com.stc.model.database.DBTable#getParent
253:             */
254:            public DatabaseModel getParent() {
255:                return this .parent;
256:            }
257:
258:            /**
259:             * @see com.stc.model.database.DBTable#getPrimaryKey
260:             */
261:            public PrimaryKey getPrimaryKey() {
262:                return this .primaryKey;
263:            }
264:
265:            /**
266:             * @see com.stc.model.database.DBTable#getForeignKeys
267:             */
268:            public List getForeignKeys() {
269:                return new ArrayList(this .foreignKeys.values());
270:            }
271:
272:            /**
273:             * @see com.stc.model.database.DBTable#getForeignKey(String)
274:             */
275:            public ForeignKey getForeignKey(final String fkName) {
276:                return (ForeignKey) this .foreignKeys.get(fkName);
277:            }
278:
279:            /**
280:             * @see com.stc.model.database.DBTable#getReferencedTables
281:             */
282:            public Set getReferencedTables() {
283:                Set tables = Collections.EMPTY_SET;
284:                final List keys = this .getForeignKeys();
285:
286:                if (keys.size() != 0) {
287:                    tables = new HashSet(keys.size());
288:                    final Iterator iter = keys.iterator();
289:                    while (iter.hasNext()) {
290:                        final ForeignKeyImpl fk = (ForeignKeyImpl) iter.next();
291:                        final DBTable pkTable = this .parent.getTable(fk
292:                                .getPKTable(), fk.getPKSchema(), fk
293:                                .getPKCatalog());
294:                        if (pkTable != null
295:                                && fk.references(pkTable.getPrimaryKey())) {
296:                            tables.add(pkTable);
297:                        }
298:                    }
299:
300:                    if (tables.size() == 0) {
301:                        tables.clear();
302:                        tables = Collections.EMPTY_SET;
303:                    }
304:                }
305:
306:                return tables;
307:            }
308:
309:            /**
310:             * @see com.stc.model.database.DBTable#getIndexes
311:             */
312:            public List getIndexes() {
313:                return new ArrayList(this .indexes.values());
314:            }
315:
316:            /**
317:             * @see com.stc.model.database.DBTable#getIndex
318:             */
319:            public Index getIndex(final String indexName) {
320:                return (Index) this .indexes.get(indexName);
321:            }
322:
323:            /**
324:             * @see com.stc.model.database.DBTable#references
325:             */
326:            public boolean references(final DBTable pkTarget) {
327:                return this .getReferenceFor(pkTarget) != null;
328:            }
329:
330:            /**
331:             * @see com.stc.model.database.DBTable#getReferenceFor
332:             */
333:            public ForeignKey getReferenceFor(final DBTable target) {
334:                if (target == null) {
335:                    return null;
336:                }
337:
338:                final PrimaryKey targetPK = target.getPrimaryKey();
339:                if (targetPK == null) {
340:                    return null;
341:                }
342:
343:                final Iterator iter = this .foreignKeys.values().iterator();
344:                while (iter.hasNext()) {
345:                    final ForeignKey myFK = (ForeignKey) iter.next();
346:                    if (myFK.references(targetPK)) {
347:                        return myFK;
348:                    }
349:                }
350:
351:                return null;
352:            }
353:
354:            /*
355:             * Setters and non-API helper methods for this implementation.
356:             */
357:            /**
358:             * Sets table name to new value.
359:             * 
360:             * @param newSchema new value for schema name
361:             */
362:            public void setName(final String newName) {
363:                this .name = newName;
364:            }
365:
366:            /**
367:             * Sets schema name to new value.
368:             * 
369:             * @param newSchema new value for schema name
370:             */
371:            public void setSchema(final String newSchema) {
372:                this .schema = newSchema;
373:            }
374:
375:            /**
376:             * Sets catalog name to new value.
377:             * 
378:             * @param newCatalog new value for catalog name
379:             */
380:            public void setCatalog(final String newCatalog) {
381:                this .catalog = newCatalog;
382:            }
383:
384:            /**
385:             * Sets type name to new value.
386:             * 
387:             * @param newType new value for type name
388:             */
389:            public void setType(final String newType) {
390:                this .type = newType;
391:            }
392:
393:            /**
394:             * Sets PrimaryKey instance for this DBTable to the given instance.
395:             * 
396:             * @param newPk new PrimaryKey instance to be associated
397:             * @return true if association succeeded, false otherwise
398:             */
399:            public boolean setPrimaryKey(final PrimaryKeyImpl newPk) {
400:                if (newPk != null) {
401:                    newPk.setParent(this );
402:                }
403:
404:                this .primaryKey = newPk;
405:                return true;
406:            }
407:
408:            /**
409:             * Adds the given ForeignKeyImpl, associating it with this DBTableImpl instance.
410:             * 
411:             * @param newFk new ForeignKeyImpl instance to be added
412:             * @return return true if addition succeeded, false otherwise
413:             */
414:            public boolean addForeignKey(final ForeignKeyImpl newFk) {
415:                if (newFk != null) {
416:                    newFk.setParent(this );
417:                    this .foreignKeys.put(newFk.getName(), newFk);
418:                    return true;
419:                } else {
420:                    return false;
421:                }
422:            }
423:
424:            /**
425:             * Dissociates the given ForeignKeyImpl from this DBTableImpl instance, removing it from its
426:             * internal FK collection.
427:             * 
428:             * @param newFk new ForeignKeyImpl instance to be removed
429:             * @return return true if removal succeeded, false otherwise
430:             */
431:            public boolean removeForeignKey(final ForeignKeyImpl oldKey) {
432:                if (oldKey != null) {
433:                    return this .foreignKeys.remove(oldKey.getName()) != null;
434:                }
435:
436:                return false;
437:            }
438:
439:            /**
440:             * Clears list of foreign keys.
441:             */
442:            public void clearForeignKeys() {
443:                this .foreignKeys.clear();
444:            }
445:
446:            /**
447:             * Adds the given IndexImpl, associating it with this DBTableImpl instance.
448:             * 
449:             * @param newIndex new IndexImpl instance to be added
450:             * @return return true if addition succeeded, false otherwise
451:             */
452:            public boolean addIndex(final IndexImpl newIndex) {
453:                if (newIndex != null) {
454:                    newIndex.setParent(this );
455:                    this .indexes.put(newIndex.getName(), newIndex);
456:
457:                    return true;
458:                } else {
459:                    return false;
460:                }
461:            }
462:
463:            /**
464:             * Clears list of indexes.
465:             */
466:            public void clearIndexes() {
467:                this .indexes.clear();
468:            }
469:
470:            /**
471:             * Compares DBTable with another object for lexicographical ordering. Null objects and those
472:             * DBTables with null names are placed at the end of any ordered collection using this method.
473:             * 
474:             * @param refObj Object to be compared.
475:             * @return -1 if the column name is less than obj to be compared. 0 if the column name is the
476:             *         same. 1 if the column name is greater than obj to be compared.
477:             */
478:            public int compareTo(final Object refObj) {
479:                if (refObj == null) {
480:                    return -1;
481:                }
482:
483:                if (refObj == this ) {
484:                    return 0;
485:                }
486:
487:                final String refName = this .parent != null ? this .parent
488:                        .getFullyQualifiedTableName((DBTable) refObj)
489:                        : ((DBTable) refObj).getName();
490:
491:                final String myName = this .parent != null ? this .parent
492:                        .getFullyQualifiedTableName(this ) : this .name;
493:
494:                return myName != null ? myName.compareTo(refName)
495:                        : refName != null ? 1 : -1;
496:            }
497:
498:            /**
499:             * Overrides default implementation to return value based on memberwise comparison.
500:             * 
501:             * @param obj Object against which we compare this instance
502:             * @return true if obj is functionally identical to this JDBCTable instance; false otherwise
503:             */
504:            public boolean equals(final Object obj) {
505:                boolean result = false;
506:
507:                // Check for reflexivity first.
508:                if (this  == obj) {
509:                    return true;
510:                }
511:
512:                // Check for castability (also deals with null obj)
513:                if (obj instanceof  DBTable) {
514:                    final DBTable aTable = (DBTable) obj;
515:                    final String aTableName = aTable.getName();
516:                    final DatabaseModel aTableParent = aTable.getParent();
517:                    final Map aTableColumns = aTable.getColumns();
518:                    final PrimaryKey aTablePK = aTable.getPrimaryKey();
519:                    final List aTableFKs = aTable.getForeignKeys();
520:                    final List aTableIdxs = aTable.getForeignKeys();
521:
522:                    result = aTableName != null && this .name != null
523:                            && this .name.equals(aTableName)
524:                            && this .parent != null && aTableParent != null
525:                            && this .parent.equals(aTableParent);
526:
527:                    if (this .columns != null && aTableColumns != null) {
528:                        final Set objCols = aTableColumns.keySet();
529:                        final Set myCols = this .columns.keySet();
530:
531:                        // Must be identical (no subsetting), hence the pair of tests.
532:                        result &= myCols.containsAll(objCols)
533:                                && objCols.containsAll(myCols);
534:                    } else if (!(this .columns == null && aTableColumns == null)) {
535:                        result = false;
536:                    }
537:
538:                    result &= this .primaryKey != null ? this .primaryKey
539:                            .equals(aTablePK) : aTablePK == null;
540:
541:                    if (this .foreignKeys != null && aTableFKs != null) {
542:                        final Collection myFKs = this .foreignKeys.values();
543:                        // Must be identical (no subsetting), hence the pair of tests.
544:                        result &= myFKs.containsAll(aTableFKs)
545:                                && aTableFKs.containsAll(myFKs);
546:                    } else if (!(this .foreignKeys == null && aTableFKs == null)) {
547:                        result = false;
548:                    }
549:
550:                    if (this .indexes != null && aTableIdxs != null) {
551:                        final Collection myIdxs = this .indexes.values();
552:                        // Must be identical (no subsetting), hence the pair of tests.
553:                        result &= myIdxs.containsAll(aTableIdxs)
554:                                && aTableIdxs.containsAll(myIdxs);
555:                    } else if (!(this .indexes == null && aTableIdxs == null)) {
556:                        result = false;
557:                    }
558:                }
559:
560:                return result;
561:            }
562:
563:            /**
564:             * Overrides default implementation to compute hashCode value for those members used in equals()
565:             * for comparison.
566:             * 
567:             * @return hash code for this object
568:             * @see java.lang.Object#hashCode
569:             */
570:            public int hashCode() {
571:                int myHash = this .name != null ? this .name.hashCode() : 0;
572:                myHash += this .parent != null ? this .parent.hashCode() : 0;
573:                myHash += this .schema != null ? this .schema.hashCode() : 0;
574:                myHash += this .catalog != null ? this .catalog.hashCode() : 0;
575:
576:                // Include hashCodes of all column names.
577:                if (this .columns != null) {
578:                    myHash += this .columns.keySet().hashCode();
579:                }
580:
581:                if (this .primaryKey != null) {
582:                    myHash += this .primaryKey.hashCode();
583:                }
584:
585:                if (this .foreignKeys != null) {
586:                    myHash += this .foreignKeys.keySet().hashCode();
587:                }
588:
589:                if (this .indexes != null) {
590:                    myHash += this .indexes.keySet().hashCode();
591:                }
592:
593:                return myHash;
594:            }
595:
596:            /**
597:             * Clone a deep copy of DBTable.
598:             * 
599:             * @return a copy of DBTable.
600:             */
601:            public Object clone() {
602:                try {
603:                    final DBTableImpl table = (DBTableImpl) super .clone();
604:
605:                    table.columns = new HashMap();
606:                    table.deepCopyReferences(this );
607:
608:                    return table;
609:                } catch (final CloneNotSupportedException e) {
610:                    throw new InternalError(e.toString());
611:                }
612:            }
613:
614:            /**
615:             * Performs deep copy of contents of given DBTable. We deep copy (that is, the method clones all
616:             * child objects such as columns) because columns have a parent-child relationship that must be
617:             * preserved internally.
618:             * 
619:             * @param source JDBCTable providing contents to be copied.
620:             */
621:            public void copyFrom(final DBTable source) {
622:                if (source == null) {
623:                    throw new IllegalArgumentException(
624:                            "Must supply non-null ref for source");
625:                } else if (source == this ) {
626:                    return;
627:                }
628:
629:                this .name = source.getName();
630:                this .description = source.getDescription();
631:                this .schema = source.getSchema();
632:                this .catalog = source.getCatalog();
633:
634:                this .parent = source.getParent();
635:                this .deepCopyReferences(source);
636:            }
637:
638:            /*
639:             * Perform deep copy of columns. @param source JDBCTable whose columns are to be copied.
640:             */
641:            private void deepCopyReferences(final DBTable source) {
642:                if (source != null && source != this ) {
643:                    this .primaryKey = null;
644:                    final PrimaryKey srcPk = source.getPrimaryKey();
645:                    if (srcPk != null) {
646:                        this .primaryKey = new PrimaryKeyImpl(source
647:                                .getPrimaryKey());
648:                    }
649:
650:                    this .foreignKeys.clear();
651:                    Iterator iter = source.getForeignKeys().iterator();
652:                    while (iter.hasNext()) {
653:                        final ForeignKeyImpl impl = new ForeignKeyImpl(
654:                                (ForeignKey) iter.next());
655:                        impl.setParent(this );
656:                        this .foreignKeys.put(impl.getName(), impl);
657:                    }
658:
659:                    this .indexes.clear();
660:                    iter = source.getIndexes().iterator();
661:                    while (iter.hasNext()) {
662:                        final IndexImpl impl = new IndexImpl((Index) iter
663:                                .next());
664:                        impl.setParent(this );
665:                        this .indexes.put(impl.getName(), impl);
666:                    }
667:
668:                    this .columns.clear();
669:                    iter = source.getColumnList().iterator();
670:
671:                    // Must do deep copy to ensure correct parent-child relationship.
672:                    while (iter.hasNext()) {
673:                        final DBColumnImpl dbColImpl = new DBColumnImpl();
674:                        dbColImpl.copyFrom((DBColumn) iter.next());
675:                        dbColImpl.setParent(this );
676:                        this .columns.put(dbColImpl.getName(), dbColImpl);
677:                    }
678:                }
679:            }
680:
681:            /**
682:             * Adds a DBColumn instance to this table.
683:             * 
684:             * @param theColumn column to be added.
685:             * @return true if successful. false if failed.
686:             */
687:            public boolean addColumn(final DBColumn theColumn) {
688:                if (theColumn != null) {
689:                    // theColumn.setParent(this);
690:                    this .columns.put(theColumn.getName(), theColumn);
691:                    return true;
692:                }
693:
694:                return false;
695:            }
696:
697:            /**
698:             * Convenience class to create DBColumnImpl instance (with the given column name, data source
699:             * name, JDBC type, scale, precision, and nullable), and add it to this DBTableImpl instance.
700:             * 
701:             * @param columnName Column name
702:             * @param jdbcType JDBC type defined in SQL.Types
703:             * @param scale Scale
704:             * @param precision Precision
705:             * @param nullable Nullable
706:             * @return new DBColumnImpl instance
707:             */
708:            public DBColumnImpl createColumn(final String columnName,
709:                    final int jdbcType, final int scale, final int precision,
710:                    final boolean isPK, final boolean isFK,
711:                    final boolean isIndexed, final boolean nullable) {
712:                final DBColumnImpl impl = new DBColumnImpl(columnName,
713:                        jdbcType, scale, precision, isPK, isFK, isIndexed,
714:                        nullable);
715:                // impl.setParent(this);
716:                this .columns.put(columnName, impl);
717:                this .columnsInTableOrder.add(impl);
718:
719:                return impl;
720:            }
721:
722:            /**
723:             * Deletes all columns associated with this table.
724:             * 
725:             * @return true if all columns were deleted successfully, false otherwise.
726:             */
727:            public boolean deleteAllColumns() {
728:                this .columns.clear();
729:                return false;
730:            }
731:
732:            /**
733:             * Deletes DBColumn, if any, associated with the given name from this table.
734:             * 
735:             * @param columnName column name to be removed.
736:             * @return true if successful. false if failed.
737:             */
738:            public boolean deleteColumn(final String columnName) {
739:                if (columnName != null && columnName.trim().length() != 0) {
740:                    return this .columns.remove(columnName) != null;
741:                }
742:                return false;
743:            }
744:
745:            /**
746:             * Get editable
747:             * 
748:             * @return true/false
749:             */
750:            public boolean isEditable() {
751:                return this .editable;
752:            }
753:
754:            /**
755:             * @return
756:             */
757:            public boolean isSelected() {
758:                return this .selected;
759:            }
760:
761:            /**
762:             * @param select
763:             */
764:            public void setSelected(final boolean select) {
765:                this .selected = select;
766:            }
767:
768:            /**
769:             * Set editable
770:             * 
771:             * @param edit - editable
772:             */
773:            public void setEditable(final boolean edit) {
774:                this .editable = edit;
775:            }
776:
777:            /**
778:             * Gets the DBColumn, if any, associated with the given name
779:             * 
780:             * @param columnName column name
781:             * @return DBColumn associated with columnName, or null if none exists
782:             */
783:            public DBColumn getColumn(final String columnName) {
784:                return (DBColumn) this .columns.get(columnName);
785:            }
786:
787:            /**
788:             * Clones contents of the given Map to this table's internal column map, overwriting any
789:             * previous mappings.
790:             * 
791:             * @param theColumns Map of columns to be substituted
792:             * @return true if successful. false if failed.
793:             */
794:            public boolean setAllColumns(final Map theColumns) {
795:                this .columns.clear();
796:                if (theColumns != null) {
797:                    this .columns.putAll(theColumns);
798:                }
799:                return true;
800:            }
801:
802:            /**
803:             * Sets description text for this instance.
804:             * 
805:             * @param newDesc new descriptive text
806:             */
807:            public void setDescription(final String newDesc) {
808:                this .description = newDesc;
809:            }
810:
811:            /**
812:             * Sets parent DatabaseModel to the given reference.
813:             * 
814:             * @param newParent new DatabaseModel parent
815:             */
816:            public void setParent(final DatabaseModelImpl newParent) {
817:                this .parent = newParent;
818:            }
819:
820:            /**
821:             * Gets Java name for this table.
822:             * 
823:             * @return normalized Java name for this table
824:             */
825:            public String getJavaName() {
826:                return this .javaName != null ? this .javaName : this .name;
827:            }
828:
829:            /**
830:             * Sets Java name for this table.
831:             * 
832:             * @param newName new normalized Java name for this table; null if plain name is to be used.
833:             */
834:            public void setJavaName(final String newName) {
835:                this .javaName = newName;
836:            }
837:
838:            private void initJDBCTypeMap() {
839:                this .jdbcTypeMap
840:                        .put("array", new Integer(java.sql.Types.ARRAY));
841:                this .jdbcTypeMap.put("bigint", new Integer(
842:                        java.sql.Types.BIGINT));
843:                this .jdbcTypeMap.put("binary", new Integer(
844:                        java.sql.Types.BINARY));
845:                this .jdbcTypeMap.put("bit", new Integer(java.sql.Types.BIT));
846:                this .jdbcTypeMap.put("blob", new Integer(java.sql.Types.BLOB));
847:                this .jdbcTypeMap.put("char", new Integer(java.sql.Types.CHAR));
848:                this .jdbcTypeMap.put("clob", new Integer(java.sql.Types.CLOB));
849:                this .jdbcTypeMap.put("date", new Integer(java.sql.Types.DATE));
850:                this .jdbcTypeMap.put("decimal", new Integer(
851:                        java.sql.Types.DECIMAL));
852:                this .jdbcTypeMap.put("distinct", new Integer(
853:                        java.sql.Types.DISTINCT));
854:                this .jdbcTypeMap.put("double", new Integer(
855:                        java.sql.Types.DOUBLE));
856:                this .jdbcTypeMap
857:                        .put("float", new Integer(java.sql.Types.FLOAT));
858:                this .jdbcTypeMap.put("integer", new Integer(
859:                        java.sql.Types.INTEGER));
860:                this .jdbcTypeMap.put("longvarbinary", new Integer(
861:                        java.sql.Types.LONGVARBINARY));
862:                this .jdbcTypeMap.put("longvarchar", new Integer(
863:                        java.sql.Types.LONGVARCHAR));
864:                this .jdbcTypeMap.put("numeric", new Integer(
865:                        java.sql.Types.NUMERIC));
866:                this .jdbcTypeMap.put("real", new Integer(java.sql.Types.REAL));
867:                this .jdbcTypeMap.put("smallint", new Integer(
868:                        java.sql.Types.SMALLINT));
869:                this .jdbcTypeMap.put("time", new Integer(java.sql.Types.TIME));
870:                this .jdbcTypeMap.put("timestamp", new Integer(
871:                        java.sql.Types.TIMESTAMP));
872:                this .jdbcTypeMap.put("tinyint", new Integer(
873:                        java.sql.Types.TINYINT));
874:                this .jdbcTypeMap.put("varchar", new Integer(
875:                        java.sql.Types.VARCHAR));
876:                this .jdbcTypeMap.put("varbinary", new Integer(
877:                        java.sql.Types.VARBINARY));
878:
879:                this .sqlTypeMap.put(new Integer(java.sql.Types.ARRAY), "array");
880:                this .sqlTypeMap.put(new Integer(java.sql.Types.BIGINT),
881:                        "bigint");
882:                this .sqlTypeMap.put(new Integer(java.sql.Types.BINARY),
883:                        "binary");
884:                this .sqlTypeMap.put(new Integer(java.sql.Types.BIT), "bit");
885:                this .sqlTypeMap.put(new Integer(java.sql.Types.BLOB), "blob");
886:                this .sqlTypeMap.put(new Integer(java.sql.Types.CHAR), "char");
887:                this .sqlTypeMap.put(new Integer(java.sql.Types.CLOB), "clob");
888:                this .sqlTypeMap.put(new Integer(java.sql.Types.DATE), "date");
889:                this .sqlTypeMap.put(new Integer(java.sql.Types.DECIMAL),
890:                        "decimal");
891:                this .sqlTypeMap.put(new Integer(java.sql.Types.DISTINCT),
892:                        "distinct");
893:                this .sqlTypeMap.put(new Integer(java.sql.Types.DOUBLE),
894:                        "double");
895:                this .sqlTypeMap.put(new Integer(java.sql.Types.FLOAT), "float");
896:                this .sqlTypeMap.put(new Integer(java.sql.Types.INTEGER),
897:                        "integer");
898:                this .sqlTypeMap.put(new Integer(java.sql.Types.LONGVARBINARY),
899:                        "longvarbinary");
900:                this .sqlTypeMap.put(new Integer(java.sql.Types.LONGVARCHAR),
901:                        "longvarchar");
902:                this .sqlTypeMap.put(new Integer(java.sql.Types.NUMERIC),
903:                        "numeric");
904:                this .sqlTypeMap.put(new Integer(java.sql.Types.REAL), "real");
905:                this .sqlTypeMap.put(new Integer(java.sql.Types.SMALLINT),
906:                        "smallint");
907:                this .sqlTypeMap.put(new Integer(java.sql.Types.TIME), "time");
908:                this .sqlTypeMap.put(new Integer(java.sql.Types.TIMESTAMP),
909:                        "timestamp");
910:                this .sqlTypeMap.put(new Integer(java.sql.Types.TINYINT),
911:                        "tinyint");
912:                this .sqlTypeMap.put(new Integer(java.sql.Types.VARCHAR),
913:                        "varchar");
914:                this .sqlTypeMap.put(new Integer(java.sql.Types.VARBINARY),
915:                        "varbinary");
916:            }
917:
918:            /**
919:             * Gets the JDBC Type for a given oracle8/oracle9 type
920:             * 
921:             * @param dbType for which jdbctype is returned
922:             * @return java.sql.Types.* for given string jdbcType
923:             */
924:            public int getJDBCType(final String dbType) {
925:                final Integer value = (Integer) this .jdbcTypeMap.get(dbType);
926:                if (value != null) {
927:                    return value.intValue();
928:                }
929:                return Integer.MIN_VALUE;
930:            }
931:
932:            /**
933:             * Gets the SQLType
934:             * 
935:             * @param type for which sql type is returned
936:             * @return String for given jdbc type
937:             */
938:            public String getSQLType(final int type) {
939:                final Integer intType = new Integer(type);
940:                return (String) this .sqlTypeMap.get(intType);
941:            }
942:
943:            static class StringComparator implements  Comparator {
944:                public int compare(final Object o1, final Object o2) {
945:                    if (o1 instanceof  String && o2 instanceof  String) {
946:                        return ((String) o1).compareTo((String) o2);
947:                    } else {
948:                        final ResourceBundle cMessages = NbBundle
949:                                .getBundle(DBTableImpl.class);
950:                        throw new ClassCastException(cMessages
951:                                .getString("ERROR_STRING_COMPARATOR")
952:                                + "ERROR_STRING_COMPARATOR");// NO i18n
953:                    }
954:                }
955:            }
956:
957:            public boolean isSelectedforAnOperation() {
958:                // TODO Auto-generated method stub
959:                return false;
960:            }
961:
962:            public void setSelectedforAllOperations(final boolean setAll) {
963:                // TODO Auto-generated method stub
964:
965:            }
966:
967:        }
w_w_w__._j__a_va2_s_.___c_o__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.