KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > dbmetatreemodel > DBMetaRootNode


1 package org.apache.ojb.tools.mapping.reversedb2.dbmetatreemodel;
2
3
4
5 /* Copyright 2002-2005 The Apache Software Foundation
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 /**
21  * This is the root node for the DatabaseMetaTreeModel. Its children are
22  * DBMetaCatalogNode objects.
23  *
24  * @author <a HREF="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
25  * @version $Id: DBMetaRootNode.java,v 1.1.2.1 2005/12/21 22:32:42 tomdz Exp $
26  */

27 public class DBMetaRootNode extends ReverseDbTreeNode
28     implements java.io.Serializable JavaDoc
29 {
30     static final long serialVersionUID = 5002948511759554049L; /** Creates a new instance of DBMetaRootNode
31      * @param pdbMeta DatabaseMetaData implementation where this node gets its data from.
32      * @param pdbMetaTreeModel The TreeModel this node is associated to.
33      */

34     public DBMetaRootNode(java.sql.DatabaseMetaData JavaDoc pdbMeta,
35                           DatabaseMetaDataTreeModel pdbMetaTreeModel)
36     {
37         super(pdbMeta, pdbMetaTreeModel, null);
38     }
39
40     /**
41      * @see ReverseDbTreeNode#isLeaf()
42      */

43     public boolean isLeaf()
44     {
45         return false;
46     }
47     
48     /**
49      * @see ReverseDbTreeNode#getAllowsChildren()
50      */

51     public boolean getAllowsChildren()
52     {
53         return false;
54     }
55     
56     /**
57      * @see Object#toString()
58      */

59     public String JavaDoc toString()
60     {
61         return "Root";
62     }
63     
64     public Class JavaDoc getPropertyEditorClass()
65     {
66         return null;
67     }
68     
69     /**
70      * Loads the catalogs of this database.
71      */

72     protected boolean _load ()
73     {
74         java.sql.ResultSet JavaDoc rs = null;
75         try
76         {
77             // This synchronization is necessary for Oracle JDBC drivers 8.1.7, 9.0.1, 9.2.0.1
78
// The documentation says synchronization is done within the driver, but they
79
// must have overlooked something. Without the lock we'd get mysterious error
80
// messages.
81
synchronized(getDbMeta())
82             {
83                 getDbMetaTreeModel().setStatusBarMessage("Started reading catalogs");
84                 rs = getDbMeta().getCatalogs();
85                 final java.util.ArrayList JavaDoc alNew = new java.util.ArrayList JavaDoc();
86                 int count = 0;
87                 while (rs.next())
88                 {
89                     getDbMetaTreeModel().setStatusBarMessage("Reading catalog " + rs.getString("TABLE_CAT"));
90                     alNew.add(new DBMetaCatalogNode(getDbMeta(), getDbMetaTreeModel(),
91                             DBMetaRootNode.this, rs.getString("TABLE_CAT")));
92                     count++;
93                 }
94                 if (count == 0)
95                     alNew.add(new DBMetaCatalogNode(getDbMeta(), getDbMetaTreeModel(),
96                             DBMetaRootNode.this, null));
97                 alChildren = alNew;
98                 javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc()
99                 {
100                     public void run()
101                     {
102                         getDbMetaTreeModel().nodeStructureChanged(DBMetaRootNode.this);
103                     }
104                 });
105                 rs.close();
106             }
107         }
108         catch (java.sql.SQLException JavaDoc sqlEx)
109         {
110             getDbMetaTreeModel().reportSqlError("Error retrieving catalogs", sqlEx);
111             try
112             {
113                 if (rs != null) rs.close ();
114             }
115             catch (java.sql.SQLException JavaDoc sqlEx2)
116             {
117                 this.getDbMetaTreeModel().reportSqlError("Error retrieving catalogs", sqlEx2);
118             }
119             return false;
120         }
121         return true;
122     }
123 }
124
Popular Tags