[Datasource Configuration] - I meet a problem when I use XA Transaction
by andy215
andy215 [https://community.jboss.org/people/andy215] created the discussion
"I meet a problem when I use XA Transaction"
To view the discussion, visit: https://community.jboss.org/message/717372#717372
--------------------------------------------------------------
I deployed oracle-xa-ds.xml, it looks like:
<datasources>
<xa-datasource>
<jndi-name>XAOracleDS</jndi-name>
<!-- uncomment to enable interleaving <interleaving/> -->
<isSameRM-override-value>false</isSameRM-override-value>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
<xa-datasource-property name="URL">jdbc:oracle:thin:@ip:port:test</xa-datasource-property>
<xa-datasource-property name="User">test</xa-datasource-property>
<xa-datasource-property name="Password">test</xa-datasource-property>
<!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
<!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
<!-- Checks the Oracle error codes and messages for fatal errors -->
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
<no-tx-separate-pools/>
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<!--
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
-->
</xa-datasource>
<mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"
name="jboss.jca:service=OracleXAExceptionFormatter">
<depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
</mbean>
</datasources>
I use EJB, my code looks like:
private EntityManager em;
public void greet(String message) {
GreetingEbo ebo = new GreetingEbo();
ebo.setGreeting(message);
em.persist(ebo);
}
When I invoke greet() api, there is a exception:
oracle.jdbc.xa.OracleXAException
at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1157)
at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:295)
at org.jboss.resource.adapter.jdbc.xa.XAManagedConnection.start(XAManagedConnection.java:213)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.enlistResource(TransactionImple.java:789)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.enlistResource(TransactionImple.java:500)
at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TransactionSynchronization.enlist(TxConnectionManager.java:908)
at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.enlist(TxConnectionManager.java:662)
at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:403)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.reconnectManagedConnection(BaseConnectionManager2.java:625)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:499)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:941)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:46)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:54)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2186)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2666)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:645)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:619)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:623)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
at org.jboss.jpa.tx.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:187)
at com.andy.proxy.EjbTestProxyBean.greet(EjbTestProxyBean.java:39)
I don't the root cause, anybody can give some help? thanks
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/717372#717372]
Start a new discussion in Datasource Configuration at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 10 months
[jBPM] - Eclipse Editor and defining Service Tasks
by Tim Kutz
Tim Kutz [https://community.jboss.org/people/tim.kutz] created the discussion
"Eclipse Editor and defining Service Tasks"
To view the discussion, visit: https://community.jboss.org/message/715301#715301
--------------------------------------------------------------
I am having difficulty with defining Service Tasks for the BPMN editor for Eclipse. I believe there is some form of conflict between the BPMN editor plugin, and something else in my Eclipse. We use a standard bundle of plugins for the development team, to ensure we are all using common versions of necessary plugins such as m2eclipse, and subclipse.
I have downloaded the 5.2 installer, and run the ant task "install.droolsjbpm-eclipse.into.eclipse" task, and the editor appears to be installed, with the ability to create a new bpmn process appearing as expected from the documentation. However, when I attempt to define a Service Task, following the directions in Chapter 13 of the User Guide, the editor gives me an error when starting up, which says: *Could not parse work definitions test.wid: java.util.HashMap cannot be cast to java.util.List*
There is a stack trace in my eclipse log file, as well:
!ENTRY org.drools.eclipse 4 120 2012-02-08 12:39:17.635
!MESSAGE Internal error in Drools Plugin:
!STACK 0
java.lang.RuntimeException: Could not parse work definitions test.wid: java.util.HashMap cannot be cast to java.util.List
at org.drools.RuleBaseConfiguration.loadWorkItems(RuleBaseConfiguration.java:806)
at org.drools.RuleBaseConfiguration.initWorkDefinitions(RuleBaseConfiguration.java:790)
at org.drools.RuleBaseConfiguration.getWorkDefinitions(RuleBaseConfiguration.java:765)
at org.drools.eclipse.WorkItemDefinitions.getWorkDefinitions(WorkItemDefinitions.java:67)
at org.drools.eclipse.WorkItemDefinitions.getWorkDefinitions(WorkItemDefinitions.java:50)
at org.drools.eclipse.flow.bpmn2.editor.BPMNModelEditor.refreshPalette(BPMNModelEditor.java:123)
at org.drools.eclipse.flow.bpmn2.editor.BPMNModelEditor.setInput(BPMNModelEditor.java:108)
at org.eclipse.gef.ui.parts.GraphicalEditor.init(GraphicalEditor.java:346)
at org.eclipse.ui.internal.EditorManager.createSite(EditorManager.java:798)
at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:647)
at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:465)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.EditorAreaHelper.setVisibleEditor(EditorAreaHelper.java:271)
at org.eclipse.ui.internal.EditorManager.setVisibleEditor(EditorManager.java:1429)
at org.eclipse.ui.internal.EditorManager$5.runWithException(EditorManager.java:942)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4041)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
at org.eclipse.ui.internal.Workbench$31.runWithException(Workbench.java:1567)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4041)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2548)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
at org.eclipse.equinox.launcher.Main.main(Main.java:1384)
I have also used the installer to download and install a full clean eclipse package using the install.demo.eclipse target, and the definition works as expected, there. This confirms that the .wid file itself is valid. However, that install is missing all of the other plugins needed for development in our standard development.
I am using Eclipse Helios, with m2eclipse 0.12, subclipse 1.6.17. Any assistance in making this work in our standard environment would be greatly appreciated.
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/715301#715301]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 10 months
[Beginner's Corner] - Jboss and Ejb with interceptors
by ninguno2
ninguno2 [https://community.jboss.org/people/ninguno2] created the discussion
"Jboss and Ejb with interceptors"
To view the discussion, visit: https://community.jboss.org/message/719733#719733
--------------------------------------------------------------
I'm using Jboss 4.2.3 + hibernate 3.3 with jta; Jboss is managing my hibernatesession, that I obtain with sessionFactory.getCurrentSession().
I have a session bean that has several mutually exclusive methods (when one is executing the other should be block). I implement and interceptor using a RecurrentLock to get this working (attached through annotations to the session bean), and is working almost fine.
But I need that this kind of "lock" interceptor is executed before the jta transacion starts and after the jta ends (and commit my hibernate changes), cause now is going the other way. Is there any way to get this working?
A simple schema if my problem it's not understood
Now
1-JTA tran. starts
2-Lock with custom interceptor
3-Ejb method called
4-Unlock with custom interceptor
5-jta tran. ends and commit changes.
I need
1-Lock with custom interceptor
2-JTA tran. starts
3-Ejb method called
4-jta tran. ends and commit changes.
5-Unlock with custom interceptor
Thanks in advance and sorry about me english!
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/719733#719733]
Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 10 months
[jBPM] - Service task exception with non-JTA transaction manager persistence and Tomcat
by navisdrools
navisdrools [https://community.jboss.org/people/navisdrools] created the discussion
"Service task exception with non-JTA transaction manager persistence and Tomcat"
To view the discussion, visit: https://community.jboss.org/message/715345#715345
--------------------------------------------------------------
I am integrating jbpm5 and drools into my company's product. I did a standalone prototype using Bitronix transcation manager with a simple work flow persisting into mysql. Script task, rule, event and service tasks all worked fine. Next I had to move this prototye into Spring and Tomcat. Bitronix did not work with the way we configured Tomcat. Finally, found a posting about using Spring transaction manager. Script task, rule, event and call activcity worked fine exception service task. If anyone could help would be appreciated. Here are my code.
Error
Hibernate: insert into SessionInfo (lastModificationDate, rulesByteArray, startDate, OPTLOCK) values (?, ?, ?, ?)
Session started ... session id = 4
Hibernate: insert into ProcessInstanceInfo (lastModificationDate, lastReadDate, processId, processInstanceByteArray, startDate, state, OPTLOCK) values (?, ?, ?, ?, ?, ?, ?)
Starting process id = 6
java.lang.NullPointerException
at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.internalExecuteWorkItem(JPAWorkItemManager.java:43)
at org.jbpm.workflow.instance.node.WorkItemNodeInstance.internalTrigger(WorkItemNodeInstance.java:105)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)
at org.jbpm.workflow.instance.node.ActionNodeInstance.triggerCompleted(ActionNodeInstance.java:55)
at org.jbpm.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:51)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)
at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)
at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)
at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)
at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:188)
at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:303)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:168)
at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:138)
at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1079)
at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:306)
at org.drools.command.runtime.process.StartProcessCommand.execute(StartProcessCommand.java:119)
at org.drools.command.runtime.process.StartProcessCommand.execute(StartProcessCommand.java:38)
at org.drools.command.impl.DefaultCommandService.execute(DefaultCommandService.java:36)
at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:345)
at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.startProcess(CommandBasedStatefulKnowledgeSession.java:223)
...
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
BPMN
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="Definition"
targetNamespace=" http://www.jboss.org/drools http://www.jboss.org/drools"
typeLanguage=" http://www.java.com/javaTypes http://www.java.com/javaTypes"
expressionLanguage=" http://www.mvel.org/2.0 http://www.mvel.org/2.0"
xmlns=" http://www.omg.org/spec/BPMN/20100524/MODEL http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.omg.org/spec/BPMN/20100524/MODEL http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
xmlns:g=" http://www.jboss.org/drools/flow/gpd http://www.jboss.org/drools/flow/gpd"
xmlns:bpmndi=" http://www.omg.org/spec/BPMN/20100524/DI http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc=" http://www.omg.org/spec/DD/20100524/DC http://www.omg.org/spec/DD/20100524/DC"
xmlns:di=" http://www.omg.org/spec/DD/20100524/DI http://www.omg.org/spec/DD/20100524/DI"
xmlns:tns=" http://www.jboss.org/drools http://www.jboss.org/drools">
<process processType="Private" isExecutable="true" id="com.navis.control.TestProcess" name="EventTest.b" >
<!-- nodes -->
<startEvent id="_1" name="Start" />
<endEvent id="_2" name="End" >
<terminateEventDefinition/>
</endEvent>
<scriptTask id="_3" name="Startup" >
<script>System.out.println("Starting process id = " + kcontext.getProcessInstance().getId());</script>
</scriptTask>
<scriptTask id="_4" name="Finish" >
<script>System.out.println("Resuming process id = " + kcontext.getProcessInstance().getId());
System.out.println("Waking Up from event");</script>
</scriptTask>
<task id="_5" name="WorkItem" tns:taskName="TestWorkItem" >
<ioSpecification>
<inputSet>
</inputSet>
<outputSet>
</outputSet>
</ioSpecification>
</task>
<intermediateCatchEvent id="_6" name="Signal" >
<signalEventDefinition signalRef="com.navis.control.TestEvent"/>
</intermediateCatchEvent>
<scriptTask id="_7" name="Sleep" >
<script>System.out.println("Going to sleep");</script>
</scriptTask>
<!-- connections -->
<sequenceFlow id="_4-_2" sourceRef="_4" targetRef="_2" />
<sequenceFlow id="_1-_3" sourceRef="_1" targetRef="_3" />
<sequenceFlow id="_6-_4" sourceRef="_6" targetRef="_4" />
<sequenceFlow id="_3-_5" sourceRef="_3" targetRef="_5" />
<sequenceFlow id="_7-_6" sourceRef="_7" targetRef="_6" />
<sequenceFlow id="_5-_7" sourceRef="_5" targetRef="_7" />
</process>
<bpmndi:BPMNDiagram>
<bpmndi:BPMNPlane bpmnElement="com.navis.control.TestProcess" >
<bpmndi:BPMNShape bpmnElement="_1" >
<dc:Bounds x="46" y="110" width="48" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_2" >
<dc:Bounds x="741" y="111" width="48" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_3" >
<dc:Bounds x="125" y="111" width="80" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_4" >
<dc:Bounds x="606" y="111" width="80" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_5" >
<dc:Bounds x="247" y="110" width="100" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_6" >
<dc:Bounds x="507" y="111" width="48" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_7" >
<dc:Bounds x="385" y="111" width="80" height="48" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_4-_2" >
<di:waypoint x="646" y="135" />
<di:waypoint x="765" y="135" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_1-_3" >
<di:waypoint x="70" y="134" />
<di:waypoint x="165" y="135" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_6-_4" >
<di:waypoint x="531" y="135" />
<di:waypoint x="646" y="135" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_3-_5" >
<di:waypoint x="165" y="135" />
<di:waypoint x="297" y="134" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_7-_6" >
<di:waypoint x="425" y="135" />
<di:waypoint x="531" y="135" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_5-_7" >
<di:waypoint x="297" y="134" />
<di:waypoint x="425" y="135" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
JAVA
package com.navis.control;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.persistence.jpa.JPAKnowledgeService;
import org.drools.runtime.Environment;
import org.drools.runtime.EnvironmentName;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
/**
* This is a sample file to launch a process.
*/
public class ProcessTest {
public static final void main(String[] args) {
ProcessTest pt = new ProcessTest();
pt.execute();
}
public String execute() {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
// create session
StatefulKnowledgeSession ksession = initSession(kbase);
int sid = ksession.getId();
System.out.println("Session started ... session id = " + sid);
// init logger
KnowledgeRuntimeLogger logger = initLogger(ksession);
// register Work Item Handler
registerHandler(ksession);
// start a new process instance
Map<String, Object> parm = new HashMap<String, Object>();
parm.put("id", 1);
ProcessInstance pi = ksession.startProcess(
"com.navis.control.TestProcess", parm);
long pid = pi.getId();
System.out.println("Process started ... process id = " + pid);
// restart process
// sendEvent(pid, kbase, env);
ksession.dispose();
logger.close();
return "Success";
} catch (Throwable t) {
t.printStackTrace();
return "Exception occurred";
}
}
private KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("data/EventTest.bpmn"),
ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}
private StatefulKnowledgeSession initSession(KnowledgeBase kbase) {
try {
// create the entity manager factory and register it in the
// environment
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("org.jbpm.persistence.jpa");
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER,
new org.springframework.orm.jpa.JpaTransactionManager(emf));
// load up the knowledge base
// StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
StatefulKnowledgeSession ksession = JPAKnowledgeService
.newStatefulKnowledgeSession(kbase, null, env);
return ksession;
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
private KnowledgeRuntimeLogger initLogger(StatefulKnowledgeSession ksession) {
try {
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
.newThreadedFileLogger(ksession, "test", 1000);
return logger;
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
private void registerHandler(StatefulKnowledgeSession ksession) {
try {
ksession.getWorkItemManager().registerWorkItemHandler(
"TestWorkItem", new TestHandler());
} catch (Throwable t) {
t.printStackTrace();
}
}
}
/*
* Copyright (c) 2012 Navis LLC. All Rights Reserved.
*
*/
package com.navis.control;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.persistence.jpa.JPAKnowledgeService;
import org.drools.runtime.Environment;
import org.drools.runtime.EnvironmentName;
import org.drools.runtime.StatefulKnowledgeSession;
/**
* This is a sample file to launch a process.
*/
public class ProcessTest2 {
public static final void main(String[] args) {
ProcessTest2 pt = new ProcessTest2();
pt.execute();
}
public String execute() {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
// create session
Environment env = initEnv();
// init logger
int sid=21;
StatefulKnowledgeSession ksession=loadSession(sid, kbase, env);
KnowledgeRuntimeLogger logger = initLogger(ksession);
// register Work Item Handler
registerHandler(ksession);
//restart process
long pid=28;
sendEvent(ksession, pid);
ksession.dispose();
logger.close();
return "Success";
} catch (Throwable t) {
t.printStackTrace();
return "Exception occurred";
}
}
private static void sendEvent(StatefulKnowledgeSession ksession, long pid) {
TestEvent testEvent = new TestEvent();
testEvent.setId(pid);
System.out.println("Sending Event ...");
ksession.signalEvent("com.navis.control.TestEvent", testEvent, pid);
System.out.println("Event sent ...");
ksession.halt();
ksession.dispose();
}
private KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("EventTest.bpmn"),
ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}
private Environment initEnv() {
try {
// create the entity manager factory and register it in the
// environment
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("org.jbpm.persistence.jpa");
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER,
new org.springframework.orm.jpa.JpaTransactionManager(emf));
// load up the knowledge base
return env;
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
private StatefulKnowledgeSession loadSession(int sid, KnowledgeBase kbase, Environment env) {
try {
StatefulKnowledgeSession ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sid, kbase, null, env);
System.out.println("Retreiving session ... id = " + ksession.getId());
return ksession;
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
private KnowledgeRuntimeLogger initLogger(StatefulKnowledgeSession ksession) {
try {
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
.newThreadedFileLogger(ksession, "test", 1000);
return logger;
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
private void registerHandler(StatefulKnowledgeSession ksession) {
try {
ksession.getWorkItemManager().registerWorkItemHandler(
"TestWorkItem", new TestHandler());
} catch (Throwable t) {
t.printStackTrace();
}
}
}
/*
* Copyright (c) 2012 Navis LLC. All Rights Reserved.
*
*/
package com.navis.control;
import org.drools.runtime.process.WorkItem;
import org.drools.runtime.process.WorkItemHandler;
import org.drools.runtime.process.WorkItemManager;
import java.io.Serializable;
public class TestHandler implements WorkItemHandler, Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println(">>>>>>>Inside work item handler");
manager.completeWorkItem(workItem.getId(), null);
System.out.println(">>>>>>>work item completed");
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
}
package com.navis.control;
import java.io.Serializable;
public class TestEvent implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3789036281504593218L;
/**
*
*/
private long id;
private String name;
public void setId(long id) {
this.id = id;
}
public long getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
PERSISTENCE
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="1.0"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
xmlns:orm=" http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm" xmlns=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence">
<persistence-unit name="org.jbpm.persistence.jpa"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:comp/env/jdbc/jbpmDS</non-jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
DATASOURCE
<Resource auth="Container" name="jdbc/jbpmDS" type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver" password="mnrpass" username="mnr"
testOnBorrow="true" validationQuery="select 1"
maxActive="25" maxIdle="10" maxWait="12000"
initialSize="6"
url="jdbc:mysql://localhost/apex?autoReconnect=true&useLegacyDatetimeCode=false" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"/>
WEB.XML
<resource-ref>
<res-ref-name>jdbc/apexDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
</resource-ref>
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/715345#715345]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&con...]
12 years, 11 months