01: package org.firebirdsql.squirrel.exp;
02:
03: import java.sql.PreparedStatement;
04: import java.sql.ResultSet;
05: import java.sql.SQLException;
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: import net.sourceforge.squirrel_sql.client.session.ISession;
10: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.INodeExpander;
11: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
12: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
13: import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
14: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
15: import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
16: import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
17: import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
18:
19: import org.firebirdsql.squirrel.util.SystemTables;
20:
21: public class AllIndexesParentExpander implements INodeExpander {
22: private static final String STD_INDICES_SQL = "SELECT "
23: + SystemTables.IIndexTable.COL_NAME + ","
24: + SystemTables.IIndexTable.COL_RELATION_NAME + " FROM "
25: + SystemTables.IIndexTable.TABLE_NAME;
26:
27: /** SQL used to load all indices in database. */
28: private static final String ALL_INDICES_SQL = STD_INDICES_SQL
29: + " ORDER BY " + SystemTables.IIndexTable.COL_NAME;
30:
31: /**
32: * Default ctor.
33: */
34: public AllIndexesParentExpander() {
35: super ();
36: }
37:
38: /**
39: * Create the child nodes for the passed parent node and return them. Note
40: * that this method should <B>not</B> actually add the child nodes to the
41: * parent node as this is taken care of in the caller.
42: *
43: * @param session Current session.
44: * @param node Node to be expanded.
45: *
46: * @return A list of <TT>ObjectTreeNode</TT> objects representing the child
47: * nodes for the passed node.
48: *
49: * @throws SQLException
50: * Thrown if an SQL error occurs.
51: */
52: public List<ObjectTreeNode> createChildren(ISession session,
53: ObjectTreeNode parentNode) throws SQLException {
54: final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
55: final ISQLConnection conn = session.getSQLConnection();
56: final SQLDatabaseMetaData md = session.getSQLConnection()
57: .getSQLMetaData();
58:
59: PreparedStatement pstmt = null;
60:
61: try {
62: pstmt = conn.prepareStatement(ALL_INDICES_SQL);
63: final ResultSet rs = pstmt.executeQuery();
64: while (rs.next()) {
65: IDatabaseObjectInfo doi = new DatabaseObjectInfo(null,
66: null, rs.getString(1),
67: DatabaseObjectType.INDEX, md);
68: childNodes.add(new ObjectTreeNode(session, doi));
69: }
70: } finally {
71: SQLUtilities.closeStatement(pstmt);
72: }
73: return childNodes;
74: }
75: }
|