[jbpm-commits] JBoss JBPM SVN: r2528 - in projects/spec/trunk/modules/ri/src/main: java/org/jbpm/ri/runtime and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Oct 10 09:50:25 EDT 2008
Author: thomas.diesler at jboss.com
Date: 2008-10-10 09:50:25 -0400 (Fri, 10 Oct 2008)
New Revision: 2528
Added:
projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/SessionAssociation.java
projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/TransactionInterceptor.java
Modified:
projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/NodeImpl.java
projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ParticipantImpl.java
projects/spec/trunk/modules/ri/src/main/resources/jbpm-cfg-beans.xml
Log:
Execute the node in a Tx
Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/NodeImpl.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/NodeImpl.java 2008-10-10 12:01:01 UTC (rev 2527)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/NodeImpl.java 2008-10-10 13:50:25 UTC (rev 2528)
@@ -78,7 +78,6 @@
{
private static final long serialVersionUID = 1L;
- // provide logging
final static Logger log = LoggerFactory.getLogger(NodeImpl.class);
@Basic
Modified: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ParticipantImpl.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ParticipantImpl.java 2008-10-10 12:01:01 UTC (rev 2527)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/model/ParticipantImpl.java 2008-10-10 13:50:25 UTC (rev 2528)
@@ -45,8 +45,7 @@
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
- @SuppressWarnings("unused")
- private int id;
+ protected int id;
@Basic
protected String name;
@@ -65,6 +64,11 @@
this.name = otherImpl.name;
}
+ // Persistence ctor
+ protected ParticipantImpl()
+ {
+ }
+
@Override
public ObjectName getName()
{
Added: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/SessionAssociation.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/SessionAssociation.java (rev 0)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/SessionAssociation.java 2008-10-10 13:50:25 UTC (rev 2528)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.ri.runtime;
+
+//$Id$
+
+import org.hibernate.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Associates the Hibernate session with the current thread
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 10-Oct-2008
+ */
+public abstract class SessionAssociation
+{
+ final static Logger log = LoggerFactory.getLogger(SessionAssociation.class);
+
+ private static ThreadLocal<Session> sessionAssociation = new ThreadLocal<Session>();
+
+ public static Session getSession()
+ {
+ return sessionAssociation.get();
+ }
+
+ public static Session setSession(Session session)
+ {
+ sessionAssociation.set(session);
+ return session;
+ }
+
+ public static void closeSession(Session session)
+ {
+ if (session != getSession())
+ throw new IllegalArgumentException("Not the associated session");
+
+ // Close the session
+ try
+ {
+ session.close();
+ }
+ catch (RuntimeException rte)
+ {
+ log.error("Cannot close the associated session", rte);
+ }
+
+ sessionAssociation.remove();
+ }
+}
\ No newline at end of file
Property changes on: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/SessionAssociation.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/TransactionInterceptor.java
===================================================================
--- projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/TransactionInterceptor.java (rev 0)
+++ projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/TransactionInterceptor.java 2008-10-10 13:50:25 UTC (rev 2528)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.ri.runtime;
+
+//$Id$
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.jbpm.api.client.ProcessEngine;
+import org.jbpm.api.model.Node;
+import org.jbpm.api.service.PersistenceService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An interceptor that handles Node transactions
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 07-Oct-2008
+ */
+public class TransactionInterceptor implements NodeInterceptor
+{
+ final static Logger log = LoggerFactory.getLogger(TransactionInterceptor.class);
+
+ private PersistenceService service;
+
+ @Override
+ public void execute(RuntimeContext rtContext)
+ {
+ Node node = rtContext.getNode();
+
+ PersistenceService service = getPersistenceService(node.getProcessEngine());
+ Session session = SessionAssociation.setSession(service.createSession());
+
+ // Begin the Tx
+ Transaction tx = session.beginTransaction();
+ try
+ {
+ // Load the node
+ node = service.loadNode(session, node.getClass(), node.getKey());
+
+ // Call the next interceptor in the chain
+ rtContext.next();
+
+ // Save the node
+ service.saveNode(session, node);
+
+ // Commit the Tx
+ tx.commit();
+ }
+ catch (RuntimeException rte)
+ {
+ try
+ {
+ // Rollback the Tx
+ tx.rollback();
+ }
+ catch (RuntimeException rbex)
+ {
+ log.error("Cannot roll back transaction", rbex);
+ }
+ throw rte;
+ }
+ finally
+ {
+ SessionAssociation.closeSession(session);
+ }
+ }
+
+ private PersistenceService getPersistenceService(ProcessEngine engine)
+ {
+ if (service == null)
+ service = engine.getService(PersistenceService.class);
+
+ return service;
+ }
+}
\ No newline at end of file
Property changes on: projects/spec/trunk/modules/ri/src/main/java/org/jbpm/ri/runtime/TransactionInterceptor.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/spec/trunk/modules/ri/src/main/resources/jbpm-cfg-beans.xml
===================================================================
--- projects/spec/trunk/modules/ri/src/main/resources/jbpm-cfg-beans.xml 2008-10-10 12:01:01 UTC (rev 2527)
+++ projects/spec/trunk/modules/ri/src/main/resources/jbpm-cfg-beans.xml 2008-10-10 13:50:25 UTC (rev 2528)
@@ -60,6 +60,7 @@
<bean name="jBPMProcessService" class="org.jbpm.ri.service.ProcessServiceImpl" >
<property name="interceptors">
<list elementClass="java.lang.String">
+ <value>org.jbpm.ri.runtime.TransactionInterceptor</value>
<value>org.jbpm.ri.runtime.SignalHandlerInterceptor</value>
<value>org.jbpm.ri.runtime.FlowHandlerInterceptor</value>
<value>org.jbpm.ri.runtime.AssignmentInterceptor</value>
More information about the jbpm-commits
mailing list