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.DatabaseObjectType;
32: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
33: import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
34: import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
35:
36: /**
37: * This class handles the expanding of the "Trigger Parent"
38: * node. It will give a list of all the triggers available for the table.
39: *
40: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
41: */
42: public class TriggerParentExpander implements INodeExpander {
43: private static String SQL = "select owner, trigger_name from sys.all_triggers where table_owner = ?"
44: + " and table_name = ?";
45:
46: /**
47: * Default ctor.
48: */
49: public TriggerParentExpander() {
50: super ();
51: }
52:
53: /**
54: * Create the child nodes for the passed parent node and return them. Note
55: * that this method should <B>not</B> actually add the child nodes to the
56: * parent node as this is taken care of in the caller.
57: *
58: * @param session Current session.
59: * @param node Node to be expanded.
60: *
61: * @return A list of <TT>ObjectTreeNode</TT> objects representing the child
62: * nodes for the passed node.
63: */
64: public List<ObjectTreeNode> createChildren(ISession session,
65: ObjectTreeNode parentNode) throws SQLException {
66: final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
67: final IDatabaseObjectInfo parentDbinfo = parentNode
68: .getDatabaseObjectInfo();
69: final ISQLConnection conn = session.getSQLConnection();
70: final SQLDatabaseMetaData md = session.getSQLConnection()
71: .getSQLMetaData();
72: final IDatabaseObjectInfo tableInfo = ((TriggerParentInfo) parentDbinfo)
73: .getTableInfo();
74: final PreparedStatement pstmt = conn.prepareStatement(SQL);
75: try {
76: pstmt.setString(1, tableInfo.getSchemaName());
77: pstmt.setString(2, tableInfo.getSimpleName());
78: ResultSet rs = pstmt.executeQuery();
79: try {
80: while (rs.next()) {
81: DatabaseObjectInfo doi = new DatabaseObjectInfo(
82: null, rs.getString(1), rs.getString(2),
83: DatabaseObjectType.TRIGGER, md);
84: childNodes.add(new ObjectTreeNode(session, doi));
85: }
86: } finally {
87: rs.close();
88: }
89: } finally {
90: pstmt.close();
91: }
92:
93: return childNodes;
94: }
95: }
|