ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sean...@apache.org
Subject svn commit: r781093 [3/5] - in /ode/trunk: ./ axis2-war/src/test/java/org/apache/ode/axis2/ axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/ axis2-war/src/test/java/org/apache/ode/dao/jpa/ axis2-war/src/test/java/org/apache/ode/daohib/bpel...
Date Tue, 02 Jun 2009 17:42:49 GMT
Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessDaoImpl.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessDaoImpl.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessDaoImpl.java Tue Jun  2 17:42:46 2009
@@ -18,10 +18,14 @@
  */
 package org.apache.ode.daohib.bpel;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.ode.bpel.common.CorrelationKey;
 import org.apache.ode.bpel.dao.CorrelatorDAO;
+import org.apache.ode.bpel.dao.DeferredProcessInstanceCleanable;
 import org.apache.ode.bpel.dao.ProcessDAO;
 import org.apache.ode.bpel.dao.ProcessInstanceDAO;
+import org.apache.ode.bpel.iapi.ProcessConf.CLEANUP_CATEGORY;
 import org.apache.ode.daohib.SessionManager;
 import org.apache.ode.daohib.bpel.hobj.HActivityRecovery;
 import org.apache.ode.daohib.bpel.hobj.HBpelEvent;
@@ -29,11 +33,13 @@
 import org.apache.ode.daohib.bpel.hobj.HCorrelationSet;
 import org.apache.ode.daohib.bpel.hobj.HCorrelator;
 import org.apache.ode.daohib.bpel.hobj.HCorrelatorMessage;
+import org.apache.ode.daohib.bpel.hobj.HCorrelatorSelector;
 import org.apache.ode.daohib.bpel.hobj.HFaultData;
 import org.apache.ode.daohib.bpel.hobj.HLargeData;
 import org.apache.ode.daohib.bpel.hobj.HMessage;
 import org.apache.ode.daohib.bpel.hobj.HMessageExchange;
 import org.apache.ode.daohib.bpel.hobj.HMessageExchangeProperty;
+import org.apache.ode.daohib.bpel.hobj.HObject;
 import org.apache.ode.daohib.bpel.hobj.HPartnerLink;
 import org.apache.ode.daohib.bpel.hobj.HProcess;
 import org.apache.ode.daohib.bpel.hobj.HProcessInstance;
@@ -54,12 +60,14 @@
 import java.util.Collections;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.Set;
 
 /**
  * Hibernate-based {@link ProcessDAO} implementation.
  */
-public class ProcessDaoImpl extends HibernateDao implements ProcessDAO {
-
+public class ProcessDaoImpl extends HibernateDao implements ProcessDAO, DeferredProcessInstanceCleanable {
+    private static final Log __log = LogFactory.getLog(ProcessDaoImpl.class);
+    
     private static final String QRY_CORRELATOR = "where this.correlatorId = ?";
 
     private HProcess _process;
@@ -154,15 +162,14 @@
         // nothing to do here (yet?)
     }
 
-    public void delete() {
+    public void deleteProcessAndRoutes() {
         entering("ProcessDaoImpl.delete");
 
-        deleteEvents();
-        deleteCorrelations();
-        deleteMessages();
-        deleteVariables();
-        deleteProcessInstances();
+        // delete routes
+        getSession().getNamedQuery(HCorrelatorSelector.DELETE_MESSAGE_ROUTES_BY_PROCESS).setParameter("process", _process).executeUpdate();
 
+        // delete process dao
+        getSession().getNamedQuery(HCorrelator.DELETE_CORRELATORS_BY_PROCESS).setParameter("process", _process).executeUpdate();
         getSession().delete(_process); // this deletes HCorrelator -> HCorrelatorSelector
 
         // after this delete, we have a use case that creates the process with the same procid.
@@ -170,48 +177,88 @@
         getSession().flush();
     }
 
-    private void deleteProcessInstances() {
-        getSession().getNamedQuery(HLargeData.DELETE_ACTIVITY_RECOVERY_LDATA_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-        getSession().getNamedQuery(HActivityRecovery.DELETE_ACTIVITY_RECOVERIES_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-        getSession().getNamedQuery(HLargeData.DELETE_FAULT_LDATA_BY_PROCESS).setParameter("process", _process).executeUpdate();
-        getSession().getNamedQuery(HFaultData.DELETE_FAULTS_BY_PROCESS).setParameter("process", _process).executeUpdate();
-        getSession().getNamedQuery(HLargeData.DELETE_JACOB_LDATA_BY_PROCESS).setParameter("process", _process).executeUpdate();
-        getSession().getNamedQuery(HProcessInstance.DELETE_INSTANCES_BY_PROCESS).setParameter("process", _process).executeUpdate();
-    }
-
-    private void deleteVariables() {
-        getSession().getNamedQuery(HCorrelationProperty.DELETE_CORPROPS_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-        getSession().getNamedQuery(HCorrelationSet.DELETE_CORSETS_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-
-        getSession().getNamedQuery(HVariableProperty.DELETE_VARIABLE_PROPERITES_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-        getSession().getNamedQuery(HLargeData.DELETE_XMLDATA_LDATA_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-        getSession().getNamedQuery(HXmlData.DELETE_XMLDATA_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-
-        getSession().getNamedQuery(HLargeData.DELETE_PARTNER_LINK_LDATA_BY_PROCESS).setParameter ("process", _process).setParameter ("process2", _process).executeUpdate();
-        getSession().getNamedQuery(HPartnerLink.DELETE_PARTNER_LINKS_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-        getSession().getNamedQuery(HScope.DELETE_SCOPES_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-    }
-
-    private void deleteMessages() {
-        getSession().getNamedQuery(HCorrelatorMessage.DELETE_CORMESSAGES_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-
-//        getSession().getNamedQuery(HLargeData.DELETE_MESSAGE_LDATA_BY_PROCESS).setParameter("process", _process).setParameter ("process2", _process).executeUpdate();
-        getSession().getNamedQuery(HMessage.DELETE_REQUEST_MESSAGES_BY_PROCESS).setParameter("process", _process).executeUpdate();
-        getSession().getNamedQuery(HMessage.DELETE_RESPONSE_MESSAGES_BY_PROCESS).setParameter("process", _process).executeUpdate();
-//        getSession().getNamedQuery(HMessageExchangeProperty.DELETE_MEX_PROPS_BY_PROCESS).setParameter("process", _process).executeUpdate();
-        getSession().getNamedQuery(HLargeData.DELETE_MEX_LDATA_BY_PROCESS).setParameter("process", _process).setParameter("process2", _process).executeUpdate();
-        getSession().getNamedQuery(HMessageExchange.DELETE_MEX_BY_PROCESS).setParameter("process", _process).executeUpdate();
-        getSession().getNamedQuery(HCorrelator.DELETE_CORRELATORS_BY_PROCESS).setParameter("process", _process).executeUpdate();
+    @SuppressWarnings("unchecked")
+    public int deleteInstances(int transactionSize) {
+        entering("ProcessDaoImpl.delete");
+
+        if( transactionSize < 1 ) {
+               if(__log.isWarnEnabled()) __log.warn("A zero or negative value was given for the transaction size of process dao deletion; overriding to '1'. Not using bulk deletion of rows may result in performance degradation.");
+               transactionSize = 1;
+        }
+
+        Collection<HProcessInstance> instances = getSession().getNamedQuery(HProcessInstance.SELECT_INSTANCES_BY_PROCESS).setParameter("process", _process).setMaxResults(transactionSize).list();
+        if( !instances.isEmpty() ) {
+            deleteEvents(instances);
+            deleteCorrelations(instances);
+            deleteMessages(instances);
+            deleteVariables(instances);
+            deleteProcessInstances(instances);
+        }
+
+        return instances.size();
+    }
+
+    public int deleteInstances(Collection<HProcessInstance> instances, Set<CLEANUP_CATEGORY> categories) {
+        entering("ProcessDaoImpl.deleteInstances");
+
+        if( !instances.isEmpty() ) {
+            if( categories.contains(CLEANUP_CATEGORY.EVENTS)) {
+                deleteEvents(instances);
+            }
+            if( categories.contains(CLEANUP_CATEGORY.CORRELATIONS)) {
+                deleteCorrelations(instances);
+            }
+            if( categories.contains(CLEANUP_CATEGORY.MESSAGES)) {
+                deleteMessages(instances);
+            }
+            if( categories.contains(CLEANUP_CATEGORY.VARIABLES)) {
+                deleteVariables(instances);
+            }
+            if( categories.contains(CLEANUP_CATEGORY.INSTANCE)) {
+                deleteProcessInstances(instances);
+            }
+        }
+
+        return instances.size();
+    }
+    
+    private void deleteProcessInstances(Collection<HProcessInstance> instances) {
+        getSession().getNamedQuery(HLargeData.DELETE_ACTIVITY_RECOVERY_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HActivityRecovery.DELETE_ACTIVITY_RECOVERIES_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HLargeData.DELETE_FAULT_LDATA_BY_INSTANCE_IDS).setParameterList("instanceIds", HObject.toIdArray(instances)).executeUpdate();
+        getSession().getNamedQuery(HFaultData.DELETE_FAULTS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HLargeData.DELETE_JACOB_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HProcessInstance.DELETE_INSTANCES).setParameterList("instances", instances).executeUpdate();
+    }
+
+    private void deleteVariables(Collection<HProcessInstance> instances) {
+        getSession().getNamedQuery(HVariableProperty.DELETE_VARIABLE_PROPERITES_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HLargeData.DELETE_XMLDATA_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HXmlData.DELETE_XMLDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+
+        getSession().getNamedQuery(HLargeData.DELETE_PARTNER_LINK_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HPartnerLink.DELETE_PARTNER_LINKS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HScope.DELETE_SCOPES_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+    }
+
+    private void deleteMessages(Collection<HProcessInstance> instances) {
+        getSession().getNamedQuery(HCorrelatorMessage.DELETE_CORMESSAGES_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+
+        getSession().getNamedQuery(HLargeData.DELETE_MESSAGE_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HMessage.DELETE_MESSAGES_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HMessageExchangeProperty.DELETE_MEX_PROPS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HLargeData.DELETE_MEX_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HMessageExchange.DELETE_MEX_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
     }
 
-    private void deleteCorrelations() {
-        getSession().getNamedQuery(HCorrelationProperty.DELETE_CORPROPS_BY_PROCESS).setParameter ("process", _process).executeUpdate();
-        getSession().getNamedQuery(HCorrelationSet.DELETE_CORSETS_BY_PROCESS).setParameter ("process", _process).executeUpdate();
+    private void deleteCorrelations(Collection<HProcessInstance> instances) {
+        getSession().getNamedQuery(HCorrelationProperty.DELETE_CORPROPS_BY_INSTANCES).setParameterList ("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HCorrelationSet.DELETE_CORSETS_BY_INSTANCES).setParameterList ("instances", instances).executeUpdate();
     }
 
-    private void deleteEvents() {
-        getSession().getNamedQuery(HLargeData.DELETE_EVENT_LDATA_BY_PROCESS).setParameter("process", _process).executeUpdate();
-        getSession().getNamedQuery(HBpelEvent.DELETE_EVENTS_BY_PROCESS).setParameter("process", _process).executeUpdate();
+    private void deleteEvents(Collection<HProcessInstance> instances) {
+        getSession().getNamedQuery(HLargeData.DELETE_EVENT_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HBpelEvent.DELETE_EVENTS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
     }
 
     public QName getType() {

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessInstanceDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessInstanceDaoImpl.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessInstanceDaoImpl.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessInstanceDaoImpl.java Tue Jun  2 17:42:46 2009
@@ -324,82 +324,85 @@
         boolean instanceDeleted = false;
         
         if(__log.isDebugEnabled()) __log.debug("Cleaning up instance data with categories = " + cleanupCategories);
-        
+          
         if( _instance.getJacobState() != null ) {
-            getSession().delete(_instance.getJacobState());
-            _instance.setJacobState(null);
+          getSession().delete(_instance.getJacobState());
+          _instance.setJacobState(null);
         }
+
+        HProcessInstance[] instances = new HProcessInstance[] {_instance};
         
         if( cleanupCategories.contains(CLEANUP_CATEGORY.EVENTS) ) {
-            deleteEvents();
+          deleteEvents(instances);
         }
-        
+          
         if( cleanupCategories.contains(CLEANUP_CATEGORY.CORRELATIONS) ) {
-            deleteCorrelations();
+          deleteCorrelations(instances);
         }
-        
+
         if( cleanupCategories.contains(CLEANUP_CATEGORY.MESSAGES) ) {
-            deleteMessages();
+          deleteMessages(instances);
         }
-        
+          
         if( cleanupCategories.contains(CLEANUP_CATEGORY.VARIABLES) ) {
-            deleteVariables();
+          deleteVariables(instances);
         }
-        
+          
         if( cleanupCategories.contains(CLEANUP_CATEGORY.INSTANCE) ) {
-            deleteInstance();
-            instanceDeleted = true;
+          deleteInstances(instances);
+          instanceDeleted = true;
         }
 
         getSession().flush();
-        
+          
         if(__log.isDebugEnabled()) __log.debug("Instance data cleaned up and flushed.");
         
         return instanceDeleted;
     }
     
-    private void deleteInstance() {
-        getSession().getNamedQuery(HLargeData.DELETE_FAULT_LDATA_BY_INSTANCE_ID).setParameter ("instanceId", _instance.getId()).executeUpdate();
-        getSession().getNamedQuery(HFaultData.DELETE_FAULTS_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
+    private void deleteInstances(HProcessInstance[] instances) {
+        getSession().getNamedQuery(HLargeData.DELETE_FAULT_LDATA_BY_INSTANCE_IDS).setParameterList("instanceIds", HObject.toIdArray(instances)).executeUpdate();
+        getSession().getNamedQuery(HFaultData.DELETE_FAULTS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
 
         getSession().delete(_instance); // this deletes JcobState, HActivityRecovery -> ActivityRecovery-LData
     }
-     
-    private void deleteVariables() {
-        getSession().getNamedQuery(HCorrelationProperty.DELETE_CORPROPS_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
-        getSession().getNamedQuery(HCorrelationSet.DELETE_CORSETS_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
-
-        getSession().getNamedQuery(HVariableProperty.DELETE_VARIABLE_PROPERITES_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
-        getSession().getNamedQuery(HLargeData.DELETE_XMLDATA_LDATA_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
-        getSession().getNamedQuery(HXmlData.DELETE_XMLDATA_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
 
-        getSession().getNamedQuery(HLargeData.DELETE_PARTNER_LINK_LDATA_BY_INSTANCE).setParameter ("instance", _instance).setParameter ("instance2", _instance).executeUpdate();
-        getSession().getNamedQuery(HPartnerLink.DELETE_PARTNER_LINKS_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
+    private void deleteVariables(HProcessInstance[] instances) {
+        getSession().getNamedQuery(HCorrelationProperty.DELETE_CORPROPS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HCorrelationSet.DELETE_CORSETS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+
+        getSession().getNamedQuery(HVariableProperty.DELETE_VARIABLE_PROPERITES_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HLargeData.DELETE_XMLDATA_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HXmlData.DELETE_XMLDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
 
-        getSession().getNamedQuery(HScope.DELETE_SCOPES_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
+        getSession().getNamedQuery(HLargeData.DELETE_PARTNER_LINK_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HPartnerLink.DELETE_PARTNER_LINKS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+
+        getSession().getNamedQuery(HScope.DELETE_SCOPES_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
     }
 
     @SuppressWarnings("unchecked")
-    private void deleteMessages() {
+    private void deleteMessages(HProcessInstance[] instances) {
         // there are chances that some unmatched messages are still there
-//        getSession().getNamedQuery(HLargeData.DELETE_UNMATCHED_MESSAGE_LDATA_BY_INSTANCE).setParameter("instance", _instance).executeUpdate();
-        Collection unmatchedMex = getSession().getNamedQuery(HMessageExchange.SELECT_UNMATCHED_MEX_BY_INSTANCE).setParameter("instance", _instance).list();
+        getSession().getNamedQuery(HLargeData.DELETE_UNMATCHED_MESSAGE_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        Collection unmatchedMex = getSession().getNamedQuery(HMessageExchange.SELECT_UNMATCHED_MEX_BY_INSTANCES).setParameterList("instances", instances).list();
         if( !unmatchedMex.isEmpty() ) {
-            getSession().getNamedQuery(HMessageExchange.DELETE_UNMATCHED_MEX).setParameter("mex", unmatchedMex).executeUpdate();
+          getSession().delete(unmatchedMex);
+//        getSession().getNamedQuery(HMessageExchange.DELETE_UNMATCHED_MEX).setParameter("mex", unmatchedMex).executeUpdate();
         }
-        getSession().getNamedQuery(HCorrelatorMessage.DELETE_CORMESSAGES_BY_INSTANCE).setParameter("instance", _instance).executeUpdate();
+        getSession().getNamedQuery(HCorrelatorMessage.DELETE_CORMESSAGES_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
 
-        getSession().getNamedQuery(HCorrelatorSelector.DELETE_MESSAGE_ROUTES_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
+        getSession().getNamedQuery(HCorrelatorSelector.DELETE_MESSAGE_ROUTES_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
     }
-    
-    private void deleteCorrelations() {
-        getSession().getNamedQuery(HCorrelationProperty.DELETE_CORPROPS_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
-        getSession().getNamedQuery(HCorrelationSet.DELETE_CORSETS_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
+      
+    private void deleteCorrelations(HProcessInstance[] instances) {
+        getSession().getNamedQuery(HCorrelationProperty.DELETE_CORPROPS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HCorrelationSet.DELETE_CORSETS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
     }
 
-    private void deleteEvents() {
-        getSession().getNamedQuery(HLargeData.DELETE_EVENT_LDATA_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();
-        getSession().getNamedQuery(HBpelEvent.DELETE_EVENTS_BY_INSTANCE).setParameter ("instance", _instance).executeUpdate();      
+    private void deleteEvents(HProcessInstance[] instances) {
+        getSession().getNamedQuery(HLargeData.DELETE_EVENT_LDATA_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();
+        getSession().getNamedQuery(HBpelEvent.DELETE_EVENTS_BY_INSTANCES).setParameterList("instances", instances).executeUpdate();     
     }
 
     public void insertBpelEvent(ProcessInstanceEvent event) {

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessManagementDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessManagementDaoImpl.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessManagementDaoImpl.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessManagementDaoImpl.java Tue Jun  2 17:42:46 2009
@@ -21,9 +21,9 @@
 	public Object[] findFailedCountAndLastFailedDateForProcessId(BpelDAOConnection conn, String status, String processId) {
 		Object[] results = new Object[] {0, null};
 		
-		Query query = getSession().getNamedQuery(HProcessInstance.COUNT_FAILED_INSTANCES_BY_STATUS_AND_PROCESS_ID);
-		query.setParameterList("states", new InstanceFilter("status=" + status).convertFilterState());
-		query.setParameter("processId", processId);
+        Query query = getSession().getNamedQuery(HProcessInstance.COUNT_FAILED_INSTANCES_BY_PROCESS_IDS_AND_STATES);
+        query.setParameterList("states", new InstanceFilter("status=" + status).convertFilterState());
+        query.setParameterList("processIds", new String[] {processId});
 		query.setResultTransformer(new ResultTransformer() {
 			private static final long serialVersionUID = 8034301512569916379L;
 

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HActivityRecovery.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HActivityRecovery.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HActivityRecovery.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HActivityRecovery.java Tue Jun  2 17:42:46 2009
@@ -25,10 +25,10 @@
  * Persistent representation of activity recovery information.
  * 
  * @hibernate.class table="BPEL_ACTIVITY_RECOVERY"
- * @hibernate.query name="DELETE_ACTIVITY_RECOVERIES_BY_PROCESS" query="delete from HActivityRecovery as a where a.instance in(select i from HProcessInstance as i where i.process = :process)"
+ * @hibernate.query name="DELETE_ACTIVITY_RECOVERIES_BY_INSTANCES" query="delete from HActivityRecovery as a where a.instance in (:instances)" 
  */
 public class HActivityRecovery extends HObject {
-    public final static String DELETE_ACTIVITY_RECOVERIES_BY_PROCESS = "DELETE_ACTIVITY_RECOVERIES_BY_PROCESS";
+    public final static String DELETE_ACTIVITY_RECOVERIES_BY_INSTANCES = "DELETE_ACTIVITY_RECOVERIES_BY_INSTANCES";
 
     /** Process instance to which this scope belongs. */
     private HProcessInstance _instance;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HBpelEvent.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HBpelEvent.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HBpelEvent.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HBpelEvent.java Tue Jun  2 17:42:46 2009
@@ -25,12 +25,10 @@
  * Row representation of a BPEL event.
  * 
  * @hibernate.class table="BPEL_EVENT"
- * @hibernate.query name="DELETE_EVENTS_BY_PROCESS" query="delete from HBpelEvent as e where e.process = :process"
- * @hibernate.query name="DELETE_EVENTS_BY_INSTANCE" query="delete from HBpelEvent as e where e.instance = :instance"
+ * @hibernate.query name="DELETE_EVENTS_BY_INSTANCES" query="delete from HBpelEvent as e where e.instance in (:instances)"
  */
 public class HBpelEvent extends HObject {
-    public final static String DELETE_EVENTS_BY_PROCESS = "DELETE_EVENTS_BY_PROCESS";
-    public static final String DELETE_EVENTS_BY_INSTANCE = "DELETE_EVENTS_BY_INSTANCE";
+    public static final String DELETE_EVENTS_BY_INSTANCES = "DELETE_EVENTS_BY_INSTANCES";
 
     private Timestamp _tstamp;
     private String _type;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelationProperty.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelationProperty.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelationProperty.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelationProperty.java Tue Jun  2 17:42:46 2009
@@ -26,12 +26,10 @@
  * correlation set.
  * 
  * @hibernate.class table="BPEL_CORRELATION_PROP"
- * @hibernate.query name="DELETE_CORPROPS_BY_PROCESS" query="delete from HCorrelationProperty as p where p.correlationSet in(select s from HCorrelationSet as s where s.process = :process)"
- * @hibernate.query name="DELETE_CORPROPS_BY_INSTANCE" query="delete from HCorrelationProperty as p where p.correlationSet in(select s from HCorrelationSet as s where s.instance = :instance)"
+ * @hibernate.query name="DELETE_CORPROPS_BY_INSTANCES" query="delete from HCorrelationProperty as p where p.correlationSet in(select s from HCorrelationSet as s where s.instance in (:instances))"
  */
 public class HCorrelationProperty extends HObject {
-    public final static String DELETE_CORPROPS_BY_PROCESS = "DELETE_CORPROPS_BY_PROCESS";
-    public final static String DELETE_CORPROPS_BY_INSTANCE = "DELETE_CORPROPS_BY_INSTANCE";
+    public final static String DELETE_CORPROPS_BY_INSTANCES = "DELETE_CORPROPS_BY_INSTANCES";
 
     private String _name;
     private String _namespace;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelationSet.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelationSet.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelationSet.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelationSet.java Tue Jun  2 17:42:46 2009
@@ -25,16 +25,14 @@
  * Hibernate table representing correlation set values.
  * 
  * @hibernate.class table="BPEL_CORRELATION_SET"
+ * @hibernate.query name="DELETE_CORSETS_BY_INSTANCES" query="delete from HCorrelationSet as c where c.instance in (:instances)"
  * @hibernate.query name="SELECT_CORSETS_BY_INSTANCES" query="from HCorrelationSet as c left join fetch c.properties where c.instance.id in (:instances)"
- * @hibernate.query name="SELECT_ACTIVE_CORSETS" query="from HCorrelationSet as c left join fetch c.process left join fetch c.instance where c.instance.state = (:state)"
- * @hibernate.query name="DELETE_CORSETS_BY_INSTANCE" query="delete from HCorrelationSet as c where c.instance = :instance"
- * @hibernate.query name="DELETE_CORSETS_BY_PROCESS" query="delete from HCorrelationSet as c where c.process = :process"
+ * @hibernate.query name="SELECT_CORSETS_BY_PROCESS_STATES" query="from HCorrelationSet as c left join fetch c.process left join fetch c.instance where c.instance.state in (:states)"
  */
 public class HCorrelationSet extends HObject {
-    public static final String DELETE_CORSETS_BY_INSTANCE = "DELETE_CORSETS_BY_INSTANCE";
-    public static final String DELETE_CORSETS_BY_PROCESS = "DELETE_CORSETS_BY_PROCESS";
+    public static final String DELETE_CORSETS_BY_INSTANCES = "DELETE_CORSETS_BY_INSTANCES";
     public static final String SELECT_CORSETS_BY_INSTANCES = "SELECT_CORSETS_BY_INSTANCES";
-    public static final String SELECT_ACTIVE_CORSETS = "SELECT_ACTIVE_CORSETS";
+    public static final String SELECT_CORSETS_BY_PROCESS_STATES = "SELECT_CORSETS_BY_PROCESS_STATES";
 	  
     private HProcess _process;
     private HProcessInstance _instance;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelator.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelator.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelator.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelator.java Tue Jun  2 17:42:46 2009
@@ -55,7 +55,7 @@
      * Get the set of {@link HCorrelatorMessage} objects representing the
      * messages that need matching to a selector (i.e. pick/receive).
      * 
-     * @hibernate.set lazy="true" inverse="true" cascade="delete"
+     * @hibernate.set lazy="true" inverse="true"
      * @hibernate.collection-key column="CORRELATOR" foreign-key="none"
      * @hibernate.collection-one-to-many class="org.apache.ode.daohib.bpel.hobj.HCorrelatorMessage"
      */
@@ -97,7 +97,7 @@
      * Get the set of {@link HCorrelatorSelector} objects representing the
      * selectors (i.e. pick/receive) that need matching to an input message.
      * 
-     * @hibernate.set lazy="true" inverse="true" cascade="delete"
+     * @hibernate.set lazy="true" inverse="true"
      * @hibernate.collection-key column="CORRELATOR" foreign-key="none"
      * @hibernate.collection-one-to-many class="org.apache.ode.daohib.bpel.hobj.HCorrelatorSelector"
      */

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelatorMessage.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelatorMessage.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelatorMessage.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelatorMessage.java Tue Jun  2 17:42:46 2009
@@ -20,14 +20,12 @@
 
 /**
  * @hibernate.class table="BPEL_UNMATCHED" lazy="true"
- * @hibernate.query name="DELETE_CORMESSAGES_BY_PROCESS" query="delete from HCorrelatorMessage as m where m.correlator in(select c from HCorrelator as c where c.process = :process)"
- * @hibernate.query name="DELETE_CORMESSAGES_BY_INSTANCE" query="delete from HCorrelatorMessage as m where m.messageExchange in(select mex from HMessageExchange as mex where mex.instance = :instance)"
+ * @hibernate.query name="DELETE_CORMESSAGES_BY_INSTANCES" query="delete from HCorrelatorMessage as m where m.messageExchange in(select mex from HMessageExchange as mex where mex.instance in (:instances))"
  * @hibernate.query name="DELETE_CORMESSAGES_BY_MEX" query="delete from HCorrelatorMessage as m where m.messageExchange = :mex"
  */
 public class HCorrelatorMessage extends HObject {
-    public final static String DELETE_CORMESSAGES_BY_PROCESS = "DELETE_CORMESSAGES_BY_PROCESS";
     public final static String DELETE_CORMESSAGES_BY_MEX = "DELETE_CORMESSAGES_BY_MEX";
-    public final static String DELETE_CORMESSAGES_BY_INSTANCE = "DELETE_CORMESSAGES_BY_INSTANCE";
+    public final static String DELETE_CORMESSAGES_BY_INSTANCES = "DELETE_CORMESSAGES_BY_INSTANCES";
 
     private HMessageExchange _messageExchange;
     private HCorrelator _correlator;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelatorSelector.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelatorSelector.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelatorSelector.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HCorrelatorSelector.java Tue Jun  2 17:42:46 2009
@@ -20,10 +20,12 @@
 
 /**
  * @hibernate.class table="BPEL_SELECTORS" lazy="true"
- * @hibernate.query name="DELETE_MESSAGE_ROUTES_BY_INSTANCE" query="delete from HCorrelatorSelector as m where m.instance = :instance)"
+ * @hibernate.query name="DELETE_MESSAGE_ROUTES_BY_PROCESS" query="delete from HCorrelatorSelector as m where m.correlator in(select c from HCorrelator c where c.process = :process)"
+ * @hibernate.query name="DELETE_MESSAGE_ROUTES_BY_INSTANCES" query="delete from HCorrelatorSelector as m where m.instance in (:instances))"
  */
 public class HCorrelatorSelector extends HObject {
-    public static final String DELETE_MESSAGE_ROUTES_BY_INSTANCE = "DELETE_MESSAGE_ROUTES_BY_INSTANCE";
+    public static final String DELETE_MESSAGE_ROUTES_BY_PROCESS = "DELETE_MESSAGE_ROUTES_BY_PROCESS";
+    public static final String DELETE_MESSAGE_ROUTES_BY_INSTANCES = "DELETE_MESSAGE_ROUTES_BY_INSTANCES";
 
     private HProcessInstance _instance;
     private String _groupId;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HFaultData.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HFaultData.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HFaultData.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HFaultData.java Tue Jun  2 17:42:46 2009
@@ -23,12 +23,10 @@
  * Persistent representation of a fault.
  * 
  * @hibernate.class table="BPEL_FAULT"
- * @hibernate.query name="DELETE_FAULTS_BY_PROCESS" query="delete from HFaultData as f where f in (select i.fault from HProcessInstance as i where i.process = :process)"
- * @hibernate.query name="DELETE_FAULTS_BY_INSTANCE" query="delete from HFaultData as f where f in (select i.fault from HProcessInstance as i where i = :instance)"
+ * @hibernate.query name="DELETE_FAULTS_BY_INSTANCES" query="delete from HFaultData as f where f in (select i.fault from HProcessInstance as i where i in (:instances))"
  */
 public class HFaultData extends HObject {
-    public final static String DELETE_FAULTS_BY_PROCESS = "DELETE_FAULTS_BY_PROCESS";
-    public final static String DELETE_FAULTS_BY_INSTANCE = "DELETE_FAULTS_BY_INSTANCE";
+    public final static String DELETE_FAULTS_BY_INSTANCES = "DELETE_FAULTS_BY_INSTANCES";
 
     private String _name;
     private String _explanation;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HLargeData.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HLargeData.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HLargeData.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HLargeData.java Tue Jun  2 17:42:46 2009
@@ -25,38 +25,33 @@
  * an instance of this class must be created.
  * 
  * @hibernate.class table="LARGE_DATA"
- * @hibernate.query name="DELETE_EVENT_LDATA_BY_PROCESS" query="delete from HLargeData as d where d in(select e.data from HBpelEvent as e where e.process = :process)"
- * @hibernate.query name="DELETE_XMLDATA_LDATA_BY_PROCESS" query="delete from HLargeData as d where d in(select x.data from HXmlData as x where x.instance.process = :process)"
- * @hibernate.query name="DELETE_ACTIVITY_RECOVERY_LDATA_BY_PROCESS" query="delete from HLargeData as d where d in(select a.details from HActivityRecovery as a where a.instance.process = :process)"
- * @hibernate.query name="DELETE_FAULT_LDATA_BY_PROCESS" query="delete from HLargeData as d where d in(select f.data from HFaultData as f, HProcessInstance as i where f.id = i.fault and i.process = :process)"
- * @hibernate.query name="DELETE_JACOB_LDATA_BY_PROCESS" query="delete from HLargeData as d where d in(select i.jacobState from HProcessInstance as i where i.process = :process)"
- * @hibernate.query name="DELETE_PARTNER_LINK_LDATA_BY_PROCESS" query="delete from HLargeData as d where d in(select l.myEPR from HPartnerLink as l where l.scope.instance.process = :process) or d IN(select l.partnerEPR from HPartnerLink as l where l.scope.instance.process = :process2)"
- * @hibernate.query name="DELETE_MESSAGE_LDATA_BY_PROCESS" query="delete from HLargeData as d where d in(select m.messageData from HMessage m where m in(select request from HMessageExchange x where x.process = :process)) or d in(select m.header from HMessage m where m in(select request from HMessageExchange x where x.process = :process)) or d in(select m.messageData from HMessage m where m in(select response from HMessageExchange x where x.process = :process)) or d in(select m.header from HMessage m where m in(select response from HMessageExchange x where x.process = :process))"
- * @hibernate.query name="DELETE_MEX_LDATA_BY_PROCESS" query="delete from HLargeData as d where d in(select e.endpoint from HMessageExchange as e where e.process = :process) or d IN(select e.callbackEndpoint from HMessageExchange as e where e.process = :process2)"
- * 
- * @hibernate.query name="DELETE_EVENT_LDATA_BY_INSTANCE" query="delete from HLargeData as d where d in(select e.data from HBpelEvent as e where e.instance = :instance)"
- * @hibernate.query name="DELETE_MESSAGE_LDATA_BY_MEX" query="delete from HLargeData as d where d in(select m.messageData from HMessage m where m in(select request from HMessageExchange x where x = :mex)) or d in(select m.header from HMessage m where m in(select request from HMessageExchange x where x = :mex)) or d in(select m.messageData from HMessage m where m in(select response from HMessageExchange x where x = :mex)) or d in(select m.header from HMessage m where m in(select response from HMessageExchange x where x = :mex))"
- * @hibernate.query name="DELETE_UNMATCHED_MESSAGE_LDATA_BY_INSTANCE" query="delete from HLargeData as d where d in(select m.messageData from HMessage m, HMessageExchange x, HCorrelatorMessage cm where (m = x.request or m = x.response) and x = cm.messageExchange and x.instance = :instance) or d in(select m.header from HMessage m, HMessageExchange x, HCorrelatorMessage cm where (m = x.request or m = x.response) and x = cm.messageExchange and x.instance = :instance)"
- * @hibernate.query name="DELETE_XMLDATA_LDATA_BY_INSTANCE" query="delete from HLargeData as d where d in(select x.data from HXmlData as x where x.instance = :instance)"
- * @hibernate.query name="DELETE_PARTNER_LINK_LDATA_BY_INSTANCE" query="delete from HLargeData as d where d in(select l.myEPR from HPartnerLink as l where l.scope.instance = :instance) or d IN(select l.partnerEPR from HPartnerLink as l where l.scope.instance = :instance2)"
- * @hibernate.query name="DELETE_FAULT_LDATA_BY_INSTANCE_ID" query="delete from HLargeData as d where d in(select f.data from HFaultData as f, HProcessInstance as i where f.id = i.fault and i.id = :instanceId)"
+ * @hibernate.query name="DELETE_ACTIVITY_RECOVERY_LDATA_BY_INSTANCES" query="delete from HLargeData as d where d in(select a.details from HActivityRecovery as a where a.instance in (:instances))"
+ * @hibernate.query name="DELETE_JACOB_LDATA_BY_INSTANCES" query="delete from HLargeData as d where d in(select i.jacobState from HProcessInstance as i where i in (:instances))"
+ * @hibernate.query name="DELETE_MESSAGE_LDATA_BY_INSTANCES" query="delete from HLargeData as d where d in(select x.request.messageData from HMessageExchange x where x.instance in(:instances)) or d in(select x.response.messageData from HMessageExchange x where x.instance in(:instances)) or d in(select x.request.header from HMessageExchange x where x.instance in (:instances)) or d in(select x.response.header from HMessageExchange x where x.instance in (:instances))"
+ * @hibernate.query name="DELETE_MEX_LDATA_BY_INSTANCES" query="delete from HLargeData as d where d in(select e.endpoint from HMessageExchange as e where e.instance in (:instances)) or d IN(select e.callbackEndpoint from HMessageExchange as e where e.instance in (:instances))"
+ *
+ * @hibernate.query name="DELETE_EVENT_LDATA_BY_INSTANCES" query="delete from HLargeData as d where d in(select e.data from HBpelEvent as e where e.instance in (:instances))"
+ * @hibernate.query name="DELETE_UNMATCHED_MESSAGE_LDATA_BY_INSTANCES" query="delete from HLargeData as d where d in(select cm.messageExchange.request.messageData from HCorrelatorMessage cm where cm.messageExchange.instance in (:instances)) or d in(select cm.messageExchange.response.messageData from HCorrelatorMessage cm where cm.messageExchange.instance in (:instances)) or d in(select cm.messageExchange.request.header from HCorrelatorMessage cm where cm.messageExchange.instance in (:instances)) or d in(select cm.messageExchange.response.header from HCorrelatorMessage cm where cm.messageExchange.instance in (:instances))"
+ * @hibernate.query name="DELETE_XMLDATA_LDATA_BY_INSTANCES" query="delete from HLargeData as d where d in(select x.data from HXmlData as x where x.instance in (:instances))"
+ * @hibernate.query name="DELETE_PARTNER_LINK_LDATA_BY_INSTANCES" query="delete from HLargeData as d where d in(select l.myEPR from HPartnerLink as l where l.scope.instance in (:instances)) or d IN(select l.partnerEPR from HPartnerLink as l where l.scope.instance in (:instances))"
+ * @hibernate.query name="DELETE_FAULT_LDATA_BY_INSTANCE_IDS" query="delete from HLargeData as d where d in(select f.data from HFaultData as f, HProcessInstance as i where f.id = i.fault and i.id in (:instanceIds))"
+
+ * @hibernate.query name="DELETE_MESSAGE_LDATA_BY_MEX" query="delete from HLargeData as d where d in(select m.messageData from HMessage m, HMessageExchange x where (m = x.request or m = x.response) and x = :mex) or d in(select m.header from HMessage m, HMessageExchange x where (m = x.request or m = x.response) and x = :mex)"
  */
 public class HLargeData extends HObject {
-    public final static String DELETE_EVENT_LDATA_BY_PROCESS = "DELETE_EVENT_LDATA_BY_PROCESS";
-    public final static String DELETE_XMLDATA_LDATA_BY_PROCESS = "DELETE_XMLDATA_LDATA_BY_PROCESS";
-    public final static String DELETE_ACTIVITY_RECOVERY_LDATA_BY_PROCESS = "DELETE_ACTIVITY_RECOVERY_LDATA_BY_PROCESS";
-    public final static String DELETE_FAULT_LDATA_BY_PROCESS = "DELETE_FAULT_LDATA_BY_PROCESS";
-    public final static String DELETE_JACOB_LDATA_BY_PROCESS = "DELETE_JACOB_LDATA_BY_PROCESS";
-    public final static String DELETE_PARTNER_LINK_LDATA_BY_PROCESS = "DELETE_PARTNER_LINK_LDATA_BY_PROCESS";
-    public final static String DELETE_MESSAGE_LDATA_BY_PROCESS = "DELETE_MESSAGE_LDATA_BY_PROCESS";
-    public final static String DELETE_MEX_LDATA_BY_PROCESS = "DELETE_MEX_LDATA_BY_PROCESS";
+//@hibernate.query name="DELETE_MESSAGE_LDATA_BY_INSTANCES" query="delete from HLargeData as d where d in(select m.messageData from HMessage m, HMessageExchange x where (m = x.request or m = x.response) and x.instance in(:instances)) or d in(select m.header from HMessage m, HMessageExchange x where (m = x.request or m = x.response) and x.instance in (:instances))"
+    
+    public final static String DELETE_ACTIVITY_RECOVERY_LDATA_BY_INSTANCES = "DELETE_ACTIVITY_RECOVERY_LDATA_BY_INSTANCES";
+    public final static String DELETE_JACOB_LDATA_BY_INSTANCES = "DELETE_JACOB_LDATA_BY_INSTANCES";
+    public final static String DELETE_MESSAGE_LDATA_BY_INSTANCES = "DELETE_MESSAGE_LDATA_BY_INSTANCES";
+    public final static String DELETE_MEX_LDATA_BY_INSTANCES = "DELETE_MEX_LDATA_BY_INSTANCES";
 
-    public final static String DELETE_EVENT_LDATA_BY_INSTANCE = "DELETE_EVENT_LDATA_BY_INSTANCE";
+    public final static String DELETE_EVENT_LDATA_BY_INSTANCES = "DELETE_EVENT_LDATA_BY_INSTANCES";
     public final static String DELETE_MESSAGE_LDATA_BY_MEX = "DELETE_MESSAGE_LDATA_BY_MEX";
-    public final static String DELETE_UNMATCHED_MESSAGE_LDATA_BY_INSTANCE = "DELETE_UNMATCHED_MESSAGE_LDATA_BY_INSTANCE";
-    public final static String DELETE_XMLDATA_LDATA_BY_INSTANCE = "DELETE_XMLDATA_LDATA_BY_INSTANCE";
-    public final static String DELETE_PARTNER_LINK_LDATA_BY_INSTANCE = "DELETE_PARTNER_LINK_LDATA_BY_INSTANCE";
-    public final static String DELETE_FAULT_LDATA_BY_INSTANCE_ID = "DELETE_FAULT_LDATA_BY_INSTANCE_ID";
+    public final static String DELETE_UNMATCHED_MESSAGE_LDATA_BY_INSTANCES = "DELETE_UNMATCHED_MESSAGE_LDATA_BY_INSTANCES";
+    public final static String DELETE_XMLDATA_LDATA_BY_INSTANCES = "DELETE_XMLDATA_LDATA_BY_INSTANCES";
+    public final static String DELETE_PARTNER_LINK_LDATA_BY_INSTANCES = "DELETE_PARTNER_LINK_LDATA_BY_INSTANCES";
+    public final static String DELETE_FAULT_LDATA_BY_INSTANCE_IDS = "DELETE_FAULT_LDATA_BY_INSTANCE_IDS";
 
     private byte[] binary = null;
 

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessage.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessage.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessage.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessage.java Tue Jun  2 17:42:46 2009
@@ -24,12 +24,12 @@
  *
  * @hibernate.class
  *  table="BPEL_MESSAGE"
- * @hibernate.query name="DELETE_REQUEST_MESSAGES_BY_PROCESS" query="delete from HMessage as m WHERE m IN(select request from HMessageExchange e where e.process = :process)"
- * @hibernate.query name="DELETE_RESPONSE_MESSAGES_BY_PROCESS" query="delete from HMessage as m WHERE m IN(select response from HMessageExchange e where e.process = :process)"
+ * @hibernate.query name="DELETE_MESSAGES_BY_MEX" query="delete from HMessage as m where m in(select request from HMessageExchange e where e = :messageExchange) or m in(select response from HMessageExchange e where e = :messageExchange)"
+ * @hibernate.query name="DELETE_MESSAGES_BY_INSTANCES" query="delete from HMessage as m where m in(select request from HMessageExchange e where e.instance in (:instances)) or m in(select response from HMessageExchange e where e.instance in (:instances))"
  */
 public class HMessage extends HObject {
-    public final static String DELETE_REQUEST_MESSAGES_BY_PROCESS = "DELETE_REQUEST_MESSAGES_BY_PROCESS";
-    public final static String DELETE_RESPONSE_MESSAGES_BY_PROCESS = "DELETE_RESPONSE_MESSAGES_BY_PROCESS";
+    public final static String DELETE_MESSAGES_BY_MEX = "DELETE_MESSAGES_BY_MEX";
+    public final static String DELETE_MESSAGES_BY_INSTANCES = "DELETE_MESSAGES_BY_INSTANCES";
 
     private String _type;
     private HLargeData _data;
@@ -61,5 +61,4 @@
     public void setHeader(HLargeData header) {
         _header = header;
     }
-
 }

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessageExchange.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessageExchange.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessageExchange.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessageExchange.java Tue Jun  2 17:42:46 2009
@@ -26,16 +26,12 @@
  * Hibernate-managed table for keeping track of message exchanges.
  * 
  * @hibernate.class table="BPEL_MESSAGE_EXCHANGE" dynamic-update="true"
- * @hibernate.query name="DELETE_MEX_BY_INSTANCE" query="delete from HMessageExchange as m where m.instance = :instance"
- * @hibernate.query name="SELECT_UNMATCHED_MEX_BY_INSTANCE" query="from HMessageExchange as m where m in(select cm.messageExchange from HCorrelatorMessage as cm where cm.messageExchange.instance = :instance)"
- * @hibernate.query name="DELETE_UNMATCHED_MEX" query="delete from HMessageExchange as m where m in(:mex)"
- * @hibernate.query name="DELETE_MEX_BY_PROCESS" query="delete from HMessageExchange as m where m.process = :process"
+ * @hibernate.query name="DELETE_MEX_BY_INSTANCES" query="delete from HMessageExchange as m where m.instance in (:instances)"
+ * @hibernate.query name="SELECT_UNMATCHED_MEX_BY_INSTANCES" query="from HMessageExchange as m where m in(select cm.messageExchange from HCorrelatorMessage as cm where cm.messageExchange.instance in (:instances))"
  */
 public class HMessageExchange extends HObject {
-    public final static String DELETE_MEX_BY_INSTANCE = "DELETE_MEX_BY_INSTANCE";
-    public final static String SELECT_UNMATCHED_MEX_BY_INSTANCE = "SELECT_UNMATCHED_MEX_BY_INSTANCE";
-    public final static String DELETE_UNMATCHED_MEX = "DELETE_UNMATCHED_MEX";
-    public final static String DELETE_MEX_BY_PROCESS = "DELETE_MEX_BY_PROCESS";
+    public final static String DELETE_MEX_BY_INSTANCES = "DELETE_MEX_BY_INSTANCES";
+    public final static String SELECT_UNMATCHED_MEX_BY_INSTANCES = "SELECT_UNMATCHED_MEX_BY_INSTANCES";
 
     private String _channelName;
 

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessageExchangeProperty.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessageExchangeProperty.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessageExchangeProperty.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HMessageExchangeProperty.java Tue Jun  2 17:42:46 2009
@@ -25,11 +25,11 @@
  * is excluded from schema export.
  * 
  * @hibernate.class table="BPEL_MEX_PROPS" lazy="true"
- * @hibernate.query name="DELETE_MEX_PROPS_BY_PROCESS" query="delete from HMessageExchangeProperty as p where p.mex in(select e from HMessageExchange e where e.process = :process)"
+ * @hibernate.query name="DELETE_MEX_PROPS_BY_INSTANCES" query="delete from HMessageExchangeProperty as p where p.mex in(select e from HMessageExchange e where e.instance in (:instances))"
  */
 @SuppressWarnings("serial")
 public class HMessageExchangeProperty implements Serializable {
-	public final static String DELETE_MEX_PROPS_BY_PROCESS = "DELETE_MEX_PROPS_BY_PROCESS";
+    public final static String DELETE_MEX_PROPS_BY_INSTANCES = "DELETE_MEX_PROPS_BY_INSTANCES";
 
 	private HMessageExchange _mex;
 	private String _name;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HObject.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HObject.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HObject.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HObject.java Tue Jun  2 17:42:46 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.ode.daohib.bpel.hobj;
 
+import java.util.Collection;
 import java.util.Date;
 
 /**
@@ -75,6 +76,28 @@
         _lock = lock;
     }
 
+    public static <T extends HObject> Object[] toIdArray(T[] objects) {
+        Object[] ids = new Object[objects.length];
+
+        int index = 0;
+        for( HObject object : objects ) {
+            ids[index++] = object.getId();
+        }
+
+        return ids;
+    }
+
+    public static Object[] toIdArray(Collection<? extends HObject> objects) {
+        Object[] ids = new Object[objects.size()];
+
+        int index = 0;
+        for( HObject object : objects ) {
+            ids[index++] = object.getId();
+        }
+
+        return ids;
+    }
+
     public String toString() {
         return this.getClass()+"{id="+_id+"}";
     }

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HPartnerLink.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HPartnerLink.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HPartnerLink.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HPartnerLink.java Tue Jun  2 17:42:46 2009
@@ -28,12 +28,10 @@
  * configuration).
  * 
  * @hibernate.class table="BPEL_PLINK_VAL"
- * @hibernate.query name="DELETE_PARTNER_LINKS_BY_INSTANCE" query="delete from HPartnerLink as l where l.scope in (select s from HScope as s where s.instance = :instance)"
- * @hibernate.query name="DELETE_PARTNER_LINKS_BY_PROCESS" query="delete from HPartnerLink as l where l.scope in (select s.id from HScope as s where s.instance.process = :process)"
+ * @hibernate.query name="DELETE_PARTNER_LINKS_BY_INSTANCES" query="delete from HPartnerLink as l where l.scope in (select s from HScope as s where s.instance in (:instances))"
  */
 public class HPartnerLink extends HObject {
-    public final static String DELETE_PARTNER_LINKS_BY_INSTANCE = "DELETE_PARTNER_LINKS_BY_INSTANCE";
-    public final static String DELETE_PARTNER_LINKS_BY_PROCESS = "DELETE_PARTNER_LINKS_BY_PROCESS";
+    public final static String DELETE_PARTNER_LINKS_BY_INSTANCES = "DELETE_PARTNER_LINKS_BY_INSTANCES";
 
     private String _linkName;
 

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HProcess.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HProcess.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HProcess.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HProcess.java Tue Jun  2 17:42:46 2009
@@ -74,7 +74,6 @@
      * @hibernate.set
      *  lazy="true"
      *  inverse="true"
-     *  cascade="delete"
      * @hibernate.collection-key
      *  column="PROCESS" foreign-key="none"
      * @hibernate.collection-one-to-many

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HProcessInstance.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HProcessInstance.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HProcessInstance.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HProcessInstance.java Tue Jun  2 17:42:46 2009
@@ -28,16 +28,16 @@
  * Hibernate table representing a BPEL process instance.
  * 
  * @hibernate.class table="BPEL_INSTANCE" dynamic-update="true" lazy="true"
- * @hibernate.query name="COUNT_INSTANCES_BY_STATUS_AND_PROCESS_ID" query="select count(i.id) as cnt, max(i.activityFailureDateTime) as lastFailureDt from HProcessInstance as i where i.process.processId = :processId and i.state in(:states) and i.activityFailureCount > 0"
- * @hibernate.query name="COUNT_FAILED_INSTANCES_BY_STATUS_AND_PROCESS_ID" query="select count(i.id) as cnt, max(i.activityFailureDateTime) as lastFailureDt from HProcessInstance as i where i.process.processId = :processId and i.state in(:states) and i.activityFailureCount > 0"
- * @hibernate.query name="SELECT_ACTIVE_INSTANCES" query="from HProcessInstance as i where i.process.id = :processId and i.state = :state"
- * @hibernate.query name="DELETE_INSTANCES_BY_PROCESS" query="delete from HProcessInstance as p where p.process = :process"
+ * @hibernate.query name="COUNT_FAILED_INSTANCES_BY_PROCESS_IDS_AND_STATES" query="select count(i.id) as cnt, max(i.activityFailureDateTime) as lastFailureDt from HProcessInstance as i where i.process.processId in (:processIds) and i.state in(:states) and i.activityFailureCount > 0"
+ * @hibernate.query name="SELECT_INSTANCES_BY_PROCESS" query="from HProcessInstance as i where i.process = :process)"
+ * @hibernate.query name="SELECT_INSTANCES_BY_PROCESSES_AND_STATES" query="from HProcessInstance as i where i.process in (:processes) and i.state in (:states)"
+ * @hibernate.query name="DELETE_INSTANCES" query="delete from HProcessInstance as i where i in (:instances)"
  */
 public class HProcessInstance extends HObject {
-	public static final String SELECT_ACTIVE_INSTANCES="SELECT_ACTIVE_INSTANCES";
-	public static final String DELETE_INSTANCES_BY_PROCESS="DELETE_INSTANCES_BY_PROCESS";
-	public static final String COUNT_FAILED_INSTANCES_BY_STATUS_AND_PROCESS_ID="COUNT_FAILED_INSTANCES_BY_STATUS_AND_PROCESS_ID";
-	public static final String COUNT_INSTANCeS_BY_STATUS_AND_PROCESS_ID="COUNT_INSTANCES_BY_STATUS_AND_PROCESS_ID";
+    public static final String COUNT_FAILED_INSTANCES_BY_PROCESS_IDS_AND_STATES="COUNT_FAILED_INSTANCES_BY_PROCESS_IDS_AND_STATES";
+    public static final String SELECT_INSTANCES_BY_PROCESS="SELECT_INSTANCES_BY_PROCESS";
+    public static final String SELECT_INSTANCES_BY_PROCESSES_AND_STATES="SELECT_INSTANCES_BY_PROCESSES_AND_STATES";
+    public static final String DELETE_INSTANCES="DELETE_INSTANCES";
 	
     /** Foreign key to owner {@link HProcess}. */
     private HProcess _process;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HScope.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HScope.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HScope.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HScope.java Tue Jun  2 17:42:46 2009
@@ -25,12 +25,10 @@
  * Hibernate table representing a BPEL scope instance.
  * 
  * @hibernate.class table="BPEL_SCOPE"
- * @hibernate.query name="DELETE_SCOPES_BY_INSTANCE" query="delete from HScope as s where s.instance = :instance"
- * @hibernate.query name="DELETE_SCOPES_BY_PROCESS" query="delete from HScope as s where s.instance in (select i from HProcessInstance as i where i.process = :process)"
+ * @hibernate.query name="DELETE_SCOPES_BY_INSTANCES" query="delete from HScope as s where s.instance in (:instances)"
  */
 public class HScope extends HObject {
-    public final static String DELETE_SCOPES_BY_INSTANCE = "DELETE_SCOPES_BY_INSTANCE";
-    public final static String DELETE_SCOPES_BY_PROCESS = "DELETE_SCOPES_BY_PROCESS";
+    public final static String DELETE_SCOPES_BY_INSTANCES = "DELETE_SCOPES_BY_INSTANCES";
 
     /** Process instance to which this scope belongs. */
     private HProcessInstance _instance;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HVariableProperty.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HVariableProperty.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HVariableProperty.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HVariableProperty.java Tue Jun  2 17:42:46 2009
@@ -23,12 +23,10 @@
  * of process instances based on indexed lookup of property values.
  * 
  * @hibernate.class table="VAR_PROPERTY"
- * @hibernate.query name="DELETE_VARIABLE_PROPERITES_BY_PROCESS" query="delete from HVariableProperty as p where p.xmlData in(select x.id from HXmlData x where x.instance.process = :process)"
- * @hibernate.query name="DELETE_VARIABLE_PROPERITES_BY_INSTANCE" query="delete from HVariableProperty as p where p.xmlData in(select x.id from HXmlData x where x.instance = :instance)"
+ * @hibernate.query name="DELETE_VARIABLE_PROPERITES_BY_INSTANCES" query="delete from HVariableProperty as p where p.xmlData in(select x.id from HXmlData x where x.instance in (:instances))"
  */
 public class HVariableProperty extends HObject {
-    public final static String DELETE_VARIABLE_PROPERITES_BY_PROCESS = "DELETE_VARIABLE_PROPERITES_BY_PROCESS";
-    public final static String DELETE_VARIABLE_PROPERITES_BY_INSTANCE = "DELETE_VARIABLE_PROPERITES_BY_INSTANCE";
+    public final static String DELETE_VARIABLE_PROPERITES_BY_INSTANCES = "DELETE_VARIABLE_PROPERITES_BY_INSTANCES";
 
     private String _propertyValue;
     private String _propertyName;

Modified: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HXmlData.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HXmlData.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HXmlData.java (original)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/hobj/HXmlData.java Tue Jun  2 17:42:46 2009
@@ -23,12 +23,10 @@
 
 /**
  * @hibernate.class table="BPEL_XML_DATA"
- * @hibernate.query name="DELETE_XMLDATA_BY_PROCESS" query="delete from HXmlData as x where x.instance in(select i from HProcessInstance as i where i.process = :process)"
- * @hibernate.query name="DELETE_XMLDATA_BY_INSTANCE" query="delete from HXmlData as x where x.instance = :instance"
+ * @hibernate.query name="DELETE_XMLDATA_BY_INSTANCES" query="delete from HXmlData as x where x.instance in (:instances)"
  */
 public class HXmlData extends HObject {
-    public static final String DELETE_XMLDATA_BY_PROCESS = "DELETE_XMLDATA_BY_PROCESS";
-    public static final String DELETE_XMLDATA_BY_INSTANCE = "DELETE_XMLDATA_BY_INSTANCE";
+    public static final String DELETE_XMLDATA_BY_INSTANCES = "DELETE_XMLDATA_BY_INSTANCES";
 
     private boolean _simpleType;
     private HLargeData _data;

Modified: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/BPELDAOConnectionImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/BPELDAOConnectionImpl.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/BPELDAOConnectionImpl.java (original)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/BPELDAOConnectionImpl.java Tue Jun  2 17:42:46 2009
@@ -35,6 +35,8 @@
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import javax.xml.namespace.QName;
+
+import java.io.Serializable;
 import java.sql.Timestamp;
 import java.text.ParseException;
 import java.util.*;
@@ -89,6 +91,13 @@
         return ret;
     }
 
+    public ProcessDAO createTransientProcess(Serializable id) {
+        ProcessDAOImpl ret = new ProcessDAOImpl(null, null, null, 0);
+        ret.setId((Long)id);
+        
+        return ret;
+    }
+
     public ProcessDAO getProcess(QName processId) {
         List l = _em.createQuery("select x from ProcessDAOImpl x where x._processId = ?1")
                 .setParameter(1, processId.toString()).getResultList();

Modified: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/ProcessDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/ProcessDAOImpl.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/ProcessDAOImpl.java (original)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/ProcessDAOImpl.java Tue Jun  2 17:42:46 2009
@@ -28,6 +28,8 @@
 
 import javax.persistence.*;
 import javax.xml.namespace.QName;
+
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -55,29 +57,37 @@
 
     @Basic @Column(name="PROCESS_ID")
     private String _processId;
-	@Transient
+    @Transient
     private int _numInstances;
-	@Basic @Column(name="PROCESS_TYPE")
+    @Basic @Column(name="PROCESS_TYPE")
     private String _processType;
-	@Basic @Column(name="GUID")
+    @Basic @Column(name="GUID")
     private String _guid;
-	@Basic @Column(name="VERSION")
+    @Basic @Column(name="VERSION")
     private long _version;
 
-	@OneToMany(targetEntity=CorrelatorDAOImpl.class,mappedBy="_process",fetch=FetchType.LAZY,cascade={CascadeType.ALL})
+    @OneToMany(targetEntity=CorrelatorDAOImpl.class,mappedBy="_process",fetch=FetchType.LAZY,cascade={CascadeType.ALL})
     private Collection<CorrelatorDAOImpl> _correlators = new ArrayList<CorrelatorDAOImpl>();
 
-	public ProcessDAOImpl() {}
-	public ProcessDAOImpl(QName pid, QName type, String guid, long version) {
+    public ProcessDAOImpl() {}
+    public ProcessDAOImpl(QName pid, QName type, String guid, long version) {
         _processId = pid.toString();
-		_processType = type.toString();
-		_guid = guid;
+        _processType = type.toString();
+        _guid = guid;
         _version = version;
     }
-	
-	public CorrelatorDAO addCorrelator(String correlator) {
-		CorrelatorDAOImpl corr = new CorrelatorDAOImpl(correlator, this);
-		_correlators.add(corr);
+    
+    public Serializable getId() {
+        return _id; 
+    }
+    
+    public void setId(Long id) {
+        _id = id;
+    }
+
+    public CorrelatorDAO addCorrelator(String correlator) {
+        CorrelatorDAOImpl corr = new CorrelatorDAOImpl(correlator, this);
+        _correlators.add(corr);
         return corr;
     }
 
@@ -91,47 +101,60 @@
     }
 
     public ProcessInstanceDAO createInstance(
-			CorrelatorDAO instantiatingCorrelator) {
-		ProcessInstanceDAOImpl inst = new ProcessInstanceDAOImpl((CorrelatorDAOImpl)instantiatingCorrelator, this);
-		getEM().persist(inst);
-		_numInstances++;
-		return inst;
-	}
+            CorrelatorDAO instantiatingCorrelator) {
+        ProcessInstanceDAOImpl inst = new ProcessInstanceDAOImpl((CorrelatorDAOImpl)instantiatingCorrelator, this);
+        getEM().persist(inst);
+        _numInstances++;
+        return inst;
+    }
 
     public Collection<ProcessInstanceDAO> findInstance(CorrelationKey key) {
-    	return findInstance(key, true);
+        return findInstance(key, true);
     }
     
-	@SuppressWarnings("unchecked")
+    @SuppressWarnings("unchecked")
     public Collection<ProcessInstanceDAO> findInstance(CorrelationKey ckey, boolean wait) {
-		Query qry = getEM().createNamedQuery("InstanceByCKey");
+        Query qry = getEM().createNamedQuery("InstanceByCKey");
         qry.setParameter("ckey", ckey.toCanonicalString());
         return qry.getResultList();
-	}
+    }
 
-	public ProcessInstanceDAO getInstance(Long iid) {
-		return getEM().find(ProcessInstanceDAOImpl.class, iid);
-	}
+    public ProcessInstanceDAO getInstance(Long iid) {
+        return getEM().find(ProcessInstanceDAOImpl.class, iid);
+    }
+
+    public QName getProcessId() {
+        return QName.valueOf(_processId);
+    }
 
-	public QName getProcessId() {
-		return QName.valueOf(_processId);
-	}
+    public QName getType() {
+        return QName.valueOf(_processType);
+    }
 
-	public QName getType() {
-		return QName.valueOf(_processType);
-	}
+    @SuppressWarnings("unchecked")
+    public void deleteProcessAndRoutes() {
+        // delete routes
+        Collection instanceIds = getEM().createNamedQuery(ProcessInstanceDAOImpl.SELECT_INSTANCE_IDS_BY_PROCESS).setParameter("process", this).getResultList();
+        batchUpdateByIds(instanceIds.iterator(), getEM().createNamedQuery(MessageRouteDAOImpl.DELETE_MESSAGE_ROUTES_BY_INSTANCE_IDS), "instanceIds");
+        getEM().createNamedQuery(CorrelatorDAOImpl.DELETE_CORRELATORS_BY_PROCESS).setParameter("process", this).executeUpdate();
 
-    public void delete() {
+        deleteInstances(Integer.MAX_VALUE);
+        
+        // delete process dao
+        getEM().remove(this); // This deletes CorrelatorDAO
+        getEM().flush();
+    }
+    
+    private int deleteInstances(int transactionSize) {
         if(__log.isDebugEnabled()) __log.debug("Cleaning up process data.");
 
-        getEM().flush();
         deleteEvents();
         deleteCorrelations();
         deleteMessages();
         deleteVariables();
         deleteProcessInstances();
-        getEM().remove(this); // This deletes CorrelatorDAO
-        getEM().flush();
+        
+        return 0;
     }
 
     @SuppressWarnings("unchecked")

Modified: ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/BpelServerImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/BpelServerImpl.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/BpelServerImpl.java (original)
+++ ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/BpelServerImpl.java Tue Jun  2 17:42:46 2009
@@ -23,6 +23,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.Callable;
@@ -46,6 +47,7 @@
 import org.apache.ode.bpel.iapi.*;
 import org.apache.ode.bpel.iapi.Scheduler.JobInfo;
 import org.apache.ode.bpel.iapi.Scheduler.JobProcessorException;
+import org.apache.ode.bpel.iapi.Scheduler.MapSerializableRunnable;
 import org.apache.ode.bpel.intercept.MessageExchangeInterceptor;
 import org.apache.ode.bpel.rapi.ProcessModel;
 import org.apache.ode.il.config.OdeConfigProperties;
@@ -80,6 +82,12 @@
     /** Maximum age of a process before it is quiesced */
     private static Long __processMaxAge;
 
+    public final static String DEFERRED_PROCESS_INSTANCE_CLEANUP_DISABLED_NAME =
+        "org.apache.ode.disable.deferredProcessInstanceCleanup";
+    
+    private static boolean DEFERRED_PROCESS_INSTANCE_CLEANUP_DISABLED = 
+        Boolean.getBoolean(DEFERRED_PROCESS_INSTANCE_CLEANUP_DISABLED_NAME);
+
     /** RNG, for delays */
     private Random _random = new Random(System.currentTimeMillis());
 
@@ -473,26 +481,41 @@
         return false;
     }
 
-    /* TODO: We need to have a method of cleaning up old deployment data. */
-    private boolean deleteProcessDAO(final QName pid) {
+    protected boolean deleteProcessDAO(final QName pid) {
         try {
-            // Delete it from the database.
             return _db.exec(new BpelDatabase.Callable<Boolean>() {
                 public Boolean run(BpelDAOConnection conn) throws Exception {
-                    ProcessDAO proc = conn.getProcess(pid);
-                    if (proc != null) {
-                        proc.delete();
-                        return true;
-                    }
-                    return false;
+                    return deleteProcessDAO(conn, pid);
                 }
             });
-        } catch (Exception ex) {
-            String errmsg = "DbError";
-            __log.error(errmsg, ex);
-            throw new BpelEngineException(errmsg, ex);
+        } catch (RuntimeException re) {
+            throw re;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
         }
     }
+    
+    private boolean deleteProcessDAO(BpelDAOConnection conn, QName pid) {
+        final ProcessDAO proc = conn.getProcess(pid);
+        if (proc != null) {
+            // delete routes
+            if(__log.isDebugEnabled()) __log.debug("Deleting only the process " + pid + "...");
+            proc.deleteProcessAndRoutes();
+            if(__log.isInfoEnabled()) __log.info("Deleted only the process " + pid + ".");
+             // we do deferred instance cleanup only for hibernate, for now
+            if( proc instanceof DeferredProcessInstanceCleanable &&
+                !DEFERRED_PROCESS_INSTANCE_CLEANUP_DISABLED ) {
+                // schedule deletion of process runtime data
+                _contexts.scheduler.scheduleMapSerializableRunnable(
+                    new ProcessCleanUpRunnable(((DeferredProcessInstanceCleanable)proc).getId()), new Date());
+            } else if( proc instanceof DeferredProcessInstanceCleanable ) {
+                ((DeferredProcessInstanceCleanable)proc).deleteInstances(Integer.MAX_VALUE);
+            }
+            return true;
+        }
+        return false;
+        
+    }
 
     public void onScheduledJob(final JobInfo jobInfo) throws JobProcessorException {
         _mngmtLock.readLock().lock();
@@ -1008,4 +1031,113 @@
     
     public void setTransacted(boolean atomicScope) {
     }
+
+    /**
+     * A polled runnable instance that implements this interface will be set 
+     * with the contexts before the run() method is called.
+     * 
+     * @author sean
+     *
+     */
+    public interface ContextsAware {
+        void setContexts(Contexts contexts);
+    }
+
+    /**
+     * This wraps up the executor service for polled runnables.
+     * 
+     * @author sean
+     *
+     */
+    public static class PolledRunnableProcessor implements Scheduler.JobProcessor {
+        private ExecutorService _polledRunnableExec;
+        private Contexts _contexts;
+        
+        // this map contains all polled runnable results that are not completed.
+        // keep an eye on this one, since if we re-use this polled runnable and
+        // generate too many entries in this map, this becomes a memory leak(
+        // long-running memory occupation)
+        private final Map<String, PolledRunnableResults> resultsByJobId = new HashMap<String, PolledRunnableResults>();
+
+        public void setContexts(Contexts contexts) {
+            _contexts = contexts;
+        }
+        
+        public void setPolledRunnableExecutorService(ExecutorService polledRunnableExecutorService) {
+            _polledRunnableExec = polledRunnableExecutorService;
+        }
+
+        public void onScheduledJob(final Scheduler.JobInfo jobInfo) throws Scheduler.JobProcessorException {
+            JOB_STATUS statusOfPriorTry = JOB_STATUS.PENDING;
+            Exception exceptionThrownOnPriorTry = null;
+            boolean toRetry = false;
+            
+            synchronized( resultsByJobId ) {
+                PolledRunnableResults results = resultsByJobId.get(jobInfo.jobName);        
+                if( results != null ) {
+                    statusOfPriorTry = results._status;
+                    exceptionThrownOnPriorTry = results._exception;
+                }
+                if( statusOfPriorTry == JOB_STATUS.COMPLETED ) {
+                    resultsByJobId.remove(jobInfo.jobName);
+                    jobInfo.jobDetail.put("runnable_status", JOB_STATUS.COMPLETED);
+                    return;
+                }
+                if( statusOfPriorTry == JOB_STATUS.PENDING || statusOfPriorTry == JOB_STATUS.FAILED ) {
+                    resultsByJobId.put(jobInfo.jobName, new PolledRunnableResults(JOB_STATUS.IN_PROGRESS, null));
+                    toRetry = true;
+                }
+            }
+            
+            if( toRetry ) {
+                // re-try
+                _polledRunnableExec.submit(new Runnable() {
+                    public void run() {
+                        try {
+                            MapSerializableRunnable runnable = (MapSerializableRunnable)jobInfo.jobDetail.get("runnable");
+                            runnable.restoreFromDetailsMap(jobInfo.jobDetail);
+                            if( runnable instanceof ContextsAware ) {
+                                ((ContextsAware)runnable).setContexts(_contexts);
+                            }
+                            runnable.run();
+                            synchronized( resultsByJobId ) {
+                                resultsByJobId.put(jobInfo.jobName, new PolledRunnableResults(JOB_STATUS.COMPLETED, null));
+                            }
+                        } catch( Exception e) {
+                            __log.error("", e);
+                            synchronized( resultsByJobId ) {
+                                resultsByJobId.put(jobInfo.jobName, new PolledRunnableResults(JOB_STATUS.FAILED, e));
+                            }
+                        } finally {
+                        }
+                    }
+                });
+            }
+            
+            jobInfo.jobDetail.put("runnable_status", JOB_STATUS.IN_PROGRESS);
+            if( exceptionThrownOnPriorTry != null ) {
+                throw new Scheduler.JobProcessorException(exceptionThrownOnPriorTry, true);
+            }
+        }
+        
+        private static enum JOB_STATUS {
+            PENDING, IN_PROGRESS, FAILED, COMPLETED
+        }
+        
+        private class PolledRunnableResults {
+            private JOB_STATUS _status = JOB_STATUS.PENDING;
+            private Exception _exception;
+            
+            public PolledRunnableResults(JOB_STATUS status, Exception exception) {
+                _status = status;
+                _exception = exception;
+            }
+        }
+    }
+
+    public void cleanupProcess(ProcessConf pconf) throws BpelEngineException {
+        if (pconf != null) {
+            deleteProcessDAO(pconf.getProcessId());
+        }
+    }
 }

Modified: ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/Contexts.java
URL: http://svn.apache.org/viewvc/ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/Contexts.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/Contexts.java (original)
+++ ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/Contexts.java Tue Jun  2 17:42:46 2009
@@ -42,21 +42,23 @@
 import org.apache.ode.bpel.iapi.MessageExchangeContext;
 import org.apache.ode.bpel.iapi.Scheduler;
 import org.apache.ode.bpel.intercept.MessageExchangeInterceptor;
+import org.apache.ode.bpel.engine.cron.CronScheduler;
 import org.apache.ode.bpel.evar.ExternalVariableModule;
 import org.apache.ode.bpel.extension.ExtensionBundleRuntime;
 
 /**
  * Aggregation of all the contexts provided to the BPEL engine by the integration layer.
  */
-class Contexts {
+public class Contexts {
     private static final Log __log = LogFactory.getLog(Contexts.class);
     
     TransactionManager txManager;
     MessageExchangeContext mexContext;
-    Scheduler scheduler;
+    public Scheduler scheduler;
+    public CronScheduler cronScheduler;
     EndpointReferenceContext eprContext;
     BindingContext bindingContext;
-    BpelDAOConnectionFactory dao;
+    public BpelDAOConnectionFactory dao;
 
     /** Global Message-Exchange interceptors. Must be copy-on-write!!! */
     final List<MessageExchangeInterceptor> globalIntereceptors = new CopyOnWriteArrayList<MessageExchangeInterceptor>();

Modified: ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/ODEProcess.java
URL: http://svn.apache.org/viewvc/ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/ODEProcess.java?rev=781093&r1=781092&r2=781093&view=diff
==============================================================================
--- ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/ODEProcess.java (original)
+++ ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/ODEProcess.java Tue Jun  2 17:42:46 2009
@@ -566,7 +566,8 @@
      * exists and matches the GUID.
      */
     private void doBounce(BpelDAOConnection conn, final QName pid, final long version, final ProcessModel mprocess) {
-        deleteProcessDAO(conn, pid, version, mprocess);
+        // SEAN; I do not think we need this one anymore -- needs to confirm
+        // deleteProcessDAO(conn, pid, version, mprocess);
         createProcessDAO(conn, pid, version, mprocess);
     }
     
@@ -585,7 +586,7 @@
                         // GUIDS dont match, delete and create new
                         String errmsg = "ProcessDAO GUID " + old.getGuid() + " does not match " + mprocess.getGuid() + "; replacing.";
                         __log.debug(errmsg);
-                        old.delete();
+                        old.deleteProcessAndRoutes();
                     }
                 }
             }

Added: ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/ProcessCleanUpRunnable.java
URL: http://svn.apache.org/viewvc/ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/ProcessCleanUpRunnable.java?rev=781093&view=auto
==============================================================================
--- ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/ProcessCleanUpRunnable.java (added)
+++ ode/trunk/engine/src/main/java/org/apache/ode/bpel/engine/ProcessCleanUpRunnable.java Tue Jun  2 17:42:46 2009
@@ -0,0 +1,68 @@
+package org.apache.ode.bpel.engine;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.dao.DeferredProcessInstanceCleanable;
+import org.apache.ode.bpel.dao.ProcessDAO;
+import org.apache.ode.bpel.engine.BpelServerImpl.ContextsAware;
+import org.apache.ode.bpel.iapi.Scheduler.MapSerializableRunnable;
+
+public class ProcessCleanUpRunnable implements MapSerializableRunnable, ContextsAware {
+    private static final long serialVersionUID = 1L;
+
+    private static final Log __log = LogFactory.getLog(ProcessCleanUpRunnable.class);
+
+    public final static int PROCESS_CLEANUP_TRANSACTION_SIZE = Integer.getInteger("org.apache.ode.processInstanceDeletion.transactionSize", 10);
+    
+    private transient Contexts _contexts;
+    private transient Serializable _pid;
+
+    public ProcessCleanUpRunnable() {
+    }
+    
+    public ProcessCleanUpRunnable(Serializable pid) {
+        _pid = pid;
+    }
+
+    public void storeToDetailsMap(Map<String, Object> details) {
+        details.put("pid", _pid);
+    }
+    
+    public void restoreFromDetailsMap(Map<String, Object> details) {
+        _pid = (Serializable)details.get("pid");
+    }
+
+    public void setContexts(Contexts contexts) {
+        _contexts = contexts;
+    }
+    
+    public void run() {
+        if(__log.isDebugEnabled()) __log.debug("Deleting runtime data for old process: " + _pid + "...");
+        try {
+            // deleting of a process may involve hours' of database transaction, 
+            // we need to break it down to smaller transactions
+            int transactionResultSize = 0;
+            do {
+                transactionResultSize = _contexts.execTransaction(new Callable<Integer>() {
+                    public Integer call() throws Exception {
+                        ProcessDAO process = _contexts.dao.getConnection().createTransientProcess(_pid);
+                        if( !(process instanceof DeferredProcessInstanceCleanable) ) {
+                            throw new IllegalArgumentException("ProcessDAO does not implement DeferredProcessInstanceCleanable!!!");
+                        }
+                        return ((DeferredProcessInstanceCleanable)process).deleteInstances(PROCESS_CLEANUP_TRANSACTION_SIZE);
+                    }
+                });
+                if(__log.isDebugEnabled()) __log.debug("Deleted " + transactionResultSize + "instances for old process: " + _pid + ".");
+            } while( transactionResultSize == PROCESS_CLEANUP_TRANSACTION_SIZE );
+        } catch (RuntimeException re) {
+            throw re;
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }
+        if(__log.isInfoEnabled()) __log.info("Deleted runtime data for old process: " + _pid + ".");
+    }
+}
\ No newline at end of file



Mime
View raw message