001: package net.sourceforge.squirrel_sql.plugins.oracle.expander;
002:
003: /*
004: * Copyright (C) 2002 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.sql.PreparedStatement;
022: import java.sql.ResultSet;
023: import java.sql.SQLException;
024: import java.util.ArrayList;
025: import java.util.List;
026:
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.ISQLConnection;
031: import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
032:
033: import net.sourceforge.squirrel_sql.client.session.ISession;
034: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.INodeExpander;
035: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
036:
037: /**
038: * This class handles the expanding of the "Sequence Group"
039: * node. It will give a list of all the Sequences available in the schema.
040: *
041: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
042: */
043: public class SequenceParentExpander implements INodeExpander {
044: /** SQL used to load info about sequences. */
045: private static final String SQL = "select sequence_name"
046: + " from all_sequences" + " where sequence_owner = ?"
047: + " and sequence_name like ?";
048:
049: /**
050: * Default ctor.
051: */
052: public SequenceParentExpander() {
053: super ();
054: }
055:
056: /**
057: * Create the child nodes for the passed parent node and return them. Note
058: * that this method should <B>not</B> actually add the child nodes to the
059: * parent node as this is taken care of in the caller.
060: *
061: * @param session Current session.
062: * @param node Node to be expanded.
063: *
064: * @return A list of <TT>ObjectTreeNode</TT> objects representing the child
065: * nodes for the passed node.
066: */
067: public List<ObjectTreeNode> createChildren(ISession session,
068: ObjectTreeNode parentNode) throws SQLException {
069: final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
070: final IDatabaseObjectInfo parentDbinfo = parentNode
071: .getDatabaseObjectInfo();
072: final ISQLConnection conn = session.getSQLConnection();
073: final SQLDatabaseMetaData md = session.getSQLConnection()
074: .getSQLMetaData();
075: final String catalogName = parentDbinfo.getCatalogName();
076: final String schemaName = parentDbinfo.getSchemaName();
077: final String objFilter = session.getProperties()
078: .getObjectFilter();
079:
080: final PreparedStatement pstmt = conn.prepareStatement(SQL);
081: try {
082: pstmt.setString(1, schemaName);
083: pstmt.setString(2, objFilter != null
084: && objFilter.length() > 0 ? objFilter : "%");
085: ResultSet rs = pstmt.executeQuery();
086: try {
087: while (rs.next()) {
088: IDatabaseObjectInfo si = new DatabaseObjectInfo(
089: catalogName, schemaName, rs.getString(1),
090: DatabaseObjectType.SEQUENCE, md);
091: childNodes.add(new ObjectTreeNode(session, si));
092: }
093: } finally {
094: rs.close();
095: }
096: } finally {
097: pstmt.close();
098: }
099: return childNodes;
100: }
101: }
|