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: import java.sql.PreparedStatement;
022: import java.sql.SQLException;
023:
024: import net.sourceforge.squirrel_sql.client.session.ISession;
025: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BasePreparedStatementTab;
026: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
027: import net.sourceforge.squirrel_sql.fw.util.StringManager;
028: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
029: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
030: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
031:
032: /**
033: * This class will display the details for an DB2 sequence.
034: *
035: * @author manningr
036: */
037: public class SequenceDetailsTab extends BasePreparedStatementTab {
038: private static final StringManager s_stringMgr = StringManagerFactory
039: .getStringManager(SequenceDetailsTab.class);
040:
041: /**
042: * This interface defines locale specific strings. This should be
043: * replaced with a property file.
044: */
045: private interface i18n {
046: // i18n[SequenceDetailsTab.title=Details]
047: String TITLE = s_stringMgr
048: .getString("SequenceDetailsTab.title");
049: // i18n[SequenceDetailsTab.hint=Display sequence details]
050: String HINT = s_stringMgr.getString("SequenceDetailsTab.hint");
051: }
052:
053: /** SQL that retrieves the data. */
054: private static final String SQL = "SELECT T1.OWNER AS sequence_owner, "
055: + " T1.DEFINER AS sequence_definer, "
056: + " T1.SEQNAME AS sequence_name, "
057: + " T2.TYPENAME AS data_type, "
058: + " T1.MINVALUE AS min_value, "
059: + " T1.MAXVALUE AS max_value, "
060: + " T1.INCREMENT AS increment_by, "
061: + " case T1.CYCLE "
062: + " when 'Y' then 'CYCLE' "
063: + " else 'NOCYCLE' "
064: + " end AS cycle_flag, "
065: + " case T1.ORDER "
066: + " when 'Y' then 'ORDERED' "
067: + " else 'UNORDERED' "
068: + " end AS order_flag, "
069: + " T1.CACHE AS cache_size, "
070: + " T1.CREATE_TIME AS create_time, "
071: + " T1.ALTER_TIME AS last_alter_time, "
072: + " case T1.ORIGIN "
073: + " when 'U' then 'User' "
074: + " when 'S' then 'System' "
075: + " end AS origin, "
076: + " T1.REMARKS AS comment "
077: + "FROM SYSCAT.SEQUENCES AS T1, "
078: + " SYSCAT.DATATYPES AS T2 "
079: + "WHERE T1.DATATYPEID = T2.TYPEID "
080: + "and T1.SEQSCHEMA = ? " + "and T1.SEQNAME = ? ";
081:
082: /** SQL that retrieves the data on OS/400 */
083: private static final String OS_400_SQL = "select sequence_schema, "
084: + "sequence_name, " + "sequence_definer, "
085: + "data_type as type_name, "
086: + "minimum_value as min_value, "
087: + "maximum_value as max_value, "
088: + "increment as increment_by, " + "case cycle_option "
089: + " when 'YES' then 'CYCLE' " + " else 'NOCYCLE' "
090: + "end as cycle_flag, " + "case order "
091: + " when 'YES' then 'ORDERED' " + " else 'UNORDERED' "
092: + "end as order_flag, " + "cache as cache_size, "
093: + "sequence_created as create_time, "
094: + "last_altered_timestamp as last_alter_time, "
095: + "long_comment as comment " + "from qsys2.syssequences "
096: + "where sequence_schema = ? " + "and sequence_name = ?";
097:
098: /** Logger for this class. */
099: private final static ILogger s_log = LoggerController
100: .createLogger(SequenceDetailsTab.class);
101:
102: /** whether or not we are connected to OS/400 */
103: private boolean isOS400 = false;
104:
105: public SequenceDetailsTab(boolean isOS400) {
106: super (i18n.TITLE, i18n.HINT, true);
107: this .isOS400 = isOS400;
108: }
109:
110: /**
111: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BasePreparedStatementTab#createStatement()
112: */
113: @Override
114: protected PreparedStatement createStatement() throws SQLException {
115: ISession session = getSession();
116: IDatabaseObjectInfo doi = getDatabaseObjectInfo();
117: String sql = SQL;
118: if (isOS400) {
119: sql = OS_400_SQL;
120: }
121: if (s_log.isDebugEnabled()) {
122: s_log.debug("Sequence details SQL: " + sql);
123: s_log.debug("Sequence schema: " + doi.getSchemaName());
124: s_log.debug("Sequence name: " + doi.getSimpleName());
125: }
126: PreparedStatement pstmt = session.getSQLConnection()
127: .prepareStatement(sql);
128: pstmt.setString(1, doi.getSchemaName());
129: pstmt.setString(2, doi.getSimpleName());
130: return pstmt;
131: }
132: }
|