001: package net.sourceforge.squirrel_sql.plugins.oracle.expander;
002:
003: /*
004: * Copyright (C) 2002-2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.util.ArrayList;
022: import java.util.List;
023:
024: import net.sourceforge.squirrel_sql.client.session.ISession;
025: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.INodeExpander;
026: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
027: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
028: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
029: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
030: import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
031: import net.sourceforge.squirrel_sql.plugins.oracle.IObjectTypes;
032:
033: /**
034: * This class is an expander for the schema nodes. It will add various Object Type
035: * nodes to the schema node.
036: *
037: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
038: */
039: public class SchemaExpander implements INodeExpander {
040:
041: /**
042: * Ctor.
043: */
044: public SchemaExpander() {
045: super ();
046: }
047:
048: /**
049: * Create the child nodes for the passed parent node and return them. Note
050: * that this method should <B>not</B> actually add the child nodes to the
051: * parent node as this is taken care of in the caller.
052: *
053: * @param session Current session.
054: * @param node Node to be expanded.
055: *
056: * @return A list of <TT>ObjectTreeNode</TT> objects representing the child
057: * nodes for the passed node.
058: */
059: public List<ObjectTreeNode> createChildren(ISession session,
060: ObjectTreeNode parentNode) {
061: final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
062: final IDatabaseObjectInfo parentDbinfo = parentNode
063: .getDatabaseObjectInfo();
064: final SQLDatabaseMetaData md = session.getSQLConnection()
065: .getSQLMetaData();
066: final String catalogName = parentDbinfo.getCatalogName();
067: final String schemaName = parentDbinfo.getSimpleName();
068:
069: IDatabaseObjectInfo dbinfo = new DatabaseObjectInfo(
070: catalogName, schemaName, "PACKAGE",
071: IObjectTypes.PACKAGE_PARENT, md);
072: ObjectTreeNode child = new ObjectTreeNode(session, dbinfo);
073: child.addExpander(new PackageParentExpander());
074: childNodes.add(child);
075:
076: ObjectType objType;
077: objType = new ObjectType(IObjectTypes.CONSUMER_GROUP_PARENT,
078: "CONSUMER GROUP", IObjectTypes.CONSUMER_GROUP);
079: childNodes.add(createObjectTypeNode(session, catalogName,
080: schemaName, md, objType));
081:
082: objType = new ObjectType(IObjectTypes.FUNCTION_PARENT,
083: "FUNCTION", DatabaseObjectType.FUNCTION);
084: childNodes.add(createObjectTypeNode(session, catalogName,
085: schemaName, md, objType));
086:
087: objType = new ObjectType(IObjectTypes.INDEX_PARENT, "INDEX",
088: DatabaseObjectType.INDEX);
089: childNodes.add(createObjectTypeNode(session, catalogName,
090: schemaName, md, objType));
091:
092: objType = new ObjectType(IObjectTypes.LOB_PARENT, "LOB",
093: IObjectTypes.LOB);
094: childNodes.add(createObjectTypeNode(session, catalogName,
095: schemaName, md, objType));
096:
097: IDatabaseObjectInfo seqInfo = new DatabaseObjectInfo(
098: catalogName, schemaName, "SEQUENCE",
099: IObjectTypes.SEQUENCE_PARENT, md);
100: ObjectTreeNode node = new ObjectTreeNode(session, seqInfo);
101: node.addExpander(new SequenceParentExpander());
102: childNodes.add(node);
103:
104: objType = new ObjectType(IObjectTypes.TYPE_PARENT, "TYPE",
105: IObjectTypes.TYPE);
106: childNodes.add(createObjectTypeNode(session, catalogName,
107: schemaName, md, objType));
108:
109: return childNodes;
110: }
111:
112: private ObjectTreeNode createObjectTypeNode(ISession session,
113: String catalogName, String schemaName,
114: SQLDatabaseMetaData md, ObjectType objType) {
115: IDatabaseObjectInfo dbinfo = new DatabaseObjectInfo(
116: catalogName, schemaName, objType._objectTypeColumnData,
117: objType._dboType, md);
118: ObjectTreeNode node = new ObjectTreeNode(session, dbinfo);
119: node.addExpander(new ObjectTypeExpander(objType));
120: return node;
121: }
122: }
|