[jbpm-commits] JBoss JBPM SVN: r4872 - in jbpm4/trunk: modules/api/src/main/java/org/jbpm/api and 17 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri May 22 05:58:21 EDT 2009
Author: ainze
Date: 2009-05-22 05:58:21 -0400 (Fri, 22 May 2009)
New Revision: 4872
Added:
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/applicationContext.xml
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java
jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/
jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/
jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/applicationContext.xml
jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/
jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/applicationContext.xml
jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
Removed:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/HibernateSessionManager.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironmentContext.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java
jbpm4/trunk/modules/examples/pom.xml
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/CommandTransactionCallback.java
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
jbpm4/trunk/modules/test-db/pom.xml
jbpm4/trunk/pom.xml
Log:
spring integration - initial release
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -60,8 +60,8 @@
implementationClassNames = new HashMap<String, String>();
// null represents the default configuration (== the JbpmConfiguration)
implementationClassNames.put(null, "org.jbpm.pvm.internal.cfg.JbpmConfiguration");
+ implementationClassNames.put("spring-test", "org.jbpm.pvm.internal.cfg.SpringConfiguration");
// TODO
- // implementationClasses.put("spring", "org.jbpm.pvm.internal.cfg.SpringConfiguration");
// implementationClasses.put("mc", "org.jbpm.pvm.internal.cfg.McConfiguration");
// implementationClasses.put("programatic", "org.jbpm.pvm.internal.cfg.ProgramaticConfiguration");
}
Modified: jbpm4/trunk/modules/examples/pom.xml
===================================================================
--- jbpm4/trunk/modules/examples/pom.xml 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/examples/pom.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -69,6 +69,12 @@
<groupId>org.subethamail</groupId>
<artifactId>subethasmtp-wiser</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/applicationContext.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/applicationContext.xml (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/applicationContext.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
+
+ <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
+ <property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />
+ <!-- A best practice should be to keep split the config into multiple files
+ <property name="configLocations" value="hibernate.cfg.xml, hibernate.jbpm.cfg.xml" />
+ -->
+ </bean>
+
+ <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
+ <property name="sessionFactory" ref="sessionFactory" />
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+ <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
+ <property name="url" value="jdbc:hsqldb:mem:." />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </bean>
+</beans>
\ No newline at end of file
Property changes on: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/applicationContext.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration>
+
+ <import resource="jbpm.default.cfg.xml" />
+
+ <import resource="jbpm.jpdl.cfg.xml" />
+ <import resource="jbpm.identity.cfg.xml" />
+
+ <!-- Job executor is excluded for running the example test cases. -->
+ <!-- To enable timers and messages in production use, this should be included. -->
+ <!--
+ <import resource="jbpm.jobexecutor.cfg.xml" />
+ -->
+
+ <import resource="jbpm.mail.templates.examples.xml" />
+
+ <process-engine-context>
+ <command-service>
+ <retry-interceptor />
+ <environment-interceptor />
+ <spring-transaction-interceptor />
+ </command-service>
+ </process-engine-context>
+
+ <transaction-context>
+ <transaction />
+ <hibernate-session />
+ </transaction-context>
+
+</jbpm-configuration>
Property changes on: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -21,85 +21,147 @@
*/
package org.jbpm.pvm.internal.cfg;
-import java.util.HashSet;
+import java.io.IOException;
import java.util.List;
-import java.util.Set;
+import org.jbpm.api.ProcessEngine;
+import org.jbpm.api.env.Context;
import org.jbpm.api.env.Environment;
import org.jbpm.api.env.EnvironmentFactory;
import org.jbpm.api.env.WireObject;
-import org.jbpm.pvm.internal.spring.SpringEnvironment;
-import org.jbpm.pvm.internal.util.ReflectUtil;
+import org.jbpm.pvm.internal.env.PvmEnvironment;
+import org.jbpm.pvm.internal.env.SpringContext;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.core.io.ClassPathResource;
-/** this environment factory will see only the singleton beans.
+/**
+ * this environment factory will see only the singleton beans.
*
- * The created {@link SpringEnvironment}s will see the prototype
- * beans and it will cache them.
- *
- * @author Tom Baeyens
+ * The created {@link SpringEnvironment}s will see the prototype beans and it
+ * will cache them.
+ *
+ * @author Andries Inze
*/
-public class SpringConfiguration implements EnvironmentFactory, ApplicationContextAware {
-
- // TODO pull up the common behaviour between this class and the SpringEnvironmentContext
-
- private static final long serialVersionUID = 1L;
-
- ApplicationContext applicationContext;
-
- public SpringEnvironment openEnvironment() {
- return new SpringEnvironment(this);
- }
+public class SpringConfiguration extends JbpmConfiguration implements
+ EnvironmentFactory, ProcessEngine, ApplicationContextAware {
- public boolean has(String key) {
- return applicationContext.isSingleton(key);
- }
+ private static final long serialVersionUID = 1L;
- public Object get(String key) {
- if (has(key)) {
- return applicationContext.getBean(key);
+ private ApplicationContext applicationContext;
+
+ private String jbpmConfigurationLocation;
+
+ /**
+ * Instantiates a new spring configuration.
+ */
+ public SpringConfiguration(String jbpmConfigurationLocation) {
+ try {
+ super.setInputStream(new ClassPathResource(
+ jbpmConfigurationLocation).getInputStream());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
- return null;
- }
- public <T> T get(Class<T> type) {
- String name = ReflectUtil.getUnqualifiedClassName(type);
- name = name.substring(0, 1).toLowerCase() + name.substring(1);
- return (T) get(name);
- }
+ public SpringConfiguration() {
+ // By jbpmTestCase
+ }
- public Set<String> keys() {
- HashSet<String> keys = new HashSet<String>();
- for (String key : applicationContext.getBeanDefinitionNames()) {
- if (has(key)) {
- keys.add(key);
- }
+ @Override
+ public ProcessEngine buildProcessEngine() {
+ if (applicationContext == null) {
+ applicationContext = new ClassPathXmlApplicationContext(System
+ .getProperty("jbpm.test.cfg.applicationContext"));
+ }
+
+ return super.buildProcessEngine();
}
- return keys;
- }
-
- public ApplicationContext getApplicationContext() {
- return applicationContext;
- }
- public void setApplicationContext(ApplicationContext applicationContext) {
- this.applicationContext = applicationContext;
- }
+ /**
+ * {@inheritDoc)
-
- public void close() {
- }
+ */
+ @Override
+ public Environment openEnvironment(List<WireObject> txWireObjects) {
- public String getName() {
- return null;
- }
+ PvmEnvironment environment = new PvmEnvironment(this);
- public Object set(String key, Object value) {
- return null;
- }
+ // FIXME: All beneath should be a super call
- public Environment openEnvironment(List<WireObject> txWireObjects) {
- return null;
- }
+ // set the classloader
+ ClassLoader classLoader = processEngineWireContext.getClassLoader();
+ if (classLoader != null) {
+ environment.setClassLoader(classLoader);
+ }
+
+ // add the process-engine context
+ environment.addContext(new SpringContext(applicationContext));
+ environment.addContext(processEngineWireContext);
+
+ // add the transaction context
+ WireDefinition usedWireDefinition = transactionWireDefinition;
+ if (txWireObjects != null) {
+ usedWireDefinition = new WireDefinition(transactionWireDefinition,
+ txWireObjects);
+ }
+
+ WireContext transactionContext = new WireContext(usedWireDefinition,
+ Context.CONTEXTNAME_TRANSACTION, environment, true);
+ // add the environment block context to the environment
+ environment.addContext(transactionContext);
+
+ Environment.pushEnvironment(environment);
+ try {
+ // finish the creation of the environment wire context
+ transactionContext.create();
+
+ } catch (RuntimeException e) {
+ Environment.popEnvironment();
+ throw e;
+ }
+
+ // if all went well, return the created environment
+ return environment;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T get(Class<T> type) {
+ String[] names = applicationContext.getBeanNamesForType(type);
+ if (names.length == 1) {
+ return (T) applicationContext.getBean(names[0]);
+ }
+
+ return super.get(type);
+ }
+
+ @Override
+ public Object get(String key) {
+ if (applicationContext.containsBean(key)) {
+ return applicationContext.getBean(key);
+ }
+
+ return super.get(key);
+ }
+
+ /**
+ * {@inheritDoc)
+
+ */
+ public void setApplicationContext(ApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ }
+
+ /**
+ * Gets the application context.
+ *
+ * @return the application context
+ */
+ public ApplicationContext getApplicationContext() {
+ return applicationContext;
+ }
}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -0,0 +1,101 @@
+/*
+ * 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.pvm.internal.env;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jbpm.api.env.Context;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * @author Andries Inze
+ *
+ */
+public class SpringContext implements Context {
+
+ private ApplicationContext applicationContext;
+
+ public SpringContext(ApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jbpm.api.env.Context#get(java.lang.String)
+ */
+ public Object get(String key) {
+ if (applicationContext.containsBean(key)) {
+ return applicationContext.getBean(key);
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T get(Class<T> type) {
+ String[] names = applicationContext.getBeanNamesForType(type);
+ if (names.length == 1) {
+ return (T) applicationContext.getBean(names[0]);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jbpm.api.env.Context#getName()
+ */
+ public String getName() {
+ return "SpringContext";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jbpm.api.env.Context#has(java.lang.String)
+ */
+ public boolean has(String key) {
+ return applicationContext.containsBean(key);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jbpm.api.env.Context#keys()
+ */
+ public Set<String> keys() {
+ Set set = new HashSet<String>(Arrays.asList(applicationContext.getBeanDefinitionNames()));
+ return set;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jbpm.api.env.Context#set(java.lang.String, java.lang.Object)
+ */
+ public Object set(String key, Object value) {
+ throw new RuntimeException("Can't add to the spring context");
+ }
+
+}
Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/CommandTransactionCallback.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/CommandTransactionCallback.java 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/CommandTransactionCallback.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -22,33 +22,31 @@
package org.jbpm.pvm.internal.spring;
import org.jbpm.api.cmd.Command;
-import org.jbpm.api.env.Environment;
-import org.jbpm.api.env.EnvironmentFactory;
+import org.jbpm.api.cmd.CommandService;
+import org.springframework.orm.hibernate3.HibernateTransactionManager;
+import org.springframework.orm.hibernate3.SessionFactoryUtils;
+import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.util.Assert;
/**
- * @author Tom Baeyens
+ * @author Andries Inze
*/
public class CommandTransactionCallback<T> implements TransactionCallback {
-
- Command<T> command;
- EnvironmentFactory environmentFactory;
-
- public CommandTransactionCallback(Command<T> command, EnvironmentFactory environmentFactory) {
- this.command = command;
- this.environmentFactory = environmentFactory;
- }
- public T doInTransaction(TransactionStatus status) {
- Environment environment = environmentFactory.openEnvironment();
- try {
- return command.execute(environment);
- } catch (Exception e) {
- throw new RuntimeException("ooops", e);
- } finally {
- environment.close();
+ private Command<T> command;
+ private CommandService commandService;
+ private PlatformTransactionManager manager;
+
+ public CommandTransactionCallback(Command<T> command,
+ CommandService commandService, PlatformTransactionManager platformTransactionManager) {
+ this.command = command;
+ this.commandService = commandService;
+ this.manager = platformTransactionManager;
}
- }
+ public T doInTransaction(TransactionStatus status) {
+ return commandService.execute(command);
+ }
}
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/HibernateSessionManager.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/HibernateSessionManager.java 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/HibernateSessionManager.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -1,30 +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.pvm.internal.spring;
-
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-
-/**
- * @author Tom Baeyens
- */
-public class HibernateSessionManager extends HibernateDaoSupport {
-}
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -1,58 +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.pvm.internal.spring;
-
-import org.hibernate.Session;
-import org.jbpm.api.cmd.Command;
-import org.jbpm.api.cmd.CommandService;
-import org.jbpm.api.env.Environment;
-import org.jbpm.api.env.EnvironmentFactory;
-import org.springframework.orm.hibernate3.HibernateTransactionManager;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-import org.springframework.transaction.support.TransactionTemplate;
-
-
-/**
- * @author Tom Baeyens
- */
-public class SpringCommandService implements CommandService {
-
- TransactionTemplate transactionTemplate;
- EnvironmentFactory environmentFactory;
-
- public void setEnvironmentFactory(EnvironmentFactory environmentFactory) {
- this.environmentFactory = environmentFactory;
- }
-
- public void setTransactionManager(HibernateTransactionManager transactionManager) {
- this.transactionTemplate = new TransactionTemplate(transactionManager);
- }
-
- public <T> T execute(Command<T> command) {
- return (T) transactionTemplate.execute(
- new CommandTransactionCallback(command, environmentFactory)
- );
- }
-
-
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -1,70 +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.pvm.internal.spring;
-
-import org.jbpm.api.env.EnvironmentFactory;
-import org.jbpm.pvm.internal.cfg.SpringConfiguration;
-import org.jbpm.pvm.internal.env.BasicEnvironment;
-import org.springframework.context.ApplicationContext;
-
-/** sees the prototype beans in the application context and
- * this environment will cache all the prototyped objects.
- *
- * @author Tom Baeyens
- */
-public class SpringEnvironment extends BasicEnvironment {
-
- private static final long serialVersionUID = 1L;
-
- protected ApplicationContext applicationContext;
-
- public SpringEnvironment(SpringConfiguration springConfiguration) {
- addContext(springConfiguration);
- addContext(new SpringEnvironmentContext(springConfiguration.getApplicationContext()));
- pushEnvironment(this);
- }
-
- public ClassLoader getClassLoader() {
- return null;
- }
-
- public EnvironmentFactory getEnvironmentFactory() {
- return null;
- }
-
- public Throwable getException() {
- return null;
- }
-
- public String getUserId() {
- return null;
- }
-
- public void setClassLoader(ClassLoader classLoader) {
- }
-
- public void setException(Throwable exception) {
- }
-
- public void setUserId(String userId) {
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironmentContext.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironmentContext.java 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironmentContext.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -1,98 +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.pvm.internal.spring;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.jbpm.api.env.Context;
-import org.jbpm.api.env.Environment;
-import org.jbpm.pvm.internal.util.ReflectUtil;
-import org.springframework.context.ApplicationContext;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-
-
-/**
- * @author Tom Baeyens
- */
-public class SpringEnvironmentContext implements Context {
-
- // TODO pull up the common behaviour between this class and the SpringEnvironmentFactory
-
- ApplicationContext applicationContext;
- Map<String, Object> cache = new HashMap<String, Object>();
-
- public SpringEnvironmentContext(ApplicationContext applicationContext) {
- this.applicationContext = applicationContext;
- }
-
- public boolean has(String key) {
- return applicationContext.isPrototype(key);
- }
-
- public Object get(String key) {
- if (cache.containsKey(key)) {
- return cache.get(key);
- }
- if (has(key)) {
- Object bean = applicationContext.getBean(key);
- // cache.put(key, bean);
- return bean;
- }
- return null;
- }
-
- public <T> T get(Class<T> type) {
- String name = ReflectUtil.getUnqualifiedClassName(type);
- name = name.substring(0, 1).toLowerCase() + name.substring(1);
- return (T) get(name);
- }
-
- public Set<String> keys() {
- HashSet<String> keys = new HashSet<String>();
- for (String key : applicationContext.getBeanDefinitionNames()) {
- if (has(key)) {
- keys.add(key);
- }
- }
- return keys;
- }
-
- public ApplicationContext getApplicationContext() {
- return applicationContext;
- }
-
- public void setApplicationContext(ApplicationContext applicationContext) {
- this.applicationContext = applicationContext;
- }
-
-
- public String getName() {
- return null;
- }
-
- public Object set(String key, Object value) {
- return null;
- }
-}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -0,0 +1,95 @@
+/*
+ * 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.pvm.internal.tx;
+
+import org.hibernate.Session;
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.env.Environment;
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.spring.CommandTransactionCallback;
+import org.jbpm.pvm.internal.svc.Interceptor;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.support.DefaultTransactionDefinition;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+
+/**
+ * calls setRollbackOnly on the transaction in the environment in case an
+ * exception occurs during execution of the command.
+ *
+ * @author Andries Inze
+ */
+public class SpringTransactionInterceptor extends Interceptor {
+
+ private static final Log log = Log.getLog(SpringTransactionInterceptor.class.getName());
+
+ private boolean useCurrent;
+
+ @SuppressWarnings("unchecked")
+ public <T> T execute(Command<T> command) {
+ Environment environment = Environment.getCurrent();
+ if (environment == null) {
+ throw new JbpmException("no environment for managing hibernate transaction");
+ }
+
+ StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+ if (standardTransaction == null) {
+ throw new JbpmException("no standard-transaction in environment");
+ }
+
+ PlatformTransactionManager platformTransactionManager = environment.get(PlatformTransactionManager.class);
+ if (platformTransactionManager == null) {
+ throw new JbpmException("No platformTransaction manager defined.");
+ }
+
+
+ standardTransaction.begin();
+
+ try {
+ DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
+
+ if (useCurrent) {
+ definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_MANDATORY);
+ }
+
+ TransactionTemplate template = new TransactionTemplate(platformTransactionManager, definition);
+ TransactionCallback transactionCallback = new CommandTransactionCallback<T>(command, next, platformTransactionManager);
+ T t = (T) template.execute(transactionCallback);
+
+ Session session = environment.get(Session.class);
+ session.flush();
+ return t;
+ } catch (RuntimeException e) {
+ standardTransaction.setRollbackOnly();
+ throw e;
+
+ } finally {
+ standardTransaction.complete();
+ }
+ }
+
+ public void setUseCurrent(Boolean useCurrent) {
+ this.useCurrent = useCurrent;
+ }
+}
Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -0,0 +1,55 @@
+/*
+ * 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.pvm.internal.wire.binding;
+
+import org.jbpm.pvm.internal.tx.SpringTransactionInterceptor;
+import org.jbpm.pvm.internal.tx.StandardTransactionInterceptor;
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.wire.descriptor.ProvidedObjectDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+/** parses a descriptor for creating a {@link StandardTransactionInterceptor}.
+ *
+ * See schema docs for more details.
+ *
+ * @author Tom Baeyens
+ */
+public class SpringTransactionInterceptorBinding extends WireInterceptorBinding {
+
+ public SpringTransactionInterceptorBinding() {
+ super("spring-transaction-interceptor");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+ SpringTransactionInterceptor springTransactionInterceptor = new SpringTransactionInterceptor();
+
+ Boolean useCurrent = XmlUtil.attributeBoolean(element, "current", false, parse);
+ if (useCurrent!=null) {
+ // set it accordingly
+ springTransactionInterceptor.setUseCurrent(useCurrent);
+ }
+
+ return new ProvidedObjectDescriptor(springTransactionInterceptor);
+ }
+}
Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -98,5 +98,8 @@
<!-- jpdl bindings -->
<binding class="org.jbpm.jpdl.internal.xml.JpdlDeployerBinding" />
+
+ <!-- spring bindings -->
+ <binding class="org.jbpm.pvm.internal.wire.binding.SpringTransactionInterceptorBinding" />
</wire-bindings>
Added: jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/applicationContext.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/applicationContext.xml (rev 0)
+++ jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/applicationContext.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
+
+ <bean id="testSF" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
+ <property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />
+ <!-- A best practice should be to keep split the config into multiple files
+ <property name="configLocations" value="hibernate.cfg.xml, hibernate.jbpm.cfg.xml" />
+ -->
+ </bean>
+
+ <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
+ <property name="sessionFactory" ref="testSF" />
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+ <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
+ <property name="url" value="jdbc:hsqldb:mem:." />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </bean>
+</beans>
\ No newline at end of file
Property changes on: jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/applicationContext.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml (rev 0)
+++ jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration xmlns="http://jbpm.org/xsd/cfg">
+
+ <process-engine-context>
+
+ <repository-service />
+ <repository-cache />
+ <execution-service />
+ <history-service />
+ <management-service />
+ <task-service />
+ <identity-service />
+ <command-service>
+ <retry-interceptor />
+ <environment-interceptor />
+ <spring-transaction-interceptor />
+ </command-service>
+
+ <hibernate-configuration>
+ <cfg resource="jbpm.hibernate.cfg.xml" />
+ </hibernate-configuration>
+
+
+ <script-manager default-expression-language="juel"
+ default-script-language="juel"
+ read-contexts="execution, environment, process-engine"
+ write-context="">
+ <script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
+ </script-manager>
+
+ <authentication />
+
+ <job-executor auto-start="false" />
+
+ <id-generator />
+ <types resource="jbpm.variable.types.xml" />
+
+ <business-calendar>
+ <monday hours="9:00-12:00 and 12:30-17:00"/>
+ <tuesday hours="9:00-12:00 and 12:30-17:00"/>
+ <wednesday hours="9:00-12:00 and 12:30-17:00"/>
+ <thursday hours="9:00-12:00 and 12:30-17:00"/>
+ <friday hours="9:00-12:00 and 12:30-17:00"/>
+ <holiday period="01/07/2008 - 31/08/2008"/>
+ </business-calendar>
+
+ </process-engine-context>
+
+ <transaction-context>
+ <repository-session />
+ <pvm-db-session />
+ <job-db-session />
+ <task-db-session />
+ <message-session />
+ <timer-session />
+ <history-session />
+ <hibernate-session />
+ <transaction />
+ <identity-session />
+ </transaction-context>
+
+</jbpm-configuration>
Property changes on: jbpm4/trunk/modules/pvm/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java 2009-05-22 09:58:21 UTC (rev 4872)
@@ -1,194 +1,201 @@
-/*
- * 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;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.hibernate.Hibernate;
-import org.hibernate.SQLQuery;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.mapping.ForeignKey;
-import org.hibernate.mapping.Table;
-import org.jbpm.api.ProcessEngine;
-import org.jbpm.api.env.EnvironmentFactory;
-import org.jbpm.internal.log.Log;
-
-
-/**
- * @author Tom Baeyens
- */
-public class Db {
-
- private static final Log log = Log.getLog(Db.class.getName());
-
- private static final String TABLE_NAMES_KEY = "tableNames";
- private static final String CLEAN_SQL_KEY = "cleanSql";
-
- public static void clean(ProcessEngine processEngine) {
- clean((EnvironmentFactory) processEngine);
- }
-
- public static void verifyClean(ProcessEngine processEngine) {
- verifyClean((EnvironmentFactory) processEngine);
- }
-
- public static void clean(EnvironmentFactory environmentFactory) {
- SessionFactory sessionFactory = environmentFactory.get(SessionFactory.class);
- // when running this with a remote ejb invocation configuration, there is no
- // session factory and no cleanup needs to be done
- if (sessionFactory==null) {
- return;
- }
-
- String[] cleanSql = (String[]) environmentFactory.get(CLEAN_SQL_KEY);
-
- if (cleanSql == null) {
- Configuration configuration = environmentFactory.get(Configuration.class);
-
- SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
- Dialect dialect = sessionFactoryImplementor.getDialect();
-
- // loop over all foreign key constraints
- List<String> dropForeignKeysSql = new ArrayList<String>();
- List<String> createForeignKeysSql = new ArrayList<String>();
- Iterator<Table> iter = configuration.getTableMappings();
- while (iter.hasNext()) {
- Table table = (Table) iter.next();
- if (table.isPhysicalTable()) {
- String catalog = table.getCatalog();
- String schema = table.getSchema();
- Iterator<ForeignKey> subIter = table.getForeignKeyIterator();
- while (subIter.hasNext()) {
- ForeignKey fk = (ForeignKey) subIter.next();
- if (fk.isPhysicalConstraint()) {
- // collect the drop foreign key constraint sql
- dropForeignKeysSql.add(fk.sqlDropString(dialect, catalog, schema));
- // MySQLDialect creates an index for each foreign key.
- // see
- // http://opensource.atlassian.com/projects/hibernate/browse/HHH-2155
- // This index should be dropped or an error will be thrown during
- // the creation phase
- if (dialect instanceof MySQLDialect) {
- dropForeignKeysSql.add("alter table " + table.getName() + " drop key " + fk.getName());
- }
- // and collect the create foreign key constraint sql
- createForeignKeysSql.add(fk.sqlCreateString(dialect, sessionFactoryImplementor, catalog, schema));
- }
- }
- }
- }
-
- List<String> deleteSql = new ArrayList<String>();
- iter = configuration.getTableMappings();
- while (iter.hasNext()) {
- Table table = (Table) iter.next();
- if (table.isPhysicalTable()) {
- deleteSql.add("delete from " + table.getName());
- }
- }
-
- // glue
- // - drop foreign key constraints
- // - delete contents of all tables
- // - create foreign key constraints
- // together to form the clean script
- List<String> cleanSqlList = new ArrayList<String>();
- cleanSqlList.addAll(dropForeignKeysSql);
- cleanSqlList.addAll(deleteSql);
- cleanSqlList.addAll(createForeignKeysSql);
-
- cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
-
- environmentFactory.set(CLEAN_SQL_KEY, cleanSql);
- }
-
- Session session = sessionFactory.openSession();
- try {
- for (String query : cleanSql) {
- // log.trace(query);
- session.createSQLQuery(query).executeUpdate();
- }
- } finally {
- session.close();
- }
- }
-
- public static void verifyClean(EnvironmentFactory environmentFactory) {
- SessionFactory sessionFactory = environmentFactory.get(SessionFactory.class);
- // when running this with a remote ejb invocation configuration, there is no
- // session factory and no cleanup needs to be done
- if (sessionFactory==null) {
- return;
- }
-
- String[] tableNames = (String[]) environmentFactory.get(TABLE_NAMES_KEY);
-
- if (tableNames == null) {
- Configuration configuration = environmentFactory.get(Configuration.class);
-
- SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
- Dialect dialect = sessionFactoryImplementor.getDialect();
-
- // loop over all foreign key constraints
- List<String> tableNamesList = new ArrayList<String>();
- Iterator iter = configuration.getTableMappings();
- while (iter.hasNext()) {
- Table table = (Table) iter.next();
- if (table.isPhysicalTable()) {
- tableNamesList.add(table.getName());
- }
- }
-
- tableNames = (String[]) tableNamesList.toArray(new String[tableNamesList.size()]);
-
- environmentFactory.set(TABLE_NAMES_KEY, tableNames);
- }
-
- boolean recordsLeft = false;
- Session session = sessionFactory.openSession();
- try {
- for (String tableName : tableNames) {
- String countSql = "select count(*) recordCount from "+tableName;
- SQLQuery sqlQuery = session.createSQLQuery(countSql);
- sqlQuery.addScalar("recordCount", Hibernate.INTEGER);
- Integer recordCount = (Integer) sqlQuery.uniqueResult();
- if (recordCount>0) {
- recordsLeft = true;
- log.error("FIXME: JBPM-2004 "+recordCount+" records left in table "+tableName);
- }
- }
- } finally {
- session.close();
- }
-
- if (recordsLeft) {
- clean(environmentFactory);
- }
- }
-}
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.Hibernate;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.MySQLDialect;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.mapping.ForeignKey;
+import org.hibernate.mapping.Table;
+import org.jbpm.api.ProcessEngine;
+import org.jbpm.api.env.EnvironmentFactory;
+import org.jbpm.internal.log.Log;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class Db {
+
+ private static final Log log = Log.getLog(Db.class.getName());
+
+ private static final String TABLE_NAMES_KEY = "tableNames";
+ private static final String CLEAN_SQL_KEY = "cleanSql";
+
+ public static void clean(ProcessEngine processEngine) {
+ clean((EnvironmentFactory) processEngine);
+ }
+
+ public static void verifyClean(ProcessEngine processEngine) {
+ verifyClean((EnvironmentFactory) processEngine);
+ }
+
+ public static void clean(EnvironmentFactory environmentFactory) {
+ SessionFactory sessionFactory = environmentFactory.get(SessionFactory.class);
+ // when running this with a remote ejb invocation configuration, there is no
+ // session factory and no cleanup needs to be done
+ if (sessionFactory==null) {
+ return;
+ }
+
+ String[] cleanSql = (String[]) environmentFactory.get(CLEAN_SQL_KEY);
+
+ if (cleanSql == null) {
+ Configuration configuration = environmentFactory.get(Configuration.class);
+
+ SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
+ Dialect dialect = sessionFactoryImplementor.getDialect();
+
+ // loop over all foreign key constraints
+ List<String> dropForeignKeysSql = new ArrayList<String>();
+ List<String> createForeignKeysSql = new ArrayList<String>();
+ Iterator<Table> iter = configuration.getTableMappings();
+
+ //if no session-factory is build, the configuration is not fully initialized.
+ //Hence, the ForeignKey's won't have a referenced table. This is calculated on
+ //second pass.
+ configuration.buildMappings();
+
+
+ while (iter.hasNext()) {
+ Table table = (Table) iter.next();
+ if (table.isPhysicalTable()) {
+ String catalog = table.getCatalog();
+ String schema = table.getSchema();
+ Iterator<ForeignKey> subIter = table.getForeignKeyIterator();
+ while (subIter.hasNext()) {
+ ForeignKey fk = (ForeignKey) subIter.next();
+ if (fk.isPhysicalConstraint()) {
+ // collect the drop foreign key constraint sql
+ dropForeignKeysSql.add(fk.sqlDropString(dialect, catalog, schema));
+ // MySQLDialect creates an index for each foreign key.
+ // see
+ // http://opensource.atlassian.com/projects/hibernate/browse/HHH-2155
+ // This index should be dropped or an error will be thrown during
+ // the creation phase
+ if (dialect instanceof MySQLDialect) {
+ dropForeignKeysSql.add("alter table " + table.getName() + " drop key " + fk.getName());
+ }
+ // and collect the create foreign key constraint sql
+ createForeignKeysSql.add(fk.sqlCreateString(dialect, sessionFactoryImplementor, catalog, schema));
+ }
+ }
+ }
+ }
+
+ List<String> deleteSql = new ArrayList<String>();
+ iter = configuration.getTableMappings();
+ while (iter.hasNext()) {
+ Table table = (Table) iter.next();
+ if (table.isPhysicalTable()) {
+ deleteSql.add("delete from " + table.getName());
+ }
+ }
+
+ // glue
+ // - drop foreign key constraints
+ // - delete contents of all tables
+ // - create foreign key constraints
+ // together to form the clean script
+ List<String> cleanSqlList = new ArrayList<String>();
+ cleanSqlList.addAll(dropForeignKeysSql);
+ cleanSqlList.addAll(deleteSql);
+ cleanSqlList.addAll(createForeignKeysSql);
+
+ cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
+
+ environmentFactory.set(CLEAN_SQL_KEY, cleanSql);
+ }
+
+ Session session = sessionFactory.openSession();
+ try {
+ for (String query : cleanSql) {
+ // log.trace(query);
+ session.createSQLQuery(query).executeUpdate();
+ }
+ } finally {
+ session.close();
+ }
+ }
+
+ public static void verifyClean(EnvironmentFactory environmentFactory) {
+ SessionFactory sessionFactory = environmentFactory.get(SessionFactory.class);
+ // when running this with a remote ejb invocation configuration, there is no
+ // session factory and no cleanup needs to be done
+ if (sessionFactory==null) {
+ return;
+ }
+
+ String[] tableNames = (String[]) environmentFactory.get(TABLE_NAMES_KEY);
+
+ if (tableNames == null) {
+ Configuration configuration = environmentFactory.get(Configuration.class);
+
+ SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
+ Dialect dialect = sessionFactoryImplementor.getDialect();
+
+ // loop over all foreign key constraints
+ List<String> tableNamesList = new ArrayList<String>();
+ Iterator iter = configuration.getTableMappings();
+ while (iter.hasNext()) {
+ Table table = (Table) iter.next();
+ if (table.isPhysicalTable()) {
+ tableNamesList.add(table.getName());
+ }
+ }
+
+ tableNames = (String[]) tableNamesList.toArray(new String[tableNamesList.size()]);
+
+ environmentFactory.set(TABLE_NAMES_KEY, tableNames);
+ }
+
+ boolean recordsLeft = false;
+ Session session = sessionFactory.openSession();
+ try {
+ for (String tableName : tableNames) {
+ String countSql = "select count(*) recordCount from "+tableName;
+ SQLQuery sqlQuery = session.createSQLQuery(countSql);
+ sqlQuery.addScalar("recordCount", Hibernate.INTEGER);
+ Integer recordCount = (Integer) sqlQuery.uniqueResult();
+ if (recordCount>0) {
+ recordsLeft = true;
+ log.error("FIXME: JBPM-2004 "+recordCount+" records left in table "+tableName);
+ }
+ }
+ } finally {
+ session.close();
+ }
+
+ if (recordsLeft) {
+ clean(environmentFactory);
+ }
+ }
+}
Modified: jbpm4/trunk/modules/test-db/pom.xml
===================================================================
--- jbpm4/trunk/modules/test-db/pom.xml 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/modules/test-db/pom.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -47,6 +47,11 @@
<artifactId>jbpm-test-base</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
@@ -114,7 +119,9 @@
<skipTests>true</skipTests>
</properties>
</profile>
+
+
<!-- -Djboss.bind.address
<profile>
<id>integration.tests</id>
@@ -180,7 +187,8 @@
</plugin>
</plugins>
</build>
- </profile -->
+ </profile
+-->
</profiles>
</project>
\ No newline at end of file
Added: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/applicationContext.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/applicationContext.xml (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/applicationContext.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
+
+ <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
+ <property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />
+ <!-- A best practice should be to keep split the config into multiple files
+ <property name="configLocations" value="hibernate.cfg.xml, hibernate.jbpm.cfg.xml" />
+ -->
+ </bean>
+
+ <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
+ <property name="sessionFactory" ref="sessionFactory" />
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+ <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
+ <property name="url" value="jdbc:hsqldb:mem:." />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </bean>
+</beans>
\ No newline at end of file
Property changes on: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/applicationContext.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration>
+
+ <import resource="jbpm.default.cfg.xml" />
+ <import resource="jbpm.jpdl.cfg.xml" />
+ <import resource="jbpm.identity.cfg.xml" />
+
+ <process-engine-context>
+ <command-service>
+ <retry-interceptor />
+ <environment-interceptor />
+ <spring-transaction-interceptor />
+ </command-service>
+ </process-engine-context>
+
+ <transaction-context>
+ <transaction />
+ <hibernate-session />
+ </transaction-context>
+</jbpm-configuration>
Property changes on: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/spring/jbpm.cfg.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/pom.xml
===================================================================
--- jbpm4/trunk/pom.xml 2009-05-22 09:23:50 UTC (rev 4871)
+++ jbpm4/trunk/pom.xml 2009-05-22 09:58:21 UTC (rev 4872)
@@ -63,7 +63,7 @@
<log4j.version>1.2.14</log4j.version>
<mail.version>1.4.1</mail.version>
<servlet-api.version>2.5</servlet-api.version>
- <spring.version>2.5.4</spring.version>
+ <spring.version>2.0.8</spring.version>
<stax.api.version>1.0.1</stax.api.version>
<wiser.version>1.2</wiser.version>
<woodstox.version>3.2.6</woodstox.version>
More information about the jbpm-commits
mailing list