01: /*
02: * Copyright (C) 2007 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.db2.exp;
20:
21: import java.sql.PreparedStatement;
22: import java.sql.SQLException;
23:
24: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.ITableIndexExtractor;
25: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
26: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
27: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
28:
29: /**
30: * Provides the query and parameter binding behavior for DB2's index catalog.
31: *
32: * @author manningr
33: */
34: public class DB2TableIndexExtractorImpl implements ITableIndexExtractor {
35:
36: /** Logger for this class */
37: private final static ILogger s_log = LoggerController
38: .createLogger(DB2TableIndexExtractorImpl.class);
39:
40: /** The query that finds the indexes for a given table */
41: private static final String query = "select INDNAME from SYSCAT.INDEXES "
42: + "where TABSCHEMA = ? " + "and TABNAME = ? ";
43:
44: /** The query that finds the indexes for a given table on OS/400 */
45: private static final String OS_400_SQL = "select " + "index_name "
46: + "from qsys2.sysindexes " + "where table_schema = ? "
47: + "and table_name = ? ";
48:
49: /** boolean to indicate whether or not this session is OS/400 */
50: private boolean isOS400 = false;
51:
52: /**
53: * Ctor.
54: *
55: * @param isOS400 whether or not the session is OS/400
56: */
57: public DB2TableIndexExtractorImpl(boolean isOS400) {
58: this .isOS400 = isOS400;
59: }
60:
61: /**
62: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.ITableIndexExtractor#bindParamters(java.sql.PreparedStatement, net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo)
63: */
64: public void bindParamters(PreparedStatement pstmt,
65: IDatabaseObjectInfo dbo) throws SQLException {
66: if (s_log.isDebugEnabled()) {
67: s_log.debug("Binding schema name " + dbo.getSchemaName()
68: + " as first bind value");
69: s_log.debug("Binding table name " + dbo.getSimpleName()
70: + " as second bind value");
71: }
72: pstmt.setString(1, dbo.getSchemaName());
73: pstmt.setString(2, dbo.getSimpleName());
74: }
75:
76: /**
77: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.ITableIndexExtractor#getTableIndexQuery()
78: */
79: public String getTableIndexQuery() {
80: if (isOS400) {
81: return OS_400_SQL;
82: }
83: return query;
84: }
85:
86: }
|