01: package net.sourceforge.squirrel_sql.plugins.oracle.expander;
02:
03: /*
04: * Copyright (C) 2002-2003 Colin Bell
05: * colbell@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: import java.sql.PreparedStatement;
22: import java.sql.ResultSet;
23: import java.sql.SQLException;
24: import java.util.ArrayList;
25: import java.util.List;
26:
27: import net.sourceforge.squirrel_sql.client.session.ISession;
28: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.INodeExpander;
29: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
30: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
31: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
32: import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
33: import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
34: import net.sourceforge.squirrel_sql.plugins.oracle.IObjectTypes;
35:
36: /**
37: * This class handles the expanding of the "Session Parent"
38: * node. It will give a list of all the sessions.
39: *
40: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
41: */
42: public class SessionParentExpander implements INodeExpander {
43:
44: /** SQL that retrieves the data. */
45: private static String SQL = "select sid||' ('||schemaname||')' from sys.v_$session";
46:
47: /**
48: * Default ctor.
49: */
50: public SessionParentExpander() {
51: super ();
52: }
53:
54: /**
55: * Create the child nodes for the passed parent node and return them. Note
56: * that this method should <B>not</B> actually add the child nodes to the
57: * parent node as this is taken care of in the caller.
58: *
59: * @param session Current session.
60: * @param node Node to be expanded.
61: *
62: * @return A list of <TT>ObjectTreeNode</TT> objects representing the child
63: * nodes for the passed node.
64: */
65: public List<ObjectTreeNode> createChildren(ISession session,
66: ObjectTreeNode parentNode) throws SQLException {
67: final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
68: final ISQLConnection conn = session.getSQLConnection();
69: final SQLDatabaseMetaData md = session.getSQLConnection()
70: .getSQLMetaData();
71: final IDatabaseObjectInfo parentDbinfo = parentNode
72: .getDatabaseObjectInfo();
73: final String schemaName = parentDbinfo.getSchemaName();
74:
75: PreparedStatement pstmt = conn.prepareStatement(SQL);
76: try {
77: ResultSet rs = pstmt.executeQuery();
78: try {
79: while (rs.next()) {
80: IDatabaseObjectInfo doi = new DatabaseObjectInfo(
81: null, schemaName, rs.getString(1),
82: IObjectTypes.SESSION, md);
83: childNodes.add(new ObjectTreeNode(session, doi));
84: }
85: } finally {
86: rs.close();
87: }
88: } finally {
89: pstmt.close();
90: }
91: return childNodes;
92: }
93: }
|