001: package org.apache.ojb.tools.mapping.reversedb2.dbmetatreemodel;
002:
003: /* Copyright 2002-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * This is the root node for the DatabaseMetaTreeModel. Its children are
020: * DBMetaCatalogNode objects.
021: *
022: * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
023: * @version $Id: DBMetaRootNode.java,v 1.1.2.1 2005/12/21 22:32:42 tomdz Exp $
024: */
025: public class DBMetaRootNode extends ReverseDbTreeNode implements
026: java.io.Serializable {
027: static final long serialVersionUID = 5002948511759554049L;
028:
029: /** Creates a new instance of DBMetaRootNode
030: * @param pdbMeta DatabaseMetaData implementation where this node gets its data from.
031: * @param pdbMetaTreeModel The TreeModel this node is associated to.
032: */
033: public DBMetaRootNode(java.sql.DatabaseMetaData pdbMeta,
034: DatabaseMetaDataTreeModel pdbMetaTreeModel) {
035: super (pdbMeta, pdbMetaTreeModel, null);
036: }
037:
038: /**
039: * @see ReverseDbTreeNode#isLeaf()
040: */
041: public boolean isLeaf() {
042: return false;
043: }
044:
045: /**
046: * @see ReverseDbTreeNode#getAllowsChildren()
047: */
048: public boolean getAllowsChildren() {
049: return false;
050: }
051:
052: /**
053: * @see Object#toString()
054: */
055: public String toString() {
056: return "Root";
057: }
058:
059: public Class getPropertyEditorClass() {
060: return null;
061: }
062:
063: /**
064: * Loads the catalogs of this database.
065: */
066: protected boolean _load() {
067: java.sql.ResultSet rs = null;
068: try {
069: // This synchronization is necessary for Oracle JDBC drivers 8.1.7, 9.0.1, 9.2.0.1
070: // The documentation says synchronization is done within the driver, but they
071: // must have overlooked something. Without the lock we'd get mysterious error
072: // messages.
073: synchronized (getDbMeta()) {
074: getDbMetaTreeModel().setStatusBarMessage(
075: "Started reading catalogs");
076: rs = getDbMeta().getCatalogs();
077: final java.util.ArrayList alNew = new java.util.ArrayList();
078: int count = 0;
079: while (rs.next()) {
080: getDbMetaTreeModel().setStatusBarMessage(
081: "Reading catalog "
082: + rs.getString("TABLE_CAT"));
083: alNew.add(new DBMetaCatalogNode(getDbMeta(),
084: getDbMetaTreeModel(), DBMetaRootNode.this ,
085: rs.getString("TABLE_CAT")));
086: count++;
087: }
088: if (count == 0)
089: alNew.add(new DBMetaCatalogNode(getDbMeta(),
090: getDbMetaTreeModel(), DBMetaRootNode.this ,
091: null));
092: alChildren = alNew;
093: javax.swing.SwingUtilities.invokeLater(new Runnable() {
094: public void run() {
095: getDbMetaTreeModel().nodeStructureChanged(
096: DBMetaRootNode.this );
097: }
098: });
099: rs.close();
100: }
101: } catch (java.sql.SQLException sqlEx) {
102: getDbMetaTreeModel().reportSqlError(
103: "Error retrieving catalogs", sqlEx);
104: try {
105: if (rs != null)
106: rs.close();
107: } catch (java.sql.SQLException sqlEx2) {
108: this .getDbMetaTreeModel().reportSqlError(
109: "Error retrieving catalogs", sqlEx2);
110: }
111: return false;
112: }
113: return true;
114: }
115: }
|