Author: cbegin
Date: Fri Mar 13 04:15:47 2009
New Revision: 753103

URL: http://svn.apache.org/viewvc?rev=753103&view=rev
Log:
Added support for custom executors.  Use...
sql_executor_class=com.domain.SomeSqlExecutorImpl 
...in supplied propertiesfle
Submitted by:  Abhigyan Agrawal

Added:
    
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/DefaultSqlExecutor.java
   (contents, props changed)
      - copied, changed from r737303, 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
    
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
Modified:
    ibatis/trunk/java/ibatis-2/ibatis-2-core/   (props changed)
    ibatis/trunk/java/ibatis-2/ibatis-2-core/build/version.properties
    
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java
    
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/impl/SqlMapExecutorDelegate.java

Propchange: ibatis/trunk/java/ibatis-2/ibatis-2-core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Mar 13 04:15:47 2009
@@ -1,4 +1,3 @@
-
 .classpath
 .project
 eclipse-build
@@ -12,3 +11,4 @@
 *.iws
 derby.log
 cobertura.ser
+out

Modified: ibatis/trunk/java/ibatis-2/ibatis-2-core/build/version.properties
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/build/version.properties?rev=753103&r1=753102&r2=753103&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-2/ibatis-2-core/build/version.properties (original)
+++ ibatis/trunk/java/ibatis-2/ibatis-2-core/build/version.properties Fri Mar 
13 04:15:47 2009
@@ -1,5 +1,5 @@
 #Build version info
-#Fri Oct 03 10:04:40 CDT 2008
+#Thu Mar 12 22:04:27 MDT 2009
 version=2.3.4
-buildDate=2008/10/03 10\:04
-buildNum=730
+buildDate=2009/03/12 22\:04
+buildNum=732

Modified: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java?rev=753103&r1=753102&r2=753103&view=diff
==============================================================================
--- 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java
 (original)
+++ 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/builder/xml/XmlParserState.java
 Fri Mar 13 04:15:47 2009
@@ -129,6 +129,19 @@
         props.putAll(globalProps);
         globalProps = props;
       }
+
+      // Check for custom executors
+      String customizedSQLExecutor = 
globalProps.getProperty("sql_executor_class");
+      config.getErrorContext().setActivity("Loading SQLExecutor.");
+      if (customizedSQLExecutor != null) {
+        try {
+          
config.getClient().getDelegate().setCustomExecutor(customizedSQLExecutor);
+        } catch (Exception e) {
+          config.getErrorContext().setCause(e);
+          config.getErrorContext().setMoreInfo("Loading of 
customizedSQLExecutor failed. Please check Properties file.");
+        }
+      }
+      
     } catch (Exception e) {
       throw new RuntimeException("Error loading properties.  Cause: " + e, e);
     }

Copied: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/DefaultSqlExecutor.java
 (from r737303, 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java)
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/DefaultSqlExecutor.java?p2=ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/DefaultSqlExecutor.java&p1=ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java&r1=737303&r2=753103&rev=753103&view=diff
==============================================================================
--- 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
 (original)
+++ 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/DefaultSqlExecutor.java
 Fri Mar 13 04:15:47 2009
@@ -35,19 +35,7 @@
 /**
  * Class responsible for executing the SQL
  */
-public class SqlExecutor {
-
-  //
-  // Constants
-  //
-  /**
-   * Constant to let us know not to skip anything
-   */
-  public static final int NO_SKIPPED_RESULTS = 0;
-  /**
-   * Constant to let us know to include all records
-   */
-  public static final int NO_MAXIMUM_RESULTS = -999999;
+public class DefaultSqlExecutor implements SqlExecutor {
 
   //
   // Public Methods
@@ -384,7 +372,7 @@
 
         // Get Results
         int resultsFetched = 0;
-        while ((maxResults == SqlExecutor.NO_MAXIMUM_RESULTS || resultsFetched 
< maxResults) && rs.next()) {
+        while ((maxResults == NO_MAXIMUM_RESULTS || resultsFetched < 
maxResults) && rs.next()) {
           Object[] columnValues = resultMap.resolveSubMap(statementScope, 
rs).getResults(statementScope, rs);
           callback.handleResultObject(statementScope, columnValues, rs);
           resultsFetched++;

Propchange: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/DefaultSqlExecutor.java
------------------------------------------------------------------------------
    fisheye.access = allow

Propchange: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/DefaultSqlExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/DefaultSqlExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java?rev=753103&view=auto
==============================================================================
--- 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
 (added)
+++ 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/execution/SqlExecutor.java
 Fri Mar 13 04:15:47 2009
@@ -0,0 +1,119 @@
+package com.ibatis.sqlmap.engine.execution;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+import com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback;
+import com.ibatis.sqlmap.engine.scope.SessionScope;
+import com.ibatis.sqlmap.engine.scope.StatementScope;
+
+/**
+ * Classes responsible for executing the SQL implement this interface
+ * Support for custom SQL Executors.
+ */
+public interface SqlExecutor {
+  //
+  // Constants
+  //
+  /**
+   * Constant to let us know not to skip anything
+   */
+  int NO_SKIPPED_RESULTS = 0;
+  /**
+   * Constant to let us know to include all records
+   */
+  int NO_MAXIMUM_RESULTS = -999999;
+
+  /**
+   * Execute an update
+   *
+   * @param statementScope    - the request scope
+   * @param conn       - the database connection
+   * @param sql        - the sql statement to execute
+   * @param parameters - the parameters for the sql statement
+   * @return - the number of records changed
+   * @throws SQLException - if the update fails
+   */
+  public int executeUpdate(StatementScope statementScope, Connection conn, 
String sql, Object[] parameters) throws SQLException;
+       
+  /**
+   * Adds a statement to a batch
+   *
+   * @param statementScope    - the request scope
+   * @param conn       - the database connection
+   * @param sql        - the sql statement
+   * @param parameters - the parameters for the statement
+   * @throws SQLException - if the statement fails
+   */
+  public void addBatch(StatementScope statementScope, Connection conn, String 
sql, Object[] parameters) throws SQLException;
+    
+  /**
+   * Execute a batch of statements
+   *
+   * @param sessionScope - the session scope
+   * @return - the number of rows impacted by the batch
+   * @throws SQLException - if a statement fails
+   */
+  public int executeBatch(SessionScope sessionScope) throws SQLException;
+  
+  /**
+   * Execute a batch of statements
+   *
+   * @param sessionScope - the session scope
+   * @return - a List of BatchResult objects (may be null if no batch
+   *         has been initiated).  There will be one BatchResult object in the
+   *         list for each sub-batch executed
+   * @throws SQLException   if a database access error occurs, or the drive
+   *                        does not support batch statements
+   * @throws BatchException if the driver throws BatchUpdateException
+   */
+  public List executeBatchDetailed(SessionScope sessionScope) throws 
SQLException, BatchException;
+  
+  /**
+   * Long form of the method to execute a query
+   *
+   * @param statementScope     - the request scope
+   * @param conn        - the database connection
+   * @param sql         - the SQL statement to execute
+   * @param parameters  - the parameters for the statement
+   * @param skipResults - the number of results to skip
+   * @param maxResults  - the maximum number of results to return
+   * @param callback    - the row handler for the query
+   * @throws SQLException - if the query fails
+   */
+  public void executeQuery(StatementScope statementScope, Connection conn, 
String sql, Object[] parameters, int skipResults, int maxResults, 
RowHandlerCallback callback) throws SQLException;
+  
+  /**
+   * Execute a stored procedure that updates data
+   *
+   * @param statementScope    - the request scope
+   * @param conn       - the database connection
+   * @param sql        - the SQL to call the procedure
+   * @param parameters - the parameters for the procedure
+   * @return - the rows impacted by the procedure
+   * @throws SQLException - if the procedure fails
+   */
+  public int executeUpdateProcedure(StatementScope statementScope, Connection 
conn, String sql, Object[] parameters) throws SQLException;
+  
+  /**
+   * Execute a stored procedure
+   *
+   * @param statementScope     - the request scope
+   * @param conn        - the database connection
+   * @param sql         - the sql to call the procedure
+   * @param parameters  - the parameters for the procedure
+   * @param skipResults - the number of results to skip
+   * @param maxResults  - the maximum number of results to return
+   * @param callback    - a row handler for processing the results
+   * @throws SQLException - if the procedure fails
+   */
+  public void executeQueryProcedure(StatementScope statementScope, Connection 
conn, String sql, Object[] parameters, int skipResults, int maxResults, 
RowHandlerCallback callback) throws SQLException;
+  
+  /**
+   * Clean up any batches on the session
+   *
+   * @param sessionScope - the session to clean up
+   */
+  public void cleanup(SessionScope sessionScope);
+}

Modified: 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/impl/SqlMapExecutorDelegate.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/impl/SqlMapExecutorDelegate.java?rev=753103&r1=753102&r2=753103&view=diff
==============================================================================
--- 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/impl/SqlMapExecutorDelegate.java
 (original)
+++ 
ibatis/trunk/java/ibatis-2/ibatis-2-core/src/com/ibatis/sqlmap/engine/impl/SqlMapExecutorDelegate.java
 Fri Mar 13 04:15:47 2009
@@ -26,6 +26,7 @@
 import com.ibatis.sqlmap.engine.exchange.DataExchangeFactory;
 import com.ibatis.sqlmap.engine.execution.BatchException;
 import com.ibatis.sqlmap.engine.execution.SqlExecutor;
+import com.ibatis.sqlmap.engine.execution.DefaultSqlExecutor;
 import com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap;
 import com.ibatis.sqlmap.engine.mapping.result.ResultMap;
 import com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactory;
@@ -86,11 +87,20 @@
     resultMaps = new HashMap();
     parameterMaps = new HashMap();
 
-    sqlExecutor = new SqlExecutor();
+    sqlExecutor = new DefaultSqlExecutor();
     typeHandlerFactory = new TypeHandlerFactory();
     dataExchangeFactory = new DataExchangeFactory(typeHandlerFactory);
   }
 
+  public void setCustomExecutor(String sqlExecutorClass) {
+    try {
+      Class factoryClass = Class.forName(sqlExecutorClass);
+      sqlExecutor = (SqlExecutor) factoryClass.newInstance();
+    } catch (Exception e) {
+      throw new SqlMapException("Error instantiating " + sqlExecutorClass + ". 
Please check the class given in properties file. Cause: " + e, e);
+    }
+  }
+  
   /**
    * DO NOT DEPEND ON THIS. Here to avoid breaking spring integration.
    * @deprecated
@@ -815,7 +825,7 @@
    * @return the SqlExecutor
    */
   public SqlExecutor getSqlExecutor() {
-    return sqlExecutor;
+         return sqlExecutor;
   }
 
   /**


Reply via email to