01: /*
02: * Copyright (C) 2005 Rob Manning
03: * manningr@users.sourceforge.net
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19: package net.sourceforge.squirrel_sql.plugins.oracle.expander;
20:
21: import java.sql.SQLException;
22: import java.util.List;
23:
24: import net.sourceforge.squirrel_sql.client.session.ISession;
25: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
26: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.DatabaseExpander;
27: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
28: import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
29: import net.sourceforge.squirrel_sql.plugins.oracle.IObjectTypes;
30: import net.sourceforge.squirrel_sql.plugins.oracle.tab.InstanceDetailsTab;
31: import net.sourceforge.squirrel_sql.plugins.oracle.tab.SessionDetailsTab;
32:
33: /**
34: * This database expander limits the schemas that are displayed in the object
35: * tree to only those that the user has privileges to access. In the event that
36: * the session account has the DBA privilege, all schemas in the database will
37: * be shown (DBA privilege connotes access to all database schemas).
38: */
39: public class DefaultDatabaseExpander extends DatabaseExpander {
40:
41: public DefaultDatabaseExpander(ISession session) {
42: super (session);
43: }
44:
45: public List<ObjectTreeNode> createChildren(ISession session,
46: ObjectTreeNode parentNode) {
47: try {
48: final List<ObjectTreeNode> childNodes = super
49: .createChildren(session, parentNode);
50:
51: final SQLDatabaseMetaData md = session.getSQLConnection()
52: .getSQLMetaData();
53:
54: // Users.
55: DatabaseObjectInfo dboInfo = new DatabaseObjectInfo(null,
56: null, "USERS", IObjectTypes.USER_PARENT, md);
57: ObjectTreeNode node = new ObjectTreeNode(session, dboInfo);
58: childNodes.add(node);
59:
60: if (InstanceDetailsTab.isAccessible(session)) {
61: // Instances.
62: dboInfo = new DatabaseObjectInfo(null, null,
63: "INSTANCES", IObjectTypes.INSTANCE_PARENT, md);
64: node = new ObjectTreeNode(session, dboInfo);
65: childNodes.add(node);
66: }
67:
68: if (SessionDetailsTab.isAccessible(session)) {
69: // Sessions.
70: dboInfo = new DatabaseObjectInfo(null, null,
71: "SESSIONS", IObjectTypes.SESSION_PARENT, md);
72: node = new ObjectTreeNode(session, dboInfo);
73: childNodes.add(node);
74: }
75:
76: return childNodes;
77: } catch (SQLException e) {
78: throw new RuntimeException(e);
79: }
80: }
81:
82: }
|