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.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.IDatabaseObjectInfo;
029: import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
030: import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
031:
032: import net.sourceforge.squirrel_sql.client.session.ISession;
033: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.INodeExpander;
034: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
035:
036: import net.sourceforge.squirrel_sql.plugins.oracle.IObjectTypes;
037:
038: /**
039: * This class handles the expanding of the "Instance Parent"
040: * node. It will give a list of all the instances.
041: *
042: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
043: */
044: public class InstanceParentExpander implements INodeExpander {
045: /** SQL that retrieves the data. */
046: private static String SQL = "select instance_number, instance_name, host_name, version,"
047: + " startup_time, status, parallel, thread#, archiver, log_switch_wait,"
048: + " logins, shutdown_pending, database_status, instance_role"
049: + " from sys.v_$instance";
050:
051: /**
052: * Default ctor.
053: */
054: public InstanceParentExpander() {
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 ISQLConnection conn = session.getSQLConnection();
073: final SQLDatabaseMetaData md = session.getSQLConnection()
074: .getSQLMetaData();
075:
076: PreparedStatement pstmt = conn.prepareStatement(SQL);
077: try {
078: ResultSet rs = pstmt.executeQuery();
079: try {
080: while (rs.next()) {
081: IDatabaseObjectInfo doi = new DatabaseObjectInfo(
082: null, null, rs.getString(1),
083: IObjectTypes.INSTANCE, md);
084: // final Map map = new HashMap();
085: // map.put("Instance Number", new Integer(rs.getInt(1)));
086: // map.put("Name", rs.getString(2));
087: // map.put("Host Name", rs.getString(3));
088: // map.put("Version", rs.getString(4));
089: // map.put("Startup Time", rs.getDate(5));
090: // map.put("Instance Status", rs.getString(6));
091: // map.put("Parallel", rs.getString(7));
092: // map.put("Thread #", new Integer(rs.getInt(8)));
093: // map.put("Archiver", rs.getString(9));
094: // map.put("Log Switch Wait", rs.getString(10));
095: // map.put("Logins", rs.getString(11));
096: // map.put("Shutdown Pending", rs.getString(12));
097: // map.put("Database Status", rs.getString(13));
098: // map.put("Instance Role", rs.getString(14));
099: childNodes.add(new ObjectTreeNode(session, doi));
100: }
101: } finally {
102: rs.close();
103: }
104: } finally {
105: pstmt.close();
106: }
107: return childNodes;
108: }
109: }
|