[jbpm-commits] JBoss JBPM SVN: r5475 - jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Aug 13 06:22:26 EDT 2009
Author: tom.baeyens at jboss.com
Date: 2009-08-13 06:22:26 -0400 (Thu, 13 Aug 2009)
New Revision: 5475
Added:
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxCommand.java
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxTemplate.java
Removed:
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/HibernateLongIdTest2.java
Modified:
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/HibernateLongIdTest.java
Log:
JBPM-2474 Process variables of type hibernate-long-id/hibernate-string-id don't work: introduced template
Modified: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/HibernateLongIdTest.java
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/HibernateLongIdTest.java 2009-08-13 06:26:25 UTC (rev 5474)
+++ jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/HibernateLongIdTest.java 2009-08-13 10:22:26 UTC (rev 5475)
@@ -25,10 +25,8 @@
import java.util.List;
import java.util.Map;
+import org.hibernate.Session;
import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.classic.Session;
-import org.hibernate.context.ThreadLocalSessionContext;
import org.jbpm.api.ProcessInstance;
import org.jbpm.test.JbpmCustomCfgTestCase;
@@ -38,89 +36,73 @@
*/
public class HibernateLongIdTest extends JbpmCustomCfgTestCase {
- protected void deleteRegisteredDeployments() {
+ private TxTemplate txTemplate;
+
+ protected void setUp() throws Exception {
+ super.setUp();
SessionFactory sessionFactory = processEngine.get(SessionFactory.class);
-
- Session session = sessionFactory.openSession();
- Transaction transaction = session.beginTransaction();
- ThreadLocalSessionContext.bind(session);
+ this.txTemplate = new TxTemplate(sessionFactory);
+ }
- try {
- super.deleteRegisteredDeployments();
-
- List<Order> orders = session.createQuery("from "+Order.class.getName()).list();
- for (Order order: orders) {
- session.delete(order);
- }
+ protected void deleteRegisteredDeployments() {
+ txTemplate.execute(new TxCommand() {
+ public Object execute(Session session) {
+ for (String deploymentId : registeredDeployments) {
+ repositoryService.deleteDeploymentCascade(deploymentId);
+ }
- } finally {
- ThreadLocalSessionContext.unbind(sessionFactory);
- transaction.commit();
- session.close();
- }
+ List<Order> orders = session.createQuery("from "+Order.class.getName()).list();
+ for (Order order: orders) {
+ session.delete(order);
+ }
+
+ return null;
+ }
+ });
}
public void testHibernateLongId() {
- SessionFactory sessionFactory = processEngine.get(SessionFactory.class);
-
- Session session = sessionFactory.openSession();
- Transaction transaction = session.beginTransaction();
- ThreadLocalSessionContext.bind(session);
+ txTemplate.execute(new TxCommand() {
+ public Object execute(Session session) {
+ deployJpdlXmlString(
+ "<process name='HibernateLongId'>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a' />" +
+ "</process>"
+ );
+ return null;
+ }
+ });
- try {
- deployJpdlXmlString(
- "<process name='HibernateLongId'>" +
- " <start>" +
- " <transition to='a' />" +
- " </start>" +
- " <state name='a' />" +
- "</process>"
- );
- } finally {
- ThreadLocalSessionContext.unbind(sessionFactory);
- transaction.commit();
- session.close();
- }
-
- String processInstanceId;
+ String processInstanceId = (String) txTemplate.execute(new TxCommand() {
+ public Object execute(Session session) {
+ Order order = new Order();
+ order.setClient("Contador");
+ order.setProduct("Shampoo");
- session = sessionFactory.openSession();
- transaction = session.beginTransaction();
- ThreadLocalSessionContext.bind(session);
-
- try {
- Order order = new Order();
- order.setClient("Contador");
- order.setProduct("Shampoo");
-
- session.save(order);
- session.flush();
-
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put("order", order);
-
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("HibernateLongId", variables);
- processInstanceId = processInstance.getId();
-
- } finally {
- ThreadLocalSessionContext.unbind(sessionFactory);
- transaction.commit();
- session.close();
- }
-
- session = sessionFactory.openSession();
- transaction = session.beginTransaction();
- ThreadLocalSessionContext.bind(session);
+ session.save(order);
+ session.flush();
+
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("order", order);
- try {
- Order order = (Order) executionService.getVariable(processInstanceId, "order");
- assertNotNull(order);
- assertEquals("Contador", order.getClient());
- assertEquals("Shampoo", order.getProduct());
- } finally {
- ThreadLocalSessionContext.unbind(sessionFactory);
- transaction.commit();
- session.close();
- }
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("HibernateLongId", variables);
+ return processInstance.getId();
+ }
+ });
+
+ txTemplate.execute(new TxCommand() {
+ public Object execute(Session session) {
+ String processInstanceId = (String) params.get("processInstanceId");
+ Order order = (Order) executionService.getVariable(processInstanceId, "order");
+ assertNotNull(order);
+ assertEquals("Contador", order.getClient());
+ assertEquals("Shampoo", order.getProduct());
+ return null;
+ }
+ }.setParam("processInstanceId", processInstanceId)
+ );
}
}
Deleted: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/HibernateLongIdTest2.java
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/HibernateLongIdTest2.java 2009-08-13 06:26:25 UTC (rev 5474)
+++ jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/HibernateLongIdTest2.java 2009-08-13 10:22:26 UTC (rev 5475)
@@ -1,181 +0,0 @@
-/*
- * 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.test.hibernatelongid;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.hibernate.classic.Session;
-import org.jbpm.api.ProcessInstance;
-import org.jbpm.test.JbpmCustomCfgTestCase;
-
-
-/**
- * @author jbarrez
- */
-public class HibernateLongIdTest2 extends JbpmCustomCfgTestCase {
-
- private HibernateTemplate hibernateTemplate;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- SessionFactory sessionFactory = processEngine.get(SessionFactory.class);
- this.hibernateTemplate = new HibernateTemplate(sessionFactory);
- }
-
- protected void deleteRegisteredDeployments() {
-
- hibernateTemplate.execute(new VoidHibernateCallback() {
-
- public void executeNoReturn(Session session) {
-
- // cannot do super.x() in anonymous inner class method :-(
- // super.deleteRegisteredDeployments();
- // so we repeat the functionality ... for the moment
-
- for (String deploymentId : registeredDeployments) {
- repositoryService.deleteDeploymentCascade(deploymentId);
- }
-
- List<Order> orders = session.createQuery("from " + Order.class.getName()).list();
- for (Order order : orders) {
- session.delete(order);
- }
- }
-
- });
-
- }
-
- public void testHibernateLongId() {
-
- hibernateTemplate.execute(new VoidHibernateCallback() {
-
- public void executeNoReturn(Session session) {
- deployJpdlXmlString(
- "<process name='HibernateLongId'>" +
- " <start>" +
- " <transition to='a' />" +
- " </start>" +
- " <state name='a' />" +
- "</process>"
- );
- }
-
- });
-
- final String processInstanceId = (String) hibernateTemplate.execute(new HibernateCallback() {
-
- public Object execute(Session session) {
- Order order = new Order();
- order.setClient("Contador");
- order.setProduct("Shampoo");
-
- session.save(order);
- //session.flush();
-
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put("order", order);
-
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("HibernateLongId", variables);
- return processInstance.getId();
- }
-
- });
-
-
- hibernateTemplate.execute(new VoidHibernateCallback() {
-
- public void executeNoReturn(Session session) {
- Order order = (Order) executionService.getVariable(processInstanceId, "order");
- assertNotNull(order);
- assertEquals("Contador", order.getClient());
- assertEquals("Shampoo", order.getProduct());
- }
-
- });
- }
-
-
- // Quick template mechanism
- // This is just a quick draft!!!
-
- // Usage: hibernateTemplate.execute(new HibernateCallback() { ... });
- // or when no return value is needed: hibernateTemplate.execute(new VoidHibernateCallback() { })
-
-
- class HibernateTemplate {
-
- private SessionFactory sessionFactory;
-
- public HibernateTemplate(SessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
-
- public Object execute(HibernateCallback callback) {
- Session session = sessionFactory.openSession();
- Transaction transaction = session.beginTransaction();
- try {
- return callback.execute(session);
- } catch (Exception e) {
- transaction.rollback();
- } finally {
- if (!transaction.wasRolledBack()) {
- transaction.commit();
- }
- session.close();
- }
- return null;
- }
-
- public SessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- public void setSessionFactory(SessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
-
- }
-
- interface HibernateCallback {
-
- public Object execute(Session session);
-
- }
-
- abstract class VoidHibernateCallback implements HibernateCallback {
-
- public abstract void executeNoReturn(Session session);
-
- public Object execute(Session session) {
- executeNoReturn(session);
- return null;
- }
-
- }
-
-}
Added: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxCommand.java
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxCommand.java (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxCommand.java 2009-08-13 10:22:26 UTC (rev 5475)
@@ -0,0 +1,43 @@
+/*
+ * 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.test.hibernatelongid;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.hibernate.Session;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public abstract class TxCommand {
+
+ protected Map<String, Object> params = new HashMap<String, Object>();
+
+ public TxCommand setParam(String name, Object value) {
+ params.put(name, value);
+ return this;
+ }
+
+ public abstract Object execute(Session session);
+}
Property changes on: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxTemplate.java
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxTemplate.java (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxTemplate.java 2009-08-13 10:22:26 UTC (rev 5475)
@@ -0,0 +1,66 @@
+/*
+ * 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.test.hibernatelongid;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.classic.Session;
+import org.hibernate.context.ThreadLocalSessionContext;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TxTemplate {
+
+ private SessionFactory sessionFactory;
+
+ public TxTemplate(SessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
+
+ public Object execute(TxCommand txCommand) {
+ Session session = sessionFactory.openSession();
+ Transaction transaction = session.beginTransaction();
+ ThreadLocalSessionContext.bind(session);
+ try {
+ return txCommand.execute(session);
+ } catch (Exception e) {
+ transaction.rollback();
+ } finally {
+ ThreadLocalSessionContext.unbind(sessionFactory);
+ if (!transaction.wasRolledBack()) {
+ transaction.commit();
+ }
+ session.close();
+ }
+ return null;
+ }
+
+ public SessionFactory getSessionFactory() {
+ return sessionFactory;
+ }
+
+ public void setSessionFactory(SessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
+}
Property changes on: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/hibernatelongid/TxTemplate.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the jbpm-commits
mailing list