001: package net.sourceforge.squirrel_sql.plugins.db2.tab;
002:
003: /*
004: * Copyright (C) 2007 Rob Manning
005: * manningr@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: import java.sql.PreparedStatement;
023: import java.sql.SQLException;
024:
025: import net.sourceforge.squirrel_sql.client.session.ISession;
026: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BasePreparedStatementTab;
027: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
028: import net.sourceforge.squirrel_sql.fw.util.StringManager;
029: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
030: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
031: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
032:
033: /**
034: * This class will display the details for an DB2 trigger.
035: *
036: * @author manningr
037: */
038: public class TriggerDetailsTab extends BasePreparedStatementTab {
039: private static final StringManager s_stringMgr = StringManagerFactory
040: .getStringManager(TriggerDetailsTab.class);
041:
042: /**
043: * This interface defines locale specific strings.
044: */
045: private interface i18n {
046: // i18n[TriggerDetailsTab.title=Details]
047: String TITLE = s_stringMgr.getString("TriggerDetailsTab.title");
048: // i18n[TriggerDetailsTab.hint=Display trigger details]
049: String HINT = s_stringMgr.getString("TriggerDetailsTab.hint");
050: }
051:
052: /** SQL that retrieves the data. */
053: private static String SQL = "SELECT T1.DEFINER AS trigger_definer, "
054: + " T1.trigname AS trigger_name, "
055: + " case T1.TRIGTIME "
056: + " when 'A' then 'AFTER' "
057: + " when 'B' then 'BEFORE' "
058: + " when 'I' then 'INSTEAD OF' "
059: + " end AS trigger_time, "
060: + " case T1.TRIGEVENT "
061: + " when 'I' then 'INSERT' "
062: + " when 'U' then 'UPDATE' "
063: + " when 'D' then 'DELETE' "
064: + " when 'S' then 'SELECT' "
065: + " else T1.TRIGEVENT "
066: + " end AS triggering_event, "
067: + " T2.DEFINER AS table_definer, "
068: + " T2.TABNAME AS table_name, "
069: + " case T2.TYPE "
070: + " when 'T' then 'TABLE' "
071: + " when 'V' then 'VIEW' "
072: + " else T2.TYPE "
073: + " end AS table_type, "
074: + " case T1.GRANULARITY "
075: + " when 'R' then 'ROW' "
076: + " when 'S' then 'STATEMENT' "
077: + " else T1.GRANULARITY "
078: + " end AS granularity, "
079: + " case T1.VALID "
080: + " when 'Y' THEN 'VALID' "
081: + " when 'N' THEN 'INVALID' "
082: + " when 'X' THEN 'INOPERATIVE' "
083: + " end AS validity, "
084: + " T1.REMARKS comment "
085: + "FROM SYSCAT.TRIGGERS AS T1, "
086: + " SYSCAT.TABLES AS T2 "
087: + "WHERE T2.TABNAME = T1.TABNAME "
088: + "and T2.TABSCHEMA = T1.TABSCHEMA "
089: + "and T1.TRIGSCHEMA = ? " + "and T1.trigname = ? ";
090:
091: /** Logger for this class. */
092: private final static ILogger s_log = LoggerController
093: .createLogger(TriggerDetailsTab.class);
094:
095: public TriggerDetailsTab() {
096: super (i18n.TITLE, i18n.HINT, true);
097: }
098:
099: /**
100: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BasePreparedStatementTab#createStatement()
101: */
102: @Override
103: protected PreparedStatement createStatement() throws SQLException {
104: ISession session = getSession();
105: IDatabaseObjectInfo doi = getDatabaseObjectInfo();
106: if (s_log.isDebugEnabled()) {
107: s_log.debug("Trigger details SQL: " + SQL);
108: s_log.debug("Trigger schema: " + doi.getSchemaName());
109: s_log.debug("Trigger name: " + doi.getSimpleName());
110: }
111: PreparedStatement pstmt = session.getSQLConnection()
112: .prepareStatement(SQL);
113: pstmt.setString(1, doi.getSchemaName());
114: pstmt.setString(2, doi.getSimpleName());
115: return pstmt;
116: }
117: }
|