001: package net.sourceforge.squirrel_sql.plugins.informix.exp;
002:
003: /*
004: * Copyright (C) 2006 Rob Manning
005: * manningr@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.client.session.ISession;
028: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.INodeExpander;
029: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
030: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
031: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
032: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
033: import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
034: import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
035:
036: /**
037: * This class handles the expanding of the "Sequence Group"
038: * node. It will give a list of all the Sequences available in the schema.
039: *
040: * @author manningr
041: */
042: public class SequenceParentExpander implements INodeExpander {
043: /** SQL used to load sequence names */
044: private static final String SQL = "SELECT T2.tabname AS sequence_name "
045: + "FROM informix.syssequences AS T1, "
046: + " informix.systables AS T2 "
047: + "WHERE T2.tabid = T1.tabid "
048: + "and T2.owner = ? "
049: + "and T2.tabname like ? ";
050:
051: /**
052: * Default ctor.
053: */
054: public SequenceParentExpander() {
055: super ();
056: }
057:
058: /**
059: * Create the child nodes for the passed parent node and return them. Note
060: * that this method should <B>not</B> actually add the child nodes to the
061: * parent node as this is taken care of in the caller.
062: *
063: * @param session Current session.
064: * @param node Node to be expanded.
065: *
066: * @return A list of <TT>ObjectTreeNode</TT> objects representing the child
067: * nodes for the passed node.
068: */
069: public List<ObjectTreeNode> createChildren(ISession session,
070: ObjectTreeNode parentNode) throws SQLException {
071: final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
072: final IDatabaseObjectInfo parentDbinfo = parentNode
073: .getDatabaseObjectInfo();
074: final ISQLConnection conn = session.getSQLConnection();
075: final SQLDatabaseMetaData md = session.getSQLConnection()
076: .getSQLMetaData();
077: final String catalogName = parentDbinfo.getCatalogName();
078: final String schemaName = parentDbinfo.getSchemaName();
079: final String objFilter = session.getProperties()
080: .getObjectFilter();
081:
082: final PreparedStatement pstmt = conn.prepareStatement(SQL);
083: ResultSet rs = null;
084: try {
085: pstmt.setString(1, schemaName);
086: pstmt.setString(2, objFilter != null
087: && objFilter.length() > 0 ? objFilter : "%");
088: rs = pstmt.executeQuery();
089: while (rs.next()) {
090: IDatabaseObjectInfo si = new DatabaseObjectInfo(
091: catalogName, schemaName, rs.getString(1),
092: DatabaseObjectType.SEQUENCE, md);
093: childNodes.add(new ObjectTreeNode(session, si));
094: }
095: } finally {
096: if (rs != null) {
097: try {
098: rs.close();
099: } catch (SQLException e) {
100: }
101: }
102: if (pstmt != null) {
103: try {
104: pstmt.close();
105: } catch (SQLException e) {
106: }
107: }
108: }
109: return childNodes;
110: }
111: }
|