001: package org.firebirdsql.squirrel.exp;
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 org.firebirdsql.squirrel.FirebirdPlugin;
028:
029: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
030: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
031: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
032: import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
033: import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
034: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
035: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
036:
037: import net.sourceforge.squirrel_sql.client.session.ISession;
038: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.INodeExpander;
039: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
040:
041: /**
042: * This class handles the expanding of the "Sequence Group" node. It will give a
043: * list of all the Sequences available in the schema.
044: *
045: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell </A>
046: */
047: public class GeneratorParentExpander implements INodeExpander {
048:
049: /** SQL used to load info about sequences. */
050: private static final String SQL = "select cast(rdb$generator_name as varchar(31)) as rdb$generator_name"
051: + " from rdb$generators where rdb$system_flag is null";
052:
053: /** Logger for this class. */
054: @SuppressWarnings("unused")
055: private static final ILogger s_log = LoggerController
056: .createLogger(GeneratorParentExpander.class);
057:
058: /** The plugin. */
059: @SuppressWarnings("unused")
060: private final FirebirdPlugin _plugin;
061:
062: /**
063: * Ctor.
064: *
065: * @throws IllegalArgumentException
066: * Thrown if <TT>null</TT> <TT>OraclePlugin</TT> passed.
067: */
068: GeneratorParentExpander(FirebirdPlugin plugin) {
069: super ();
070: if (plugin == null) {
071: throw new IllegalArgumentException("FirebirdPlugin == null");
072: }
073:
074: _plugin = plugin;
075: }
076:
077: /**
078: * Create the child nodes for the passed parent node and return them. Note
079: * that this method should <B>not </B> actually add the child nodes to the
080: * parent node as this is taken care of in the caller.
081: *
082: * @param session
083: * Current session.
084: * @param node
085: * Node to be expanded.
086: *
087: * @return A list of <TT>ObjectTreeNode</TT> objects representing the
088: * child nodes for the passed node.
089: */
090: public List<ObjectTreeNode> createChildren(ISession session,
091: ObjectTreeNode parentNode) throws SQLException {
092: final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
093: final IDatabaseObjectInfo parentDbinfo = parentNode
094: .getDatabaseObjectInfo();
095: final ISQLConnection conn = session.getSQLConnection();
096: final SQLDatabaseMetaData md = session.getSQLConnection()
097: .getSQLMetaData();
098: final String catalogName = parentDbinfo.getCatalogName();
099: final String schemaName = parentDbinfo.getSchemaName();
100:
101: PreparedStatement pstmt = conn.prepareStatement(SQL);
102: try {
103: ResultSet rs = pstmt.executeQuery();
104: while (rs.next()) {
105: IDatabaseObjectInfo si = new DatabaseObjectInfo(
106: catalogName, schemaName, rs.getString(1),
107: DatabaseObjectType.SEQUENCE, md);
108: childNodes.add(new ObjectTreeNode(session, si));
109: }
110: } finally {
111: pstmt.close();
112: }
113: return childNodes;
114: }
115: }
|