001: package org.firebirdsql.squirrel.tab;
002:
003: /*
004: * Copyright (C) 2004 Colin Bell
005: * colbell@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.ResultSet;
023: import java.sql.SQLException;
024:
025: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetException;
026: import net.sourceforge.squirrel_sql.fw.datasetviewer.IDataSet;
027: import net.sourceforge.squirrel_sql.fw.datasetviewer.JavabeanDataSet;
028: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
029: import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
030:
031: import net.sourceforge.squirrel_sql.fw.util.StringManager;
032: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
033:
034: import net.sourceforge.squirrel_sql.client.session.ISession;
035: import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BaseDataSetTab;
036:
037: import org.firebirdsql.squirrel.util.IndexInfo;
038: import org.firebirdsql.squirrel.util.SystemTables;
039:
040: /**
041: * This is the tab displaying information about an index.
042: *
043: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
044: */
045: public class IndexInfoTab extends BaseDataSetTab {
046: /** Internationalized strings for this class. */
047: private static final StringManager s_stringMgr = StringManagerFactory
048: .getStringManager(IndexInfoTab.class);
049:
050: /** SQL that retrieves info about a stored procedure. */
051: private String SQL = "SELECT " + SystemTables.IIndexTable.COL_NAME
052: + "," + SystemTables.IIndexTable.COL_DESCRIPTION + ","
053: + SystemTables.IIndexTable.COL_ID + ","
054: + SystemTables.IIndexTable.COL_RELATION_NAME + ","
055: + SystemTables.IIndexTable.COL_UNIQUE + ","
056: + SystemTables.IIndexTable.COL_SEGMENT_COUNT + ","
057: + SystemTables.IIndexTable.COL_INACTIVE + ","
058: + SystemTables.IIndexTable.COL_SYSTEM + ","
059: + SystemTables.IIndexTable.COL_FOREIGN_KEY + ","
060: + SystemTables.IIndexTable.COL_EXPRESSION_SOURCE + " FROM "
061: + SystemTables.IIndexTable.TABLE_NAME + " WHERE "
062: + SystemTables.IIndexTable.COL_NAME + " = ?";
063:
064: /**
065: * Return the title for the tab.
066: *
067: * @return The title for the tab.
068: */
069: public String getTitle() {
070: return s_stringMgr.getString("IndexInfoTab.title");
071: }
072:
073: /**
074: * Return the hint for the tab.
075: *
076: * @return The hint for the tab.
077: */
078: public String getHint() {
079: return s_stringMgr.getString("IndexInfoTab.hint");
080: }
081:
082: /**
083: * Create the <TT>IDataSet</TT> to be displayed in this tab.
084: */
085: protected IDataSet createDataSet() throws DataSetException {
086: return new JavabeanDataSet(createIndexInfo());
087: }
088:
089: private IndexInfo createIndexInfo() throws DataSetException {
090: final ISession session = getSession();
091: final ISQLConnection conn = session.getSQLConnection();
092:
093: try {
094: final IDatabaseObjectInfo doi = getDatabaseObjectInfo();
095: final PreparedStatement pstmt = conn.prepareStatement(SQL);
096: pstmt.setString(1, doi.getSimpleName());
097: final ResultSet rs = pstmt.executeQuery();
098: try {
099: if (rs.next()) {
100: return new IndexInfo(rs.getString(1), rs
101: .getString(2), rs.getInt(3), rs
102: .getString(4), rs.getInt(5), rs.getInt(6),
103: rs.getInt(7), rs.getInt(8),
104: rs.getString(9), rs.getString(10));
105: }
106: String msg = s_stringMgr
107: .getString("IndexInfoTab.err.noindex", doi
108: .getSimpleName());
109: throw new DataSetException(msg);
110: } finally {
111: rs.close();
112: }
113: } catch (SQLException ex) {
114: throw new DataSetException(ex);
115: }
116: }
117: }
|