Source Code Cross Referenced for SchemaElement.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.io.*;
045:        import java.text.MessageFormat;
046:        import java.util.*;
047:
048:        import org.netbeans.modules.dbschema.util.*;
049:
050:        import org.netbeans.modules.dbschema.migration.archiver.*;
051:
052:        /** Describes an entire database schema.
053:         */
054:        public class SchemaElement extends DBElement {
055:            /** Status when the schema element is not yet prepared. */
056:            public static final int STATUS_NOT = 0;
057:
058:            /** Status when the schema element contains unrecoverable errors. */
059:            public static final int STATUS_ERROR = 1;
060:
061:            /** Status when the schema element contains minor errors. */
062:            public static final int STATUS_PARTIAL = 2;
063:
064:            /** Status when the schema element has been parsed and is error-free. */
065:            public static final int STATUS_OK = 3;
066:
067:            /** Version of the database schema API. */
068:            public static final int CURRENT_VERSION_NO = 2;
069:            private int versionNo;
070:
071:            /** Creates a new schema element represented in memory.
072:             */
073:            public SchemaElement() {
074:                this (new Memory());
075:            }
076:
077:            /** Creates a new schema element.
078:             * @param impl the pluggable implementation
079:             */
080:            public SchemaElement(Impl impl) {
081:                super (impl);
082:            }
083:
084:            /** Returns the implementation for the schema.
085:             * @return implementation for the schema
086:             */
087:            final Impl getSchemaImpl() {
088:                return (Impl) getElementImpl();
089:            }
090:
091:            /** Returns if the schema is compatible with current API version.
092:             * @return true if schema is compatible; false otherwise
093:             */
094:            public boolean isCompatibleVersion() {
095:                return (getVersionNo() == CURRENT_VERSION_NO);
096:            }
097:
098:            /** Getter for property versionNo.
099:             * @return Value of property versionNo.
100:             */
101:            public int getVersionNo() {
102:                return versionNo;
103:            }
104:
105:            /** Setter for property versionNo.
106:             * @param versionNo New value of property versionNo.
107:             */
108:            public void setVersionNo(int versionNo) {
109:                this .versionNo = versionNo;
110:            }
111:
112:            /** Cache for read schemas. */
113:            protected static Map schemaCache = new HashMap();
114:
115:            /** Last used schema. */
116:            private static SchemaElement lastSchema;
117:
118:            /** Returns the last used schema.
119:             * @return the last used schema
120:             */
121:            protected static SchemaElement getLastSchema() {
122:                return lastSchema;
123:            }
124:
125:            /** Sets the last used schema.
126:             * @param last the last used schema
127:             */
128:            protected static void setLastSchema(SchemaElement last) {
129:                lastSchema = last;
130:            }
131:
132:            /** Removes the specified schema from cache.
133:             * @param name the schema to remove
134:             */
135:            public static void removeFromCache(String name) {
136:                synchronized (schemaCache) {
137:                    if (getLastSchema() != null)
138:                        if (getLastSchema().getName().getFullName()
139:                                .equals(name))
140:                            setLastSchema(null);
141:
142:                    schemaCache.remove(name);
143:                }
144:            }
145:
146:            /** Adds the specified schema element to cache.
147:             * @param schema the schema element to add
148:             */
149:            public static void addToCache(SchemaElement schema) {
150:                synchronized (schemaCache) {
151:                    schemaCache.put(schema.getName().getFullName(), schema);
152:                    SchemaElement.setLastSchema(schema);
153:                }
154:            }
155:
156:            /** Returns the SchemaElement object associated with the schema with 
157:             * the given string name and object.  The second argument is meant to 
158:             * help define the context for loading of the schema and can be a 
159:             * FileObject[] or FileObject for use in the IDE or a ClassLoader for 
160:             * use at runtime.  Note that if if FileObject[] is used, the first match 
161:             * is returned if it's not already in the cache.  It might be extended 
162:             * later to accept a Project as well.  Any other non-null value for the 
163:             * second argument will result in an UnsupportedOperationException.
164:             * @param name the schema name
165:             * @param obj the schema context
166:             * @return the SchemaElement object for the given schema name
167:             */
168:            public static SchemaElement forName(String name, Object obj) {
169:                if (IDEUtil.isIDERunning())
170:                    return SchemaElementUtil.forName(name, obj);
171:
172:                if (obj == null)
173:                    return forNameInternal(name, SchemaElement.class
174:                            .getClassLoader());
175:                if (obj instanceof  ClassLoader)
176:                    return forNameInternal(name, (ClassLoader) obj);
177:
178:                // if we got to this point the second object is not null, the 
179:                // IDE is not running, and the type of object is not one we can
180:                // handle
181:                throw new UnsupportedOperationException("Cannot lookup schema "
182:                        + name + " in context of type " + obj.getClass()
183:                        + " expected ClassLoader or null.");
184:            }
185:
186:            /** Returns the SchemaElement object associated with the schema with the given string name, loaded by the given classloader.
187:             * @param name the schema name
188:             * @param cl the schema classloader
189:             * @return the SchemaElement object for the given schema name
190:             */
191:            private static SchemaElement forNameInternal(String name,
192:                    ClassLoader cl) {
193:                SchemaElement se = getLastSchema();
194:
195:                if (se != null && se.getName().getFullName().equals(name))
196:                    return se;
197:                else
198:                    synchronized (schemaCache) {
199:                        se = (SchemaElement) schemaCache.get(name);
200:                        if (se != null)
201:                            return se;
202:
203:                        InputStream is = cl.getResourceAsStream(NameUtil
204:                                .getSchemaResourceName(name));
205:
206:                        if (is != null)
207:                            try {
208:                                ObjectInput i = new XMLInputStream(is);
209:                                se = (SchemaElement) i.readObject();
210:                                if (!se.isCompatibleVersion()) {
211:                                    String message = MessageFormat
212:                                            .format(
213:                                                    ResourceBundle
214:                                                            .getBundle(
215:                                                                    "org.netbeans.modules.dbschema.resources.Bundle")
216:                                                            .getString(
217:                                                                    "PreviousVersion"),
218:                                                    new String[] { name }); //NOI18N
219:                                    System.out.println(message);
220:                                }
221:                                i.close();
222:
223:                                se.setName(DBIdentifier.create(name));
224:
225:                                SchemaElement.addToCache(se);
226:
227:                                // MBO: now set the declaring schema in TableElement(transient field)
228:                                TableElement tables[] = se.getTables();
229:                                int size = (tables != null) ? tables.length : 0;
230:                                for (int j = 0; j < size; j++)
231:                                    tables[j].setDeclaringSchema(se);
232:                            } catch (Exception exc) {
233:                                if (Boolean
234:                                        .getBoolean("netbeans.debug.exceptions")) // NOI18N
235:                                    System.out
236:                                            .println(ResourceBundle
237:                                                    .getBundle(
238:                                                            "org.netbeans.modules.dbschema.resources.Bundle")
239:                                                    .getString("SchemaNotFound")); //NOI18N
240:                            }
241:                        else if (Boolean
242:                                .getBoolean("netbeans.debug.exceptions")) // NOI18N
243:                            System.out
244:                                    .println(ResourceBundle
245:                                            .getBundle(
246:                                                    "org.netbeans.modules.dbschema.resources.Bundle")
247:                                            .getString("SchemaNotFound")); //NOI18N
248:
249:                        return se;
250:                    }
251:            }
252:
253:            /** Returns the SchemaElement object associated with the schema with the given string name.
254:             * @param name the schema name
255:             * @return the SchemaElement object for the given schema name
256:             */
257:            public static SchemaElement forName(String name) {
258:                return forName(name, null);
259:            }
260:
261:            /** Gets the parsing status of the element.
262:             * This is a non-blocking operation.
263:             * @return one of {@link #STATUS_NOT}, {@link #STATUS_ERROR}, {@link
264:             * #STATUS_PARTIAL}, or {@link #STATUS_OK}
265:             */
266:            public int getStatus() {
267:                return getSchemaImpl().getStatus();
268:            }
269:
270:            /** Sets the schema name of this schema snapshot.
271:             * @param id the schema name, or <code>null</code>
272:             * @exception DBException if the operation cannot proceed
273:             */
274:            public void setSchema(DBIdentifier schema) throws DBException {
275:                getSchemaImpl().setSchema(schema);
276:            }
277:
278:            /** Gets the schema name of this schema snapshot.
279:             * @return the schema name, or <code>null</code> if this snapshot does not
280:             * have a schema name
281:             */
282:            public DBIdentifier getSchema() {
283:                return getSchemaImpl().getSchema();
284:            }
285:
286:            /** Sets the catalog name of this schema snapshot.
287:             * @param id the catalog name, or <code>null</code>
288:             * @exception DBException if the operation cannot proceed
289:             */
290:            public void setCatalog(DBIdentifier catalog) throws DBException {
291:                getSchemaImpl().setCatalog(catalog);
292:            }
293:
294:            /** Gets the catalog name of this schema snapshot.
295:             * @return the catalog name, or <code>null</code> if this snapshot does
296:             * not have a catalog name
297:             */
298:            public DBIdentifier getCatalog() {
299:                return getSchemaImpl().getCatalog();
300:            }
301:
302:            /** Adds a new table to the schema snapshot.
303:             * @param el the table to add
304:             * @throws DBException if impossible
305:             */
306:            public void addTable(TableElement el) throws DBException {
307:                addTables(new TableElement[] { el });
308:            }
309:
310:            /** Adds some new tables to the schema snapshot.
311:             * @param els the tables to add
312:             * @throws DBException if impossible
313:             */
314:            public void addTables(final TableElement[] els) throws DBException {
315:                for (int i = 0; i < els.length; i++) {
316:                    if (getTable(els[i].getName()) != null)
317:                        throwAddException("FMT_EXC_AddTable", els[i]); //NOI18N
318:                    if (els[i].getDeclaringSchema() == null)
319:                        els[i].setDeclaringSchema(this );
320:                }
321:
322:                getSchemaImpl().changeTables(els, Impl.ADD);
323:            }
324:
325:            /** Removes a table from the schema snapshot.
326:             * @param el the table to remove
327:             * @throws DBException if impossible
328:             */
329:            public void removeTable(TableElement el) throws DBException {
330:                removeTables(new TableElement[] { el });
331:            }
332:
333:            /** Removes some tables from the schema snapshot.
334:             *  @param els the columns to remove
335:             * @throws DBException if impossible
336:             */
337:            public void removeTables(final TableElement[] els)
338:                    throws DBException {
339:                getSchemaImpl().changeTables(els, Impl.REMOVE);
340:            }
341:
342:            /** Sets the tables for this schema snapshot.
343:             * Previous tables are removed.
344:             * @param els the new tables
345:             * @throws DBException if impossible
346:             */
347:            public void setTables(TableElement[] els) throws DBException {
348:                if (els == null)
349:                    throw new NullPointerException(ResourceBundle.getBundle(
350:                            "org.netbeans.modules.dbschema.resources.Bundle")
351:                            .getString("NullTables")); //NOI18N
352:
353:                getSchemaImpl().changeTables(els, Impl.SET);
354:            }
355:
356:            /** Gets all tables in this schema snapshot.
357:             * @return the tables
358:             */
359:            public TableElement[] getTables() {
360:                return getSchemaImpl().getTables();
361:            }
362:
363:            /** Finds a table by name.
364:             * @param name the name of the table for which to look
365:             * @return the element or <code>null</code> if not found
366:             */
367:            public TableElement getTable(DBIdentifier name) {
368:                return getSchemaImpl().getTable(name);
369:            }
370:
371:            /** This method just throws localized exception. It is used during
372:             * adding class element, which already exists in source.
373:             * @param formatKey The message format key to localized bundle.
374:             * @param element The element which can't be added
375:             * @exception DBException is alway thrown from this method.
376:             */
377:            private void throwAddException(String formatKey,
378:                    TableElement element) throws DBException {
379:                //MessageFormat format = new MessageFormat(ElementFormat.bundle.getString(formatKey));
380:                String msg = /*format.format(new Object[] { */element
381:                        .getName().getName();// });
382:                throw new DBException(msg);
383:            }
384:
385:            /** Getter for property url.
386:             * @return Value of property url.
387:             */
388:            public String getUrl() {
389:                return getSchemaImpl().getUrl();
390:            }
391:
392:            /** Setter for property url.
393:             * @param url New value of property url.
394:             */
395:            public void setUrl(String url) throws DBException {
396:                getSchemaImpl().setUrl(url);
397:            }
398:
399:            /** Getter for property username.
400:             * @return Value of property username.
401:             */
402:            public String getUsername() {
403:                return getSchemaImpl().getUsername();
404:            }
405:
406:            /** Setter for property username.
407:             * @param username New value of property username.
408:             */
409:            public void setUsername(String username) throws DBException {
410:                getSchemaImpl().setUsername(username);
411:            }
412:
413:            /** Getter for property driver.
414:             * @return Value of property driver.
415:             */
416:            public String getDriver() {
417:                return getSchemaImpl().getDriver();
418:            }
419:
420:            /** Setter for property driver.
421:             * @param driver New value of property driver.
422:             */
423:            public void setDriver(String driver) {
424:                getSchemaImpl().setDriver(driver);
425:            }
426:
427:            /** Getter for property databaseProductName.
428:             * @return Value of property databaseProductName.
429:             */
430:            public String getDatabaseProductName() {
431:                return getSchemaImpl().getDatabaseProductName();
432:            }
433:
434:            /** Setter for property databaseProductName.
435:             *  @param databaseProductName New value of property databaseProductName.
436:             */
437:            public void setDatabaseProductName(String databaseProductName)
438:                    throws DBException {
439:                getSchemaImpl().setDatabaseProductName(databaseProductName);
440:            }
441:
442:            /** Getter for property databaseProductVersion.
443:             * @return Value of property databaseProductVersion.
444:             */
445:            public String getDatabaseProductVersion() {
446:                return getSchemaImpl().getDatabaseProductVersion();
447:            }
448:
449:            /** Setter for property databaseProductVersion.
450:             * @param databaseProductVersion New value of property databaseProductVersion.
451:             */
452:            public void setDatabaseProductVersion(String databaseProductVersion)
453:                    throws DBException {
454:                getSchemaImpl().setDatabaseProductVersion(
455:                        databaseProductVersion);
456:            }
457:
458:            /** Getter for property driverName.
459:             * @return Value of property driverName.
460:             */
461:            public String getDriverName() {
462:                return getSchemaImpl().getDriverName();
463:            }
464:
465:            /** Setter for property driverName.
466:             * @param driverName New value of property driverName.
467:             */
468:            public void setDriverName(String driverName) throws DBException {
469:                getSchemaImpl().setDriverName(driverName);
470:            }
471:
472:            /** Getter for property driverVersion.
473:             * @return Value of property driverVersion.
474:             */
475:            public String getDriverVersion() {
476:                return getSchemaImpl().getDriverVersion();
477:            }
478:
479:            /** Setter for property driverVersion.
480:             * @param driverVersion New value of property driverVersion.
481:             */
482:            public void setDriverVersion(String driverVersion)
483:                    throws DBException {
484:                getSchemaImpl().setDriverVersion(driverVersion);
485:            }
486:
487:            /** Saves the current schema to an XML file.
488:             * @param filename the system-dependent filename
489:             */
490:            public void save(String filename) {
491:                setVersionNo(CURRENT_VERSION_NO);
492:
493:                try {
494:                    OutputStream s = new FileOutputStream(filename);
495:                    ObjectOutput o = new XMLOutputStream(s);
496:                    o.writeObject(this );
497:                    o.close();
498:                } catch (Exception e) {
499:                    e.printStackTrace();
500:                }
501:            }
502:
503:            /** Saves the current schema to an XML file.
504:             * @param s the output stream
505:             */
506:            public void save(OutputStream s) {
507:                setVersionNo(CURRENT_VERSION_NO);
508:
509:                try {
510:                    ObjectOutput o = new XMLOutputStream(s);
511:                    o.writeObject(this );
512:                    o.close();
513:                } catch (Exception e) {
514:                    e.printStackTrace();
515:                }
516:            }
517:
518:            /** Pluggable behaviour for schema elements.
519:             * @see SchemaElement
520:             */
521:            public static interface Impl extends DBElement.Impl {
522:                /** Gets the parsing status of the element.
523:                 * This is a non-blocking operation.
524:                 * @return one of {@link #STATUS_NOT}, {@link #STATUS_ERROR},
525:                 * {@link #STATUS_PARTIAL}, or {@link #STATUS_OK}
526:                 */
527:                public int getStatus();
528:
529:                /** Sets the schema name of this schema snapshot.
530:                 * @param id the schema name, or <code>null</code>
531:                 * @exception DBException if the operation cannot proceed
532:                 */
533:                public void setSchema(DBIdentifier id) throws DBException;
534:
535:                /** Get the schema name of this schema snapshot.
536:                 * @return the schema name, or <code>null</code> if this snapshot does
537:                 * not have a schema name
538:                 */
539:                public DBIdentifier getSchema();
540:
541:                /** Sets the catalog name of this schema snapshot.
542:                 * @param id the catalog name, or <code>null</code>
543:                 * @exception DBException if the operation cannot proceed
544:                 */
545:                public void setCatalog(DBIdentifier id) throws DBException;
546:
547:                /** Gets the catalog name of this schema snapshot.
548:                 * @return the catalog name, or <code>null</code> if this snapshot does
549:                 * not have a catalog name
550:                 */
551:                public DBIdentifier getCatalog();
552:
553:                /** Change the set of tables.
554:                 * @param elems the tables to change
555:                 * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
556:                 * @exception DBException if the action cannot be handled
557:                 */
558:                public void changeTables(TableElement[] elems, int action)
559:                        throws DBException;
560:
561:                /** Gets all tables.
562:                 * @return the tables
563:                 */
564:                public TableElement[] getTables();
565:
566:                /** Finds a table by name.
567:                 * @param name the name for which to look
568:                 * @return the table, or <code>null</code> if it does not exist
569:                 */
570:                public TableElement getTable(DBIdentifier name);
571:
572:                /** Getter for property url.
573:                 * @return Value of property url.
574:                 */
575:                public String getUrl();
576:
577:                /** Setter for property url.
578:                 * @param url New value of property url.
579:                 */
580:                public void setUrl(String url) throws DBException;
581:
582:                /** Getter for property username.
583:                 * @return Value of property username.
584:                 */
585:                public String getUsername();
586:
587:                /** Setter for property username.
588:                 * @param username New value of property username.
589:                 */
590:                public void setUsername(String username) throws DBException;
591:
592:                /** Getter for property driver.
593:                 * @return Value of property driver.
594:                 */
595:                public String getDriver();
596:
597:                /** Setter for property driver.
598:                 * @param driver New value of property driver.
599:                 */
600:                public void setDriver(String driver);
601:
602:                /** Getter for property databaseProductName.
603:                 * @return Value of property databaseProductName.
604:                 */
605:                public String getDatabaseProductName();
606:
607:                /** Setter for property databaseProductName.
608:                 * @param databaseProductName New value of property databaseProductName.
609:                 */
610:                public void setDatabaseProductName(String databaseProductName)
611:                        throws DBException;
612:
613:                /** Getter for property databaseProductVersion.
614:                 * @return Value of property databaseProductVersion.
615:                 */
616:                public String getDatabaseProductVersion();
617:
618:                /** Setter for property databaseProductVersion.
619:                 * @param databaseProductVersion New value of property databaseProductVersion.
620:                 */
621:                public void setDatabaseProductVersion(
622:                        String databaseProductVersion) throws DBException;
623:
624:                /** Getter for property driverName.
625:                 * @return Value of property driverName.
626:                 */
627:                public String getDriverName();
628:
629:                /** Setter for property driverName.
630:                 * @param driverName New value of property driverName.
631:                 */
632:                public void setDriverName(String driverName) throws DBException;
633:
634:                /** Getter for property driverVersion.
635:                 * @return Value of property driverVersion.
636:                 */
637:                public String getDriverVersion();
638:
639:                /** Setter for property driverVersion.
640:                 * @param driverVersion New value of property driverVersion.
641:                 */
642:                public void setDriverVersion(String driverVersion)
643:                        throws DBException;
644:            }
645:
646:            /** Memory based implementation of the element factory.
647:             */
648:            static final class Memory extends DBElement.Memory implements  Impl {
649:                /** collection of tables */
650:                private DBMemoryCollection.Table tables;
651:
652:                private DBIdentifier _catalog;
653:                private DBIdentifier _schema;
654:                private int _status;
655:                private String _url;
656:                private String _username;
657:                private String _driver;
658:                private String _databaseProductName;
659:                private String _databaseProductVersion;
660:                private String _driverName;
661:                private String _driverVersion;
662:
663:                /** Default constructor
664:                 */
665:                public Memory() {
666:                    super ();
667:                }
668:
669:                /** Copy constructor.
670:                 * @param el element to copy from
671:                 */
672:                public Memory(SchemaElement el) {
673:                    super (el);
674:                    _catalog = el.getCatalog();
675:                    _schema = el.getSchema();
676:                    _status = el.getStatus();
677:                    _url = el.getUrl();
678:                    _username = el.getUsername();
679:                    _driver = el.getDriver();
680:                    _databaseProductName = el.getDatabaseProductName();
681:                    _databaseProductVersion = el.getDatabaseProductVersion();
682:                    _driverName = el.getDriverName();
683:                    _driverVersion = el.getDriverVersion();
684:                }
685:
686:                /** Late initialization of initialization of copy elements.
687:                 */
688:                public void copyFrom(SchemaElement copyFrom) throws DBException {
689:                    changeTables(copyFrom.getTables(), SET);
690:                }
691:
692:                /** Changes set of elements.
693:                 * @param elems elements to change
694:                 * @exception SourceException if the action cannot be handled
695:                 */
696:                public synchronized void changeTables(TableElement[] elems,
697:                        int action) throws DBException {
698:                    initTables();
699:                    tables.change(elems, action);
700:                }
701:
702:                /** Gets all tables.
703:                 * @return the tables
704:                 */
705:                public synchronized TableElement[] getTables() {
706:                    initTables();
707:                    return (TableElement[]) tables.getElements();
708:                }
709:
710:                /** Finds a table with given name.
711:                 * @param name the name of table for which to look
712:                 * @return the element or null if table with such name does not exist
713:                 */
714:                public synchronized TableElement getTable(DBIdentifier name) {
715:                    initTables();
716:                    return (TableElement) tables.getElement(name);
717:                }
718:
719:                /** Initializes the collection of tables.
720:                 */
721:                void initTables() {
722:                    if (tables == null)
723:                        tables = new DBMemoryCollection.Table(this );
724:                }
725:
726:                /** Getter for the associated schema
727:                 * @return the schema element for this impl
728:                 */
729:                final SchemaElement getSchemaElement() {
730:                    return (SchemaElement) _element;
731:                }
732:
733:                /** Gets the parsing status of the element.
734:                 * This is a non-blocking operation.
735:                 * @return one of {@link #STATUS_NOT}, {@link #STATUS_ERROR}, {@link
736:                 * #STATUS_PARTIAL}, or {@link #STATUS_OK}
737:                 */
738:                public int getStatus() {
739:                    return _status;
740:                }
741:
742:                public void setSchema(DBIdentifier id) throws DBException {
743:                    DBIdentifier old = _schema;
744:
745:                    _schema = id;
746:                    firePropertyChange(PROP_SCHEMA, old, id);
747:                }
748:
749:                public DBIdentifier getSchema() {
750:                    if (_schema == null) // lazy initialization !?
751:                        _schema = DBIdentifier.create(""); //NOI18N
752:
753:                    return _schema;
754:                }
755:
756:                public void setCatalog(DBIdentifier id) throws DBException {
757:                    DBIdentifier old = _catalog;
758:
759:                    _catalog = id;
760:                    firePropertyChange(PROP_CATALOG, old, id);
761:                }
762:
763:                public DBIdentifier getCatalog() {
764:                    if (_catalog == null) // lazy initialization !?
765:                        _catalog = DBIdentifier.create(""); //NOI18N
766:
767:                    return _catalog;
768:                }
769:
770:                public String getUrl() {
771:                    return _url;
772:                }
773:
774:                public void setUrl(String url) throws DBException {
775:                    _url = url;
776:                }
777:
778:                public String getUsername() {
779:                    return _username;
780:                }
781:
782:                public void setUsername(String username) throws DBException {
783:                    _username = username;
784:                }
785:
786:                public String getDriver() {
787:                    return _driverName;
788:                }
789:
790:                public void setDriver(String driver) {
791:                    _driver = driver;
792:                }
793:
794:                public String getDatabaseProductName() {
795:                    return _databaseProductName;
796:                }
797:
798:                public void setDatabaseProductName(String databaseProductName)
799:                        throws DBException {
800:                    _databaseProductName = databaseProductName;
801:                }
802:
803:                public String getDatabaseProductVersion() {
804:                    return _databaseProductVersion;
805:                }
806:
807:                public void setDatabaseProductVersion(
808:                        String databaseProductVersion) throws DBException {
809:                    _databaseProductVersion = databaseProductVersion;
810:                }
811:
812:                public String getDriverName() {
813:                    return _driverName;
814:                }
815:
816:                public void setDriverName(String driverName) throws DBException {
817:                    _driverName = driverName;
818:                }
819:
820:                public String getDriverVersion() {
821:                    return _driverVersion;
822:                }
823:
824:                public void setDriverVersion(String driverVersion)
825:                        throws DBException {
826:                    _driverVersion = driverVersion;
827:                }
828:            }
829:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.