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 index.
034: *
035: */
036: public class IndexDetailsTab extends BasePreparedStatementTab {
037: /** i18N strings for this class */
038: private static final StringManager s_stringMgr = StringManagerFactory
039: .getStringManager(IndexDetailsTab.class);
040:
041: /** boolean to indicate whether or not this session is OS/400 */
042: private boolean isOS400 = false;
043:
044: /**
045: * This interface defines locale specific strings. This should be
046: * replaced with a property file.
047: */
048: private interface i18n {
049: // i18n[IndexDetailsTab.title=Details]
050: String TITLE = s_stringMgr.getString("IndexDetailsTab.title");
051: // i18n[IndexDetailsTab.hint=Display index details]
052: String HINT = s_stringMgr.getString("IndexDetailsTab.hint");
053: }
054:
055: /** SQL that retrieves the data. */
056: private static final String SQL = "SELECT T1.IID as index_identifier, "
057: + " T1.DEFINER AS index_owner, "
058: + " T1.INDNAME AS index_name, "
059: + " T2.DEFINER AS table_owner, "
060: + " T2.TABNAME AS table_name, "
061: + " T3.TBSPACE AS table_space, "
062: + " case T1.INDEXTYPE "
063: + " when 'BLOK' then 'Block Index' "
064: + " when 'CLUS' then 'Clustering Index' "
065: + " when 'DIM' then 'Dimension Block Index' "
066: + " when 'REG' then 'Regular Index' "
067: + " when 'XPTH' then 'XML Path Index' "
068: + " when 'XRGN' then 'XML Region Index' "
069: + " when 'XVIL' then 'Index over XML column (Logical)' "
070: + " when 'XVIP' then 'Index over XML column (Physical)' "
071: + " end AS index_type, "
072: + " case T1.UNIQUERULE "
073: + " when 'U' then 'UNIQUE' "
074: + " when 'D' then 'NON-UNIQUE' "
075: + " when 'I' then 'UNIQUE (Implements PK)' "
076: + " end AS uniqueness, "
077: + " T1.NLEAF AS number_of_leaf_pages, "
078: + " T1.NLEVELS AS number_of_levels, "
079: + " T1.CREATE_TIME, "
080: + " T1.STATS_TIME AS last_statistics_update, "
081: + " case T1.REVERSE_SCANS "
082: + " when 'Y' then 'Supported' "
083: + " when 'N' then 'Not Supported' "
084: + " end AS reverse_scans "
085: + "FROM SYSCAT.INDEXES AS T1, "
086: + " SYSCAT.TABLES AS T2, "
087: + " SYSCAT.TABLESPACES as T3 "
088: + "WHERE T3.TBSPACEID = T1.TBSPACEID "
089: + "and T2.TABNAME = T1.TABNAME "
090: + "and T2.TABSCHEMA = T1.TABSCHEMA "
091: + "AND T1.TABSCHEMA = ? " + "AND T1.INDNAME = ? ";
092:
093: /** SQL that retrieves the data on OS/400 */
094: private static String OS_400_SQL = "select index_owner, "
095: + "index_name, "
096: + "index_schema, "
097: + "table_owner, "
098: + "table_name, "
099: + "table_schema, "
100: + "case is_unique "
101: + " when 'D' then 'No (duplicates are allowed)' "
102: + " when 'V' then 'Yes (duplicate NULL values are allowed)' "
103: + " when 'U' then 'Yes' "
104: + " when 'E' then 'Encoded vector index' "
105: + "end as uniqueness, " + "column_count, "
106: + "system_index_name, " + "system_index_schema, "
107: + "system_table_name, " + "system_table_schema, "
108: + "long_comment, " + "iasp_number, " + "index_text, "
109: + "is_spanning_index " + "from qsys2.sysindexes "
110: + "where table_schema = ? " + "and index_name = ? ";
111:
112: /** Logger for this class. */
113: private final static ILogger s_log = LoggerController
114: .createLogger(IndexDetailsTab.class);
115:
116: /**
117: * Constructor
118: *
119: * @param isOS400 whether or not we are connected to an OS/400 system
120: */
121: public IndexDetailsTab(boolean isOS400) {
122: super (i18n.TITLE, i18n.HINT, true);
123: this .isOS400 = isOS400;
124: }
125:
126: /**
127: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BasePreparedStatementTab#createStatement()
128: */
129: @Override
130: protected PreparedStatement createStatement() throws SQLException {
131: ISession session = getSession();
132: IDatabaseObjectInfo doi = getDatabaseObjectInfo();
133: String sql = SQL;
134: if (isOS400) {
135: sql = OS_400_SQL;
136: }
137: if (s_log.isDebugEnabled()) {
138: s_log.debug("Running SQL for index details: " + sql);
139: s_log.debug("schema=" + doi.getSchemaName());
140: s_log.debug("index name=" + doi.getSimpleName());
141: }
142: PreparedStatement pstmt = session.getSQLConnection()
143: .prepareStatement(sql);
144: pstmt.setString(1, doi.getSchemaName());
145: pstmt.setString(2, doi.getSimpleName());
146: return pstmt;
147: }
148: }
|