svn commit: r808812 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: datasource/GenericDAO.java jdbc/SQLProcessor.java util/EntityListIterator.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r808812 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: datasource/GenericDAO.java jdbc/SQLProcessor.java util/EntityListIterator.java

lektran
Author: lektran
Date: Fri Aug 28 08:35:45 2009
New Revision: 808812

URL: http://svn.apache.org/viewvc?rev=808812&view=rev
Log:
Changes to the EntityListIterator to use a separate COUNT query to determine the result size plus a few other changes to help the ELI deal with TYPE_FORWARD_ONLY resultsets.

The changes to SQLProcessor are unrelated and contains no functional changes.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=808812&r1=808811&r2=808812&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Fri Aug 28 08:35:45 2009
@@ -758,7 +758,7 @@
                 Debug.logTiming("Ran query in " + queryTotalTime + " milli-seconds: " + sql, module);
             }
         }
-        return new EntityListIterator(sqlP, modelEntity, selectFields, modelFieldTypeReader);
+        return new EntityListIterator(sqlP, modelEntity, selectFields, modelFieldTypeReader, this, whereEntityCondition, havingEntityCondition);
     }
     
     protected StringBuilder makeConditionWhereString(ModelEntity modelEntity, EntityCondition whereEntityCondition, List<EntityCondition> viewWhereConditions, List<EntityConditionParam> whereEntityConditionParams) throws GenericEntityException {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java?rev=808812&r1=808811&r2=808812&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java Fri Aug 28 08:35:45 2009
@@ -26,8 +26,6 @@
 import java.sql.*;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
-
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.entity.GenericDataSourceException;
 import org.ofbiz.entity.GenericEntityException;
@@ -37,7 +35,7 @@
 import org.ofbiz.entity.transaction.TransactionUtil;
 
 /**
- * SQLProcessor - provides utitlity functions to ease database access
+ * SQLProcessor - provides utility functions to ease database access
  *
  */
 public class SQLProcessor {
@@ -60,9 +58,6 @@
     private PreparedStatement _ps = null;
 
     // / The database resources to be used
-    private Statement _stmt = null;
-
-    // / The database resources to be used
     private ResultSet _rs = null;
 
     private ResultSetMetaData _rsmd = null;
@@ -79,9 +74,6 @@
     // / true in case the connection shall be closed.
     private boolean _bDeleteConnection = false;
 
-    private Map<String, String> _needClobWorkAroundWrite = null;
-    private Map<String, String> _needBlobWorkAroundWrite = null;
-
     /**
      * Construct an object based on the helper/datasource
      *
@@ -218,17 +210,6 @@
             _ps = null;
         }
 
-        if (_stmt != null) {
-            try {
-                _stmt.close();
-                if (Debug.verboseOn()) Debug.logVerbose("SQLProcessor:close() statement close : _manualTX=" + _manualTX, module);
-            } catch (SQLException sqle) {
-                Debug.logWarning(sqle.getMessage(), module);
-            }
-
-            _stmt = null;
-        }
-
         if ((_connection != null) && _bDeleteConnection) {
             try {
                 _connection.close();
@@ -404,7 +385,7 @@
     }
 
     /**
-     * Execute a query baed ont SQL string given
+     * Execute a query based on the SQL string given
      *
      * @param sql  The SQL string to be executed
      * @return  The result set of the query
@@ -476,7 +457,7 @@
     }
 
     /**
-     * Getter: get the currently activ ResultSet
+     * Getter: get the currently active ResultSet
      *
      * @return ResultSet
      */
@@ -708,7 +689,7 @@
         if (field != null) {
             _ps.setBoolean(_ind, field.booleanValue());
         } else {
-            _ps.setNull(_ind, Types.NULL); // TODO: really should be Types.BOOLEAN, but that wasn't introduced until Java 1.4... hmmm what to do?
+            _ps.setNull(_ind, Types.BOOLEAN);
         }
         _ind++;
     }
@@ -850,7 +831,7 @@
         // do not set fetch size when using the cursor connection
         if (_connection instanceof CursorConnection) return;
 
-        // check if the statement was called with a specific fetchsize, if not grab the default from the datasource
+        // check if the statement was called with a specific fetch size, if not grab the default from the datasource
         if (fetchSize < 0) {
             DatasourceInfo ds = EntityConfigUtil.getDatasourceInfo(helperName);
             if (ds != null) {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java?rev=808812&r1=808811&r2=808812&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityListIterator.java Fri Aug 28 08:35:45 2009
@@ -33,6 +33,8 @@
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericResultSetClosedException;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.datasource.GenericDAO;
 import org.ofbiz.entity.jdbc.SQLProcessor;
 import org.ofbiz.entity.jdbc.SqlJdbcUtil;
 import org.ofbiz.entity.model.ModelEntity;
@@ -56,15 +58,26 @@
     protected boolean closed = false;
     protected boolean haveMadeValue = false;
     protected GenericDelegator delegator = null;
+    protected GenericDAO genericDAO = null;
+    protected EntityCondition whereCondition = null;
+    protected EntityCondition havingCondition = null;
 
     private boolean haveShowHasNextWarning = false;
+    private Integer resultSize = null;
 
     public EntityListIterator(SQLProcessor sqlp, ModelEntity modelEntity, List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader) {
+        this(sqlp, modelEntity, selectFields, modelFieldTypeReader, null, null, null);
+    }
+
+    public EntityListIterator(SQLProcessor sqlp, ModelEntity modelEntity, List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader, GenericDAO genericDAO, EntityCondition whereCondition, EntityCondition havingCondition) {
         this.sqlp = sqlp;
         this.resultSet = sqlp.getResultSet();
         this.modelEntity = modelEntity;
         this.selectFields = selectFields;
         this.modelFieldTypeReader = modelFieldTypeReader;
+        this.genericDAO = genericDAO;
+        this.whereCondition = whereCondition;
+        this.havingCondition = havingCondition;
     }
 
     public EntityListIterator(ResultSet resultSet, ModelEntity modelEntity, List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader) {
@@ -196,7 +209,23 @@
         if (closed) throw new GenericResultSetClosedException("This EntityListIterator has been closed, this operation cannot be performed");
 
         try {
-            return resultSet.absolute(rowNum);
+            if (resultSet.getType() == ResultSet.TYPE_FORWARD_ONLY && Math.abs(rowNum) < this.getResultsSizeAfterPartialList()) {
+                int actualRowNum = rowNum;
+                if (actualRowNum < 0) {
+                    actualRowNum = this.getResultsSizeAfterPartialList() + actualRowNum + 1;
+                }
+                while (actualRowNum != currentIndex()) {
+                    if (actualRowNum > currentIndex()) {
+                        this.next();
+                    } else {
+                        // This will throw an exception but we would have to do that anyway
+                        this.previous();
+                    }
+                }
+                return true;
+            } else {
+                return resultSet.absolute(rowNum);
+            }
         } catch (SQLException e) {
             if (!closed) {
                 this.close();
@@ -454,7 +483,7 @@
                 }
             } else {
                 // if can't reposition to desired index, throw exception
-                if (!resultSet.absolute(start)) {
+                if (!this.absolute(start)) {
                     // maybe better to just return an empty list here...
                     return list;
                     //throw new GenericEntityException("Could not move to the start position of " + start + ", there are probably not that many results for this find.");
@@ -490,7 +519,12 @@
     }
 
     public int getResultsSizeAfterPartialList() throws GenericEntityException {
-        if (this.last()) {
+        if (genericDAO != null) {
+            if (resultSize == null) {
+                resultSize = (int) genericDAO.selectCountByCondition(modelEntity, whereCondition, havingCondition, null);
+            }
+            return resultSize;
+        } else if (this.last()) {
             return this.currentIndex();
         } else {
             // evidently no valid rows in the ResultSet, so return 0