Update of /cvsroot/squirrel-sql/sql12/app/src/net/sourceforge/squirrel_sql/client/session/mainpanel/objecttree/tabs
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv28994/app/src/net/sourceforge/squirrel_sql/client/session/mainpanel/objecttree/tabs
Modified Files:
ViewSourceTab.java FormattedSourceTab.java
Log Message:
refactoring to remove duplicate plugin code.
Index: FormattedSourceTab.java
===================================================================
RCS file: /cvsroot/squirrel-sql/sql12/app/src/net/sourceforge/squirrel_sql/client/session/mainpanel/objecttree/tabs/FormattedSourceTab.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** FormattedSourceTab.java 1 Sep 2007 18:21:04 -0000 1.6
--- FormattedSourceTab.java 12 Dec 2009 18:06:05 -0000 1.7
***************
*** 21,24 ****
--- 21,25 ----
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+ import java.sql.SQLException;
import javax.swing.JTextArea;
***************
*** 27,30 ****
--- 28,33 ----
import net.sourceforge.squirrel_sql.fw.codereformat.CodeReformator;
import net.sourceforge.squirrel_sql.fw.codereformat.CommentSpec;
+ import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+ import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
***************
*** 197,199 ****
--- 200,259 ----
return result;
}
+
+ /**
+ * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BaseSourceTab#createStatement()
+ */
+ @Override
+ protected PreparedStatement createStatement() throws SQLException
+ {
+ final ISession session = getSession();
+
+ ISQLConnection conn = session.getSQLConnection();
+
+ String sqlStatement = getSqlStatement();
+ String[] bindValues = getBindValues();
+
+ if (s_log.isDebugEnabled())
+ {
+ s_log.debug("Running SQL for index source tab: " + sqlStatement);
+ s_log.debug("With the following bind variable values: ");
+ int parameterIndex = 0;
+ for (String bindValue : bindValues) {
+ s_log.debug("["+parameterIndex+"] => '"+bindValue+"'");
+ }
+ }
+ PreparedStatement pstmt = conn.prepareStatement(sqlStatement);
+
+ int parameterIndex = 0;
+ for (String bindValue : bindValues) {
+ pstmt.setString(parameterIndex++, bindValue);
+ }
+
+ return pstmt;
+ }
+
+ /**
+ * Subclasses must override to provide the SQL necessary to select the source for the selected
+ * DatabaseObjectInfo. Note: the default implementation of getBindValues provides values for schema and
+ * object simple name. Therefore, it is advantageous if the where clause in the select statement
+ * returned from this method specify first the schema, and then the object name and no more bind variables.
+ * If this is possible, then it isn't necessary for subclasses to override getBindValues.
+ *
+ * @return an SQL select statement with embedded bind variables (?'s).
+ */
+ protected abstract String getSqlStatement();
+
+ /**
+ * This method simply returns a String array containing the schema name and the selected object's simple
+ * name, in that order. If the SQL returned from getSqlStatement must specify a different order, or for
+ * example uses that catalog of the object, instead of or in addition to schema, then this method must be
+ * overridden to return the necessary bind variable values, in the order required by the SQL statement.
+ *
+ * @return a String array of bind variable values
+ */
+ protected String[] getBindValues()
+ {
+ final IDatabaseObjectInfo doi = getDatabaseObjectInfo();
+ return new String[] { doi.getSchemaName(), doi.getSimpleName() };
+ }
}
Index: ViewSourceTab.java
===================================================================
RCS file: /cvsroot/squirrel-sql/sql12/app/src/net/sourceforge/squirrel_sql/client/session/mainpanel/objecttree/tabs/ViewSourceTab.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ViewSourceTab.java 30 Mar 2009 01:23:42 -0000 1.1
--- ViewSourceTab.java 12 Dec 2009 18:06:05 -0000 1.2
***************
*** 19,50 ****
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
-
- import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
- import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
- import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
- import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
-
- import net.sourceforge.squirrel_sql.client.session.ISession;
/**
* This class will display the source for a view. This will work for databases that support the SQL standard
* infomation_schema.views table.
- *
- * @author manningr
*/
public class ViewSourceTab extends FormattedSourceTab
{
! /** SQL that retrieves the source of a stored procedure. */
! private static String SQL =
! "select view_definition " +
! "from information_schema.views " +
! "where table_schema = ? " +
! "and table_name = ? ";
!
! /** Logger for this class. */
! private final static ILogger s_log = LoggerController.createLogger(ViewSourceTab.class);
!
public ViewSourceTab(String hint, String stmtSep)
{
--- 19,37 ----
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* This class will display the source for a view. This will work for databases that support the SQL standard
* infomation_schema.views table.
*/
public class ViewSourceTab extends FormattedSourceTab
{
! /**
! * Constructor
! *
! * @param hint
! * what the user sees on mouse-over tool-tip
! * @param stmtSep
! * the string to use to separate SQL statements
! */
public ViewSourceTab(String hint, String stmtSep)
{
***************
*** 54,72 ****
}
! protected PreparedStatement createStatement() throws SQLException
! {
! final ISession session = getSession();
! final IDatabaseObjectInfo doi = getDatabaseObjectInfo();
!
! ISQLConnection conn = session.getSQLConnection();
! if (s_log.isDebugEnabled())
! {
! s_log.debug("Running SQL for View source tab: " + SQL);
! }
! PreparedStatement pstmt = conn.prepareStatement(SQL);
!
! pstmt.setString(1, doi.getSchemaName());
! pstmt.setString(2, doi.getSimpleName());
! return pstmt;
! }
}
--- 41,55 ----
}
! /**
! * @see net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.table.PSFormattedSourceTab#getSqlStatement()
! */
! @Override
! protected String getSqlStatement()
! {
! return
! "select view_definition " +
! "from information_schema.views " +
! "where table_schema = ? " +
! "and table_name = ? ";
! }
}
|