001: package net.sourceforge.squirrel_sql.plugins.postgres.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 PostgreSQL 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. This should be
044: * replaced with a property file.
045: */
046: private interface i18n {
047: // i18n[TriggerDetailsTab.title=Details]
048: String TITLE = s_stringMgr.getString("TriggerDetailsTab.title");
049: // i18n[TriggerDetailsTab.hint=Display trigger details]
050: String HINT = s_stringMgr.getString("TriggerDetailsTab.hint");
051: }
052:
053: /** SQL that retrieves the data. */
054: private static String SQL = "select condition_timing AS trigger_time, "
055: + " v.manip AS triggering_event, "
056: + " action_orientation AS granularity, "
057: + " event_object_table AS table_name "
058: + "FROM information_schema.triggers t, "
059: + "(select trigger_schema, "
060: + " trigger_name, "
061: + " rtrim( "
062: + " max(case when pos=0 then manip else '' end)|| "
063: + " max(case when pos=1 then manip else '' end)|| "
064: + " max(case when pos=2 then manip else '' end), ' or ' "
065: + " ) as manip "
066: + "from ( "
067: + " select a.trigger_schema, "
068: + " a.trigger_name, "
069: + " a.event_manipulation||' or ' as manip, "
070: + " d.cnt, "
071: + " a.rnk as pos "
072: + " from ( select trigger_name, "
073: + " trigger_schema, "
074: + " event_manipulation, "
075: + " (select count(distinct is1.event_manipulation) "
076: + " from information_schema.triggers is1 "
077: + " where is2.event_manipulation < is1.event_manipulation) as rnk "
078: + " from information_schema.triggers is2 "
079: + " ) a, "
080: + " (select trigger_schema, trigger_name, count(event_manipulation) as cnt "
081: + " from ( "
082: + " select trigger_schema, "
083: + " trigger_name, "
084: + " event_manipulation, "
085: + " (select count(distinct is3.event_manipulation) "
086: + " from information_schema.triggers is3 "
087: + " where is4.event_manipulation < is3.event_manipulation) as rnk "
088: + " from information_schema.triggers is4 "
089: + " ) y "
090: + " group by trigger_schema, trigger_name) d "
091: + " where d.trigger_name = a.trigger_name "
092: + " and d.trigger_schema = a.trigger_schema "
093: + ") x "
094: + "group by trigger_schema, trigger_name "
095: + "order by 1) v "
096: + "where t.trigger_schema = v.trigger_schema "
097: + "and t.trigger_name = v.trigger_name "
098: + "and t.trigger_schema = ? " + "and t.trigger_name = ? ";
099:
100: /** Logger for this class. */
101: private final static ILogger s_log = LoggerController
102: .createLogger(TriggerDetailsTab.class);
103:
104: public TriggerDetailsTab() {
105: super (i18n.TITLE, i18n.HINT, true);
106: }
107:
108: protected PreparedStatement createStatement() throws SQLException {
109: ISession session = getSession();
110: IDatabaseObjectInfo doi = getDatabaseObjectInfo();
111: if (s_log.isDebugEnabled()) {
112: s_log.debug("Trigger details SQL: " + SQL);
113: s_log.debug("Trigger schema: " + doi.getSchemaName());
114: s_log.debug("Trigger name: " + doi.getSimpleName());
115: }
116: PreparedStatement pstmt = session.getSQLConnection()
117: .prepareStatement(SQL);
118: pstmt.setString(1, doi.getSchemaName());
119: pstmt.setString(2, doi.getSimpleName());
120: return pstmt;
121: }
122: }
|