You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by bo...@apache.org on 2009/10/07 03:15:27 UTC

svn commit: r822547 - /ode/branches/APACHE_ODE_1.X/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/BpelDAOConnectionImpl.java

Author: boisvert
Date: Wed Oct  7 01:15:27 2009
New Revision: 822547

URL: http://svn.apache.org/viewvc?rev=822547&view=rev
Log:
Fix issue where InstanceManagement.listInstances() and variants would fail on Oracle if > 1000 instances match selection criteria

Modified:
    ode/branches/APACHE_ODE_1.X/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/BpelDAOConnectionImpl.java

Modified: ode/branches/APACHE_ODE_1.X/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/BpelDAOConnectionImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/BpelDAOConnectionImpl.java?rev=822547&r1=822546&r2=822547&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/BpelDAOConnectionImpl.java (original)
+++ ode/branches/APACHE_ODE_1.X/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/BpelDAOConnectionImpl.java Wed Oct  7 01:15:27 2009
@@ -312,13 +312,23 @@
         if (instances.size() == 0) {
             return new HashMap<Long, Collection<CorrelationSetDAO>>();
         }
-        Long[] iids = new Long[instances.size()];
+        ArrayList<Long> iids = new ArrayList<Long>(instances.size());
         int i=0;
         for (ProcessInstanceDAO dao: instances) {
-            iids[i] = dao.getInstanceId();
+            iids.add(dao.getInstanceId());
             i++;
         }
-        Collection<HCorrelationSet> csets = getSession().getNamedQuery(HCorrelationSet.SELECT_CORSETS_BY_INSTANCES).setParameterList("instances", iids).list();
+        Collection<HCorrelationSet> csets = new ArrayList<HCorrelationSet>();
+        // some databases don't like long lists of values with IN operator
+        // so we select in batches.  Oracle 9i, for instance, doesn't support
+        // more than 1000 -- we opt to be conservative.
+        final int batchSize = 100;
+        int index = 0;
+        while (index < iids.size()) {
+            List<Long> subList = iids.subList(index, Math.min(index+batchSize, iids.size()));
+            csets.addAll(getSession().getNamedQuery(HCorrelationSet.SELECT_CORSETS_BY_INSTANCES).setParameterList("instances", subList).list());
+            index += batchSize;
+        }
         Map<Long, Collection<CorrelationSetDAO>> map = new HashMap<Long, Collection<CorrelationSetDAO>>();
         for (HCorrelationSet cset: csets) {
             Long id = cset.getInstance().getId();