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.SybaseASE.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 Sybase's trigger catalog.
31: *
32: * @author manningr
33: */
34: public class SybaseTableTriggerExtractorImpl implements
35: ITableTriggerExtractor {
36:
37: /** Logger for this class */
38: private final static ILogger s_log = LoggerController
39: .createLogger(SybaseTableTriggerExtractorImpl.class);
40:
41: /** The query that finds the triggers for a given table */
42: private static String query = "SELECT triggers.name "
43: + "FROM sysobjects tables , sysobjects triggers "
44: + "where triggers.type = 'TR' "
45: + "and triggers.deltrig = tables.id "
46: + "and tables.loginame = ? " + "and tables.name = ? ";
47:
48: // trigger source
49: // "SELECT text " +
50: // "FROM dbo.sysobjects " +
51: // "inner join syscomments on syscomments.id = sysobjects.id " +
52: // "where loginame = ? " +
53: // "and name = ? " +
54: // "and type = 'TR' ";
55:
56: /**
57: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.ITableTriggerExtractor#bindParamters(java.sql.PreparedStatement, net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo)
58: */
59: public void bindParamters(PreparedStatement pstmt,
60: IDatabaseObjectInfo dbo) throws SQLException {
61: if (s_log.isDebugEnabled()) {
62: s_log.debug("Binding catalog name " + dbo.getCatalogName()
63: + " as first bind value");
64: s_log.debug("Binding table name " + dbo.getSimpleName()
65: + " as second bind value");
66: }
67: pstmt.setString(1, dbo.getCatalogName());
68: pstmt.setString(2, dbo.getSimpleName());
69:
70: }
71:
72: /**
73: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.expanders.ITableTriggerExtractor#getTableTriggerQuery()
74: */
75: public String getTableTriggerQuery() {
76: return query;
77: }
78:
79: }
|