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.ITableTriggerExtractor;
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 trigger catalog.
31: *
32: * @author manningr
33: */
34: public class DB2TableTriggerExtractorImpl implements
35: ITableTriggerExtractor {
36:
37: /** Logger for this class */
38: private final static ILogger s_log = LoggerController
39: .createLogger(DB2TableTriggerExtractorImpl.class);
40:
41: /** The query that finds the triggers for a given table */
42: private final static String SQL = "select TRIGNAME from SYSCAT.TRIGGERS "
43: + "where TABSCHEMA = ? " + "and TABNAME = ? ";
44:
45: /** The query that finds the triggers for a given table in DB2 on OS/400 */
46: private final static String OS400_SQL = "select trigger_name "
47: + "from qsys2.systriggers " + "where trigger_schema = ? "
48: + "and event_object_table = ? ";
49:
50: /** boolean to indicate whether or not this session is OS/400 */
51: private boolean isOS400 = false;
52:
53: /**
54: * Ctor.
55: *
56: * @param isOS400 whether or not the session is OS/400
57: */
58: public DB2TableTriggerExtractorImpl(boolean isOS400) {
59: this .isOS400 = isOS400;
60: }
61:
62: /**
63: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.ITableTriggerExtractor#bindParamters(java.sql.PreparedStatement, net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo)
64: */
65: public void bindParamters(PreparedStatement pstmt,
66: IDatabaseObjectInfo dbo) throws SQLException {
67: if (s_log.isDebugEnabled()) {
68: s_log.debug("Binding schema name " + dbo.getSchemaName()
69: + " as first bind value");
70: s_log.debug("Binding table name " + dbo.getSimpleName()
71: + " as second bind value");
72: }
73: pstmt.setString(1, dbo.getSchemaName());
74: pstmt.setString(2, dbo.getSimpleName());
75:
76: }
77:
78: /**
79: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.ITableTriggerExtractor#getTableTriggerQuery()
80: */
81: public String getTableTriggerQuery() {
82: String result = SQL;
83: if (isOS400) {
84: result = OS400_SQL;
85: }
86: return result;
87: }
88:
89: }
|