Hi all, here is the solution for my problem, based on the other post:

I can now delete properly all ended processes, it works. This should exists by 
default.

package ****;
  | 
  | import java.util.Date;
  | import java.util.List;
  | 
  | import org.hibernate.Query;
  | import org.hibernate.Session;
  | import org.jboss.ejb3.annotation.Management;
  | import org.jboss.ejb3.annotation.Service;
  | import org.jbpm.JbpmConfiguration;
  | import org.jbpm.JbpmContext;
  | import org.jbpm.graph.exe.ProcessInstance;
  | 
  | @Service
  | @Management(JbpmManagementMBean.class)
  | public class JbpmManagement implements JbpmManagementMBean 
  | {
  |     JbpmConfiguration jBPMConfiguration = null;
  |     
  |     @SuppressWarnings("unchecked")
  |     @Override
  |     public void removeAllEndedProcesses()
  |     {
  |             if(jBPMConfiguration==null)
  |             {
  |                     jBPMConfiguration = JbpmConfiguration.getInstance();
  |             }
  |             JbpmContext context = jBPMConfiguration.createJbpmContext();
  |             
  |             try
  |             {
  |                     Session hibernateSession = context.getSession();
  |                     
  |                     Query processQuery = hibernateSession.createQuery(
  |                                     "from 
org.jbpm.graph.exe.ProcessInstance pi " +
  |                                     "where pi.end is not null");
  |                     
  |                     List<ProcessInstance> instances = processQuery.list();
  |                     
  |                     if(instances!=null&&instances.size()>0)
  |                     {
  |                             for(ProcessInstance instance : instances)
  |                             {
  |                                     
context.getGraphSession().deleteProcessInstance(instance);
  |                             }
  |                     }
  |             }
  |             finally 
  |             {
  |                     context.close();
  |             }
  |     }
  | 
  |     @SuppressWarnings("unchecked")
  |     @Override
  |     public void removeAllEndedProcessesBefore(Date date) 
  |     {
  |             if(jBPMConfiguration==null)
  |             {
  |                     jBPMConfiguration = JbpmConfiguration.getInstance();
  |             }
  |             JbpmContext context = jBPMConfiguration.createJbpmContext();
  |             
  |             try
  |             {
  |                     Session hibernateSession = context.getSession();
  |                     
  |                     Query processQuery = hibernateSession.createQuery(
  |                                     "from 
org.jbpm.graph.exe.ProcessInstance pi " +
  |                                     "where pi.end is not null" +
  |                                     "and pi.start < :removalDate");
  |                     
  |                     processQuery.setParameter("removalDate", date);
  |                     
  |                     List<ProcessInstance> instances = processQuery.list();
  |                     
  |                     if(instances!=null&&instances.size()>0)
  |                     {
  |                             for(ProcessInstance instance : instances)
  |                             {
  |                                     
context.getGraphSession().deleteProcessInstance(instance);
  |                             }
  |                     }
  |             }
  |             finally 
  |             {
  |                     context.close();
  |             }
  |     }
  | }

package ****;
  | 
  | import java.util.Date;
  | 
  | public interface JbpmManagementMBean
  | {
  |     public abstract void removeAllEndedProcesses();
  |     public abstract void removeAllEndedProcessesBefore(Date date);
  | }

Make a jar and put it in your deploy folder.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4221601#4221601

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4221601
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to