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:
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 DB2 user-defined function.
035: *
036: * @author manningr
037: */
038: public class UDFDetailsTab extends BasePreparedStatementTab {
039: private static final StringManager s_stringMgr = StringManagerFactory
040: .getStringManager(TriggerDetailsTab.class);
041:
042: /**
043: * This interface defines locale specific strings.
044: */
045: private interface i18n {
046: // i18n[UdfDetailsTab.title=Details]
047: String TITLE = s_stringMgr.getString("UdfDetailsTab.title");
048: // i18n[UdfDetailsTab.hint=Display UDF details]
049: String HINT = s_stringMgr.getString("UdfDetailsTab.hint");
050: }
051:
052: /** SQL that retrieves the data. */
053: private static String SQL = "select " + "name, " + "schema, "
054: + "definer, " + "function_id, " + "parm_count, "
055: + "side_effects, " + "fenced, " + "language, "
056: + "contains_sql, " + "result_cols, " + "class, "
057: + "jar_id " + "from sysibm.SYSFUNCTIONS "
058: + "where schema = ? " + "and name = ? ";
059:
060: /** SQL that retrieves the data on OS/400 */
061: private static String OS_400_SQL = "select "
062: + "routine_name as name, " + "routine_schema as schema, "
063: + "routine_definer as definer, "
064: + "in_parms as parm_count, " + "case external_action "
065: + " when 'E' then 'has external side effects' "
066: + " when 'N' then 'has no external side effects' "
067: + "end as side_effects, " + "fenced, "
068: + "external_language as language, "
069: + "sql_data_access as contains_sql, "
070: + "number_of_results as result_cols, " + "external_name "
071: + "from qsys2.SYSFUNCS " + "where routine_schema = ? "
072: + "and routine_name = ? ";
073:
074: /** Logger for this class. */
075: private final static ILogger s_log = LoggerController
076: .createLogger(TriggerDetailsTab.class);
077:
078: /** whether or not we are connected to OS/400 */
079: private boolean isOS400 = false;
080:
081: /**
082: * Constructor
083: *
084: * @param isOS400 whether or not we are connected to an OS/400 system
085: */
086: public UDFDetailsTab(boolean isOS400) {
087: super (i18n.TITLE, i18n.HINT, true);
088: this .isOS400 = isOS400;
089: }
090:
091: /**
092: * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BasePreparedStatementTab#createStatement()
093: */
094: @Override
095: protected PreparedStatement createStatement() throws SQLException {
096: ISession session = getSession();
097: IDatabaseObjectInfo doi = getDatabaseObjectInfo();
098: String sql = SQL;
099: if (isOS400) {
100: sql = OS_400_SQL;
101: }
102: if (s_log.isDebugEnabled()) {
103: s_log.debug("UDF details SQL: " + sql);
104: s_log.debug("UDF schema: " + doi.getSchemaName());
105: s_log.debug("UDF name: " + doi.getSimpleName());
106: }
107: PreparedStatement pstmt = session.getSQLConnection()
108: .prepareStatement(sql);
109: pstmt.setString(1, doi.getSchemaName());
110: pstmt.setString(2, doi.getSimpleName());
111: return pstmt;
112: }
113: }
|