Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/jbpm/workflow/log/impl/LogComponentImpl.java


1   package org.jbpm.workflow.log.impl;
2   
3   import java.util.*;
4   import net.sf.hibernate.type.*;
5   import org.apache.log4j.*;
6   import org.jbpm.util.client.*;
7   import org.jbpm.util.db.*;
8   import org.jbpm.workflow.execution.*;
9   import org.jbpm.workflow.execution.impl.*;
10  
11  public class LogComponentImpl {
12  
13    private LogComponentImpl() {
14    }
15  
16    /**
17     * gets the singleton instance.
18     */
19    public static LogComponentImpl getInstance() {
20      return instance;
21    }
22  
23    
24    private static final String queryFindAllProcessInstances =
25      "select distinct pi " +
26      "from pi in class org.jbpm.workflow.execution.impl.ProcessInstanceImpl," +
27      "     f in class org.jbpm.workflow.execution.impl.FlowImpl " + 
28      "where f.processInstance = pi ";
29  
30    public List findProcessInstances(Date startedAfter, Date startedBefore, String initiatorUserName, String actorUserName, Long processDefinitionId, Relations relations, DbSession dbSession) {
31      List processInstances = null;
32      String query = queryFindAllProcessInstances;
33      List parameters = new ArrayList();
34      List types = new ArrayList();
35  
36      if ( startedAfter != null ) {
37        query += "and pi.start > ? ";
38        parameters.add( startedAfter );
39        types.add( DbType.DATE );
40      }
41      
42      if ( startedBefore != null ) {
43        query += "and pi.start < ? ";
44        parameters.add( startedBefore );
45        types.add( DbType.DATE );
46      }
47      
48      if ( initiatorUserName != null ) {
49        query += "and pi.initiatorUserName = ? ";
50        parameters.add( initiatorUserName );
51        types.add( DbType.STRING );
52      }
53      
54      if ( actorUserName != null ) {
55        query += "and f.actorUserName = ? ";
56        parameters.add( actorUserName );
57        types.add( DbType.STRING );
58      }
59      
60      if ( processDefinitionId != null ) {
61        query += "and pi.processDefinition.id = ? ";
62        parameters.add( processDefinitionId );
63        types.add( DbType.LONG );
64      }
65      
66      query += "order by pi.start desc";
67      
68      log.debug( "query for searching process instances : '" + query  + "'");
69      
70      Object[] parameterArray = parameters.toArray();
71      Type[] typeArray = (Type[]) types.toArray( new Type[ types.size() ] );
72      
73      processInstances = dbSession.find( query, parameterArray, typeArray );
74      
75      if ( relations != null ) {
76        relations.resolve( processInstances );
77      }
78  
79      log.debug( "process instances : '" + processInstances  + "'");
80      
81      return processInstances;                                 
82    }
83    
84    public ProcessInstanceImpl getProcessInstance(Long processInstanceId, Relations relations, DbSession dbSession) {
85      ProcessInstanceImpl processInstance = null;
86      log.debug( "searching for process instances..." );
87      processInstance = (ProcessInstanceImpl) dbSession.load( ProcessInstanceImpl.class, processInstanceId );
88      resolve( (FlowImpl) processInstance.getRootFlow(), relations, dbSession );
89      return processInstance;
90    }
91  
92    private void resolve(FlowImpl flow, Relations relations, DbSession dbSession) {
93  
94      // resolve the flow 
95      if ( relations != null ) {
96        log.debug( "resolving relations : '" + relations + "' on flow '" + flow + "'" );
97        relations.resolve( flow );
98      }
99      
100     // resolve the flow-details 
101     Iterator iter = flow.getLogs().iterator();
102     while (iter.hasNext()) {
103       LogImpl logImpl = (LogImpl) iter.next();
104       Iterator detailsIter = logImpl.getDetails().iterator();
105       while (detailsIter.hasNext()) {
106         LogDetailImpl LogDetailImpl = (LogDetailImpl) detailsIter.next();
107         LogDetailImpl.resolve( dbSession );
108       }
109     }
110     
111     // resolve the attribute values
112     iter = flow.getAttributeInstances().iterator();
113     while (iter.hasNext()) {
114       AttributeInstanceImpl attributeInstance = (AttributeInstanceImpl) iter.next();
115       log.debug( "resolving attribute instance : " + attributeInstance.getValue() );
116     } 
117 
118     // resolve the child-flows 
119     iter = flow.getChildren().iterator();
120     while (iter.hasNext()) {
121       FlowImpl subFlow = (FlowImpl) iter.next();
122       resolve( subFlow, relations, dbSession );
123     } 
124 
125     // resolve the sub-process-flows 
126     ProcessInstance subProcessInstance = flow.getSubProcessInstance();
127     if ( subProcessInstance != null ) {
128       resolve( (FlowImpl) subProcessInstance.getRootFlow(), relations, dbSession );
129     }
130   }
131 
132   public FlowImpl getFlow(Long flowId, Relations relations, DbSession dbSession) {
133     FlowImpl flow = null;
134     log.debug( "searching for flow '" + flowId + "'..." );
135     flow = (FlowImpl) dbSession.load( FlowImpl.class, flowId );
136     resolve( flow, relations, dbSession );
137     return flow;
138   }
139 
140   private static final LogComponentImpl instance = new LogComponentImpl();
141   private static final Logger log = Logger.getLogger(LogComponentImpl.class);
142 }