001: package net.sourceforge.squirrel_sql.plugins.db2.tab;
002:
003: /*
004: * Copyright (C) 2006 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.FormattedSourceTab;
026: import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
027: import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
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 source for an DB2 stored procedure.
035: *
036: * @author manningr
037: */
038: public class ProcedureSourceTab extends FormattedSourceTab {
039:
040: private static interface i18n {
041: StringManager s_stringMgr = StringManagerFactory
042: .getStringManager(ProcedureSourceTab.class);
043:
044: //i18n[ProcedureSourceTab.cLanguageProcMsg=This is a C-language routine. The
045: //source code is unavailable.]
046: String C_LANGUAGE_PROC_MSG = s_stringMgr
047: .getString("ProcedureSourceTab.cLanguageProcMsg");
048: }
049:
050: /** SQL that retrieves the source of a stored procedure. */
051: private static String SQL = "select " + " case "
052: + " when language = 'C' then '"
053: + i18n.C_LANGUAGE_PROC_MSG + "' " + " else text "
054: + " end as text " + "from SYSCAT.PROCEDURES "
055: + "where PROCSCHEMA = ? " + "and PROCNAME = ? ";
056:
057: /** SQL that retrieves the source of a stored procedure on OS/400 */
058: private static String OS_400_SQL = "select routine_definition from qsys2.sysroutines "
059: + "where routine_schema = ? " + "and routine_name = ? ";
060:
061: /** Logger for this class. */
062: private final static ILogger s_log = LoggerController
063: .createLogger(ProcedureSourceTab.class);
064:
065: /** boolean to indicate whether or not this session is OS/400 */
066: private boolean isOS400 = false;
067:
068: /**
069: * Constructor
070: *
071: * @param hint what the user sees on mouse-over tool-tip
072: * @param isOS400 whether or not the session is OS/400
073: */
074: public ProcedureSourceTab(String hint, boolean isOS400,
075: String stmtSep) {
076: super (hint);
077: super .setCompressWhitespace(false);
078: super .setupFormatter(stmtSep, null);
079: this .isOS400 = isOS400;
080: }
081:
082: /**
083: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BaseSourceTab#createStatement()
084: */
085: @Override
086: protected PreparedStatement createStatement() throws SQLException {
087: final ISession session = getSession();
088: final IDatabaseObjectInfo doi = getDatabaseObjectInfo();
089: String sql = SQL;
090: if (isOS400) {
091: sql = OS_400_SQL;
092: }
093: if (s_log.isDebugEnabled()) {
094: s_log.debug("Running SQL for procedure source: " + sql);
095: s_log.debug("schema=" + doi.getSchemaName());
096: s_log.debug("procedure name=" + doi.getSimpleName());
097: }
098: ISQLConnection conn = session.getSQLConnection();
099: PreparedStatement pstmt = conn.prepareStatement(sql);
100: pstmt.setString(1, doi.getSchemaName());
101: pstmt.setString(2, doi.getSimpleName());
102: return pstmt;
103: }
104: }
|