[jbpm-commits] JBoss JBPM SVN: r5764 - in jbpm4/trunk/modules: db/scripts and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Oct 21 03:14:48 EDT 2009
Author: alex.guizar at jboss.com
Date: 2009-10-21 03:14:47 -0400 (Wed, 21 Oct 2009)
New Revision: 5764
Added:
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/ant/
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/ant/UpgradeTaskTest.java
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/DbCmd.java
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/GetDeploymentPropertyCmd.java
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RemoveDeploymentPropertyCmd.java
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RunScriptCmd.java
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/TableExistsCmd.java
Removed:
jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/UpgradeTool.java
Modified:
jbpm4/trunk/modules/db/pom.xml
jbpm4/trunk/modules/db/scripts/antrun-schema.xml
jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/ant/CreatePropertiesTask.java
jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/ant/UpgradeTask.java
jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/GetJbpmVersionCmd.java
jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/JbpmVersion.java
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/upgrade/AddLangIdCmdTest.java
jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/upgrade/UpdateSchemaCmdTest.java
jbpm4/trunk/modules/db/src/test/resources/logging.properties
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java
Log:
[JBPM-2509] test upgrade task
Modified: jbpm4/trunk/modules/db/pom.xml
===================================================================
--- jbpm4/trunk/modules/db/pom.xml 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/pom.xml 2009-10-21 07:14:47 UTC (rev 5764)
@@ -10,7 +10,8 @@
<!-- ====================================================================== -->
<!-- $Id: pom.xml 3010 2008-11-20 08:30:16Z tom.baeyens at jboss.com $ -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- Module Info -->
<modelVersion>4.0.0</modelVersion>
@@ -27,12 +28,14 @@
<relativePath>../../pom.xml</relativePath>
</parent>
+ <properties>
+ <old.version>4.1</old.version>
+ </properties>
+
<profiles>
- <profile>
- <id>upgrade</id>
- <properties>
- <old.version>4.1</old.version>
- </properties>
+ <profile>
+ <id>upgrade</id>
+
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
@@ -41,60 +44,55 @@
<scope>compile</scope>
</dependency>
</dependencies>
+
<repositories>
<repository>
<id>qa.jboss.com</id>
<url>http://www.qa.jboss.com/jdbc-drivers/maven2</url>
</repository>
</repositories>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>previous-version</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>unpack</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>org.jbpm.jbpm4</groupId>
- <artifactId>jbpm-db</artifactId>
- <version>${old.version}</version>
- </artifactItem>
- </artifactItems>
- <outputDirectory>target/old.schema.files</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <id>upgrade-script</id>
- <phase>compile</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <tasks>
- <property name="upgrade.files.dest.dir" value="src/main/resources/db/upgrade-${old.version}-to-${version}"/>
- <property name="database" value="${database}"/>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>upgrade-script</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <property name="upgrade.files.dest.dir"
+ value="src/main/resources/db/upgrade-${old.version}-to-${version}" />
+ <property name="database" value="${database}" />
<!-- for some reason that i don't get, the user.home must be passed explicitly -->
- <property name="user.home" value="${user.home}"/>
- <ant antfile="scripts/antrun-schema.xml" target="schema-upgrade" inheritRefs="yes"/>
- </tasks>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
+ <property name="user.home" value="${user.home}" />
+ <ant antfile="scripts/antrun-schema.xml" target="schema-upgrade"
+ inheritRefs="yes" />
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>no-database</id>
+ <activation>
+ <property>
+ <name>!database</name>
+ </property>
+ </activation>
+
+ <properties>
+ <database>hsqldb</database>
+ </properties>
+ </profile>
</profiles>
<!-- Dependencies -->
@@ -123,20 +121,55 @@
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
- <id>create-drop-script</id>
+ <id>create-drop-script</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
- <property name="project.output.dir" value="${project.build.outputDirectory}"/>
- <ant antfile="scripts/antrun-schema.xml" target="create-schema" inheritRefs="yes"/>
+ <property name="project.output.dir" value="${project.build.outputDirectory}" />
+ <ant antfile="scripts/antrun-schema.xml" target="create-schema" inheritRefs="yes" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>previous-version</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jbpm.jbpm4</groupId>
+ <artifactId>jbpm-db</artifactId>
+ <version>${old.version}</version>
+ </artifactItem>
+ </artifactItems>
+ <outputDirectory>target/test-classes/old-db</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>database</name>
+ <value>${database}</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
</plugins>
</build>
Modified: jbpm4/trunk/modules/db/scripts/antrun-schema.xml
===================================================================
--- jbpm4/trunk/modules/db/scripts/antrun-schema.xml 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/scripts/antrun-schema.xml 2009-10-21 07:14:47 UTC (rev 5764)
@@ -10,70 +10,74 @@
<project>
- <!-- ##################### -->
- <!-- ### CREATE SCHEMA ### -->
<!-- ##################### -->
+ <!-- ### CREATE SCHEMA ### -->
+ <!-- ##################### -->
- <target name="create-schema">
- <taskdef name="schemaexport"
- classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
- classpathref="maven.compile.classpath" />
+ <target name="create-schema">
+ <taskdef name="schemaexport"
+ classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
+ classpathref="maven.compile.classpath" />
- <mkdir dir="target/classes/db" />
+ <mkdir dir="target/classes/db" />
<create-ddl db="hsqldb" />
- <create-ddl db="oracle" />
+ <create-ddl db="oracle" />
<create-ddl db="postgresql" />
<create-ddl db="mysql" />
<replace file="target/classes/db/jbpm.mysql.create.sql"
token="BLOB_VALUE_ blob"
value="BLOB_VALUE_ longblob" />
- </target>
+ </target>
- <macrodef name="create-ddl">
- <attribute name="db" />
+ <macrodef name="create-ddl">
+ <attribute name="db" />
- <sequential>
- <echo></echo>
- <echo>=====================</echo>
- <echo>Schema Create @{db}</echo>
+ <sequential>
+ <echo />
<echo>=====================</echo>
+ <echo>Schema Create @{db}</echo>
+ <echo>=====================</echo>
- <schemaexport output="target/classes/db/jbpm.@{db}.create.sql"
- create="yes" drop="no"
- config="../distro/src/main/files/install/src/cfg/hibernate/jdbc/@{db}.hibernate.cfg.xml"
- text="yes" delimiter=";"
- quiet="yes" />
+ <schemaexport output="target/classes/db/jbpm.@{db}.create.sql"
+ create="yes"
+ drop="no"
+ config="../distro/src/main/files/install/src/cfg/hibernate/jdbc/@{db}.hibernate.cfg.xml"
+ text="yes"
+ delimiter=";"
+ quiet="yes" />
- <echo></echo>
- <echo>=====================</echo>
+ <echo />
+ <echo>=====================</echo>
<echo>Schema Drop @{db}</echo>
<echo>=====================</echo>
- <schemaexport output="target/classes/db/jbpm.@{db}.drop.sql"
- create="no" drop="yes"
- config="../distro/src/main/files/install/src/cfg/hibernate/jdbc/@{db}.hibernate.cfg.xml"
- text="yes" delimiter=";"
- quiet="yes" />
+ <schemaexport output="target/classes/db/jbpm.@{db}.drop.sql"
+ create="no"
+ drop="yes"
+ config="../distro/src/main/files/install/src/cfg/hibernate/jdbc/@{db}.hibernate.cfg.xml"
+ text="yes"
+ delimiter=";"
+ quiet="yes" />
- </sequential>
- </macrodef>
+ </sequential>
+ </macrodef>
- <!-- ###################### -->
+ <!-- ###################### -->
<!-- ### SCHEMA UPGRADE ### -->
<!-- ###################### -->
- <target name="schema-upgrade">
+ <target name="schema-upgrade">
<taskdef name="schemaupdate"
classname="org.hibernate.tool.hbm2ddl.SchemaUpdateTask"
classpathref="maven.compile.classpath" />
- <!-- By default, the qa lab databases are used. the jdbc properties are taken from the qa/jdbc directory.
+ <!-- By default, the qa lab databases are used. the jdbc properties are taken from the qa/jdbc directory.
If you want to use your local database, specify property upgrade.jdbc.properties.dir in your local build properties -->
- <echo>loading properties from ${user.home}/.jbpm4/build.properties</echo>
- <property file="${user.home}/.jbpm4/build.properties" />
+ <echo>loading properties from ${user.home}/.jbpm4/build.properties</echo>
+ <property file="${user.home}/.jbpm4/build.properties" />
<echo>upgrade.jdbc.properties.dir: ${upgrade.jdbc.properties.dir}</echo>
<property name="upgrade.jdbc.properties.dir" location="../../qa/jdbc" />
- <mkdir dir="${upgrade.files.dest.dir}" />
+ <mkdir dir="${upgrade.files.dest.dir}" />
<antcall target="start.hsqldb" inheritrefs="true" />
<upgrade-ddl db="hsqldb" />
@@ -82,8 +86,8 @@
<upgrade-ddl db="oracle" />
<upgrade-ddl db="postgresql" />
</target>
-
- <target name="start.hsqldb">
+
+ <target name="start.hsqldb">
<java classname="org.hsqldb.Server"
classpathref="maven.compile.classpath"
fork="yes"
@@ -97,7 +101,7 @@
<socket server="localhost" port="1701" />
</waitfor>
</target>
-
+
<target name="stop.hsqldb">
<sql url="jdbc:hsqldb:hsql://localhost:1701"
driver="org.hsqldb.jdbcDriver"
@@ -112,18 +116,11 @@
<macrodef name="upgrade-ddl">
<attribute name="db" />
<sequential>
- <!-- ant antfile="scripts/schema-upgrade.xml" target="create.old.schema" inheritall="false">
- <property name="database" value="@{db}" />
- <property name="upgrade.jdbc.properties.dir" value="${upgrade.jdbc.properties.dir}" />
- <property name="compile.classpath.text" value="${toString:maven.compile.classpath}" />
- </ant -->
-
<property file="${upgrade.jdbc.properties.dir}/@{db}.properties" prefix="@{db}." />
- <echo></echo>
+ <echo />
<echo>driver... ${@{db}.jdbc.driver}</echo>
<echo>url...... ${@{db}.jdbc.url}</echo>
<echo>username. ${@{db}.jdbc.username}</echo>
- <echo>password. ${@{db}.jdbc.password}</echo>
<echo>=====================</echo>
<echo>Dropping current schema @{db}</echo>
@@ -137,11 +134,11 @@
autocommit="yes"
onerror="continue" />
- <echo></echo>
+ <echo />
<echo>=====================</echo>
<echo>Creating old schema @{db}</echo>
<echo>=====================</echo>
- <sql src="target/old.schema.files/jbpm.@{db}.create.sql"
+ <sql src="target/test-classes/old-db/jbpm.@{db}.create.sql"
url="${@{db}.jdbc.url}"
driver="${@{db}.jdbc.driver}"
userid="${@{db}.jdbc.username}"
@@ -149,15 +146,15 @@
classpathref="maven.compile.classpath"
autocommit="yes"
onerror="continue" />
-
- <mkdir dir="target/cfg" />
- <copy tofile="target/cfg/@{db}.hibernate.cfg.xml"
+
+ <mkdir dir="target/cfg" />
+ <copy tofile="target/cfg/@{db}.hibernate.cfg.xml"
file="../distro/src/main/files/install/src/cfg/hibernate/jdbc/@{db}.hibernate.cfg.xml"
overwrite="true">
<filterset filtersfile="${upgrade.jdbc.properties.dir}/@{db}.properties" />
</copy>
-
- <echo></echo>
+
+ <echo />
<echo>=====================</echo>
<echo>Schema Upgrade @{db}</echo>
<echo>=====================</echo>
@@ -166,11 +163,11 @@
properties="${upgrade.jdbc.properties.dir}/@{db}.properties"
delimiter=";" />
- <echo></echo>
+ <echo />
<echo>=====================</echo>
<echo>Dropping old schema @{db}</echo>
<echo>=====================</echo>
- <sql src="target/old.schema.files/jbpm.@{db}.drop.sql"
+ <sql src="target/test-classes/old-db/jbpm.@{db}.drop.sql"
url="${@{db}.jdbc.url}"
driver="${@{db}.jdbc.driver}"
userid="${@{db}.jdbc.username}"
@@ -178,8 +175,8 @@
classpathref="maven.compile.classpath"
autocommit="yes"
onerror="continue" />
-
+
</sequential>
</macrodef>
-
+
</project>
Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/ant/CreatePropertiesTask.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/ant/CreatePropertiesTask.java 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/ant/CreatePropertiesTask.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -33,18 +33,9 @@
public class CreatePropertiesTask extends Task {
public void execute() throws BuildException {
- try {
- ProcessEngine processEngine =
- new ProcessEngineImpl()
- .skipDbCheck()
- .buildProcessEngine();
+ ProcessEngine processEngine = new ProcessEngineImpl().skipDbCheck().buildProcessEngine();
- // create properties
- processEngine.execute(new CreatePropertiesCmd());
-
- } catch (Exception e) {
- e.printStackTrace();
- throw new BuildException("failed to create jbpm properties during schema creation");
- }
+ // create properties
+ processEngine.execute(new CreatePropertiesCmd());
}
}
Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/ant/UpgradeTask.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/ant/UpgradeTask.java 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/ant/UpgradeTask.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -23,7 +23,13 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
-import org.jbpm.db.internal.upgrade.UpgradeTool;
+import org.jbpm.api.ProcessEngine;
+import org.jbpm.db.internal.upgrade.AddLangIdCmd;
+import org.jbpm.db.internal.upgrade.GetJbpmVersionCmd;
+import org.jbpm.db.internal.upgrade.JbpmVersion;
+import org.jbpm.db.internal.upgrade.UpdateSchemaCmd;
+import org.jbpm.db.internal.upgrade.UpgradePropertiesCmd;
+import org.jbpm.pvm.internal.cfg.ProcessEngineImpl;
/**
* @author Alejandro Guizar
@@ -31,12 +37,18 @@
public class UpgradeTask extends Task {
public void execute() throws BuildException {
- try {
- UpgradeTool.upgrade();
+ ProcessEngine processEngine = new ProcessEngineImpl().skipDbCheck().buildProcessEngine();
+
+ // update database schema
+ processEngine.execute(new UpdateSchemaCmd());
+
+ // check whether database version predates engine version
+ JbpmVersion currentVersion = processEngine.execute(new GetJbpmVersionCmd());
+ if (currentVersion.compareTo(JbpmVersion.V_4_2) < 0) {
+ // add property "langid" to each deployed process
+ processEngine.execute(new AddLangIdCmd());
+ // upgrade properties
+ processEngine.execute(new UpgradePropertiesCmd());
}
- catch (Exception e) {
- e.printStackTrace();
- throw new BuildException("failed to upgrade jbpm database");
- }
}
}
Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/GetJbpmVersionCmd.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/GetJbpmVersionCmd.java 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/GetJbpmVersionCmd.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -22,13 +22,10 @@
package org.jbpm.db.internal.upgrade;
import org.hibernate.Session;
-import org.jbpm.api.JbpmException;
import org.jbpm.api.cmd.Command;
import org.jbpm.api.cmd.Environment;
-import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.id.PropertyImpl;
-
/**
* @author Tom Baeyens
*/
@@ -37,14 +34,16 @@
private static final long serialVersionUID = 1L;
public JbpmVersion execute(Environment environment) throws Exception {
- Session session = EnvironmentImpl.getFromCurrent(Session.class);
+ Session session = environment.get(Session.class);
if (!PropertyImpl.propertiesTableExists(session)) {
return JbpmVersion.V_4_0;
}
String dbVersion = PropertyImpl.getDbVersion(session);
if (dbVersion==null) {
- throw new JbpmException("invalid db state: property table exists, but no db version property is present");
+ // property table exists, but no db version property is present
+ // schema must have been updated moments ago
+ return JbpmVersion.V_4_0;
}
return JbpmVersion.getJbpmVersion(dbVersion);
Modified: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/JbpmVersion.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/JbpmVersion.java 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/JbpmVersion.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -21,41 +21,22 @@
*/
package org.jbpm.db.internal.upgrade;
-import java.util.HashMap;
-import java.util.Map;
-
-
/**
* @author Tom Baeyens
*/
-public class JbpmVersion {
+public enum JbpmVersion {
- public static final JbpmVersion V_4_0 = new JbpmVersion(4,0);
- public static final JbpmVersion V_4_2 = new JbpmVersion(4,2);
-
- private static Map<String, JbpmVersion> versions = new HashMap<String, JbpmVersion>();
-
- private int major = -1;
- private int minor = -1;
+ V_4_0, V_4_1, V_4_2;
- private JbpmVersion(int major, int minor) {
- this.major = major;
- this.minor = minor;
- versions.put(toString(), this);
- }
-
- public boolean earlierThen(JbpmVersion other) {
- return (minor<other.minor);
- }
-
public String toString() {
- return major+"."+minor;
+ return "4." + ordinal();
}
public static JbpmVersion getJbpmVersion(String dbVersion) {
if (dbVersion.endsWith("-SNAPSHOT")) {
- dbVersion = dbVersion.substring(0, dbVersion.length()-9);
+ dbVersion = dbVersion.substring(0, dbVersion.length() - 9);
}
- return versions.get(dbVersion);
+ return dbVersion.startsWith("4.") && dbVersion.length() > 2 ? valueOf("V_4_"
+ + dbVersion.substring(2)) : null;
}
}
Deleted: jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/UpgradeTool.java
===================================================================
--- jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/UpgradeTool.java 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/src/main/java/org/jbpm/db/internal/upgrade/UpgradeTool.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -1,56 +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.db.internal.upgrade;
-
-import java.util.List;
-
-import org.jbpm.api.ProcessEngine;
-import org.jbpm.pvm.internal.cfg.ProcessEngineImpl;
-
-/**
- * @author Alejandro Guizar
- */
-public class UpgradeTool {
-
- public static void upgrade() throws Exception {
- ProcessEngine processEngine =
- new ProcessEngineImpl()
- .skipDbCheck()
- .buildProcessEngine();
-
- // update database schema
- processEngine.execute(new UpdateSchemaCmd());
-
- JbpmVersion currentVersion = processEngine.execute(new GetJbpmVersionCmd());
-
- if (currentVersion.earlierThen(JbpmVersion.V_4_2)) {
- // add property "langid" to each deployed process
- processEngine.execute(new AddLangIdCmd());
- // upgrade properties
- processEngine.execute(new UpgradePropertiesCmd());
- }
- }
-
- public static void main(String[] args) throws Exception {
- upgrade();
- }
-}
Added: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/ant/UpgradeTaskTest.java
===================================================================
--- jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/ant/UpgradeTaskTest.java (rev 0)
+++ jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/ant/UpgradeTaskTest.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -0,0 +1,94 @@
+/*
+ * 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.db.internal.ant;
+
+import org.jbpm.api.Configuration;
+import org.jbpm.api.JbpmException;
+import org.jbpm.db.internal.cmd.GetDeploymentPropertyCmd;
+import org.jbpm.db.internal.cmd.RemoveDeploymentPropertyCmd;
+import org.jbpm.db.internal.cmd.RunScriptCmd;
+import org.jbpm.db.internal.cmd.TableExistsCmd;
+import org.jbpm.db.internal.upgrade.UpdateSchemaCmd;
+import org.jbpm.pvm.internal.repository.DeploymentImpl;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class UpgradeTaskTest extends JbpmTestCase {
+
+ private String database;
+
+ protected void setUp() throws Exception {
+ database = System.getProperty("database");
+ super.setUp();
+ }
+
+ public void testBuildEngineBeforeUpgrading() {
+ // drop current schema
+ processEngine.execute(new RunScriptCmd("db/jbpm." + database + ".drop.sql"));
+ // create old schema
+ processEngine.execute(new RunScriptCmd("old-db/jbpm." + database + ".create.sql"));
+ // build another engine
+ try {
+ new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();
+ }
+ catch (JbpmException e) {
+ assert e.getMessage().contains("run the upgrade tool first") : e.getMessage();
+ }
+ finally {
+ // update schema
+ processEngine.execute(new UpdateSchemaCmd());
+ }
+ }
+
+ public void testBuildEngineAfterUpgrading() {
+ // drop current schema
+ processEngine.execute(new RunScriptCmd("db/jbpm." + database + ".drop.sql"));
+ // create old schema
+ processEngine.execute(new RunScriptCmd("old-db/jbpm." + database + ".create.sql"));
+ // deploy process
+ /* TODO deployment fails against old schema
+ String processName = getName();
+ String deploymentId = repositoryService.createDeployment()
+ .addResourceFromString("process.jpdl.xml", "<process name='"
+ + processName
+ + "'>"
+ + " <start/>"
+ + "</process>")
+ .deploy();
+ */
+ try {
+ // processEngine.execute(new RemoveDeploymentPropertyCmd(deploymentId, processName, DeploymentImpl.KEY_PROCESS_LANGUAGE_ID));
+ // do upgrade
+ new UpgradeTask().execute();
+ // verify new table was created
+ assert processEngine.execute(new TableExistsCmd("JBPM4_PROPERTY"));
+ // verify langid attribute was added
+ // String langId = (String) processEngine.execute(new GetDeploymentPropertyCmd(deploymentId, processName, DeploymentImpl.KEY_PROCESS_LANGUAGE_ID));
+ // assertEquals("jpdl-4.0", langId);
+ }
+ finally {
+ // repositoryService.deleteDeploymentCascade(deploymentId);
+ }
+ }
+}
Property changes on: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/ant/UpgradeTaskTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/DbCmd.java
===================================================================
--- jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/DbCmd.java (rev 0)
+++ jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/DbCmd.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -0,0 +1,112 @@
+package org.jbpm.db.internal.cmd;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.connection.ConnectionProviderFactory;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.mapping.Table;
+import org.hibernate.util.JDBCExceptionReporter;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+
+/**
+ * Base class for database commands on top of Hibernate.
+ *
+ * @author Alejandro Guizar
+ */
+public abstract class DbCmd<T> implements Command<T> {
+
+ private Configuration configuration;
+ private ConnectionProvider connectionProvider;
+
+ private static final long serialVersionUID = 1L;
+
+ public T execute(Environment environment) throws Exception {
+ configuration = environment.get(Configuration.class);
+ Connection connection = null;
+ try {
+ connection = createConnection();
+ return execute(connection);
+ }
+ finally {
+ closeConnection(connection);
+ configuration = null;
+ }
+ }
+
+ protected abstract T execute(Connection connection) throws Exception;
+
+ protected Dialect getDialect() {
+ return Dialect.getDialect(configuration.getProperties());
+ }
+
+ protected String getDefaultCatalog() {
+ return configuration.getProperty(org.hibernate.cfg.Environment.DEFAULT_CATALOG);
+ }
+
+ protected String getDefaultSchema() {
+ return configuration.getProperty(org.hibernate.cfg.Environment.DEFAULT_SCHEMA);
+ }
+
+ protected Table findTable(String tableName) {
+ for (Iterator< ? > i = configuration.getTableMappings(); i.hasNext();) {
+ Table table = (Table) i.next();
+ if (tableName.equals(table.getName()))
+ return table;
+ }
+ throw new NoSuchElementException(tableName);
+ }
+
+ private Connection createConnection() throws SQLException {
+ try {
+ connectionProvider = ConnectionProviderFactory.newConnectionProvider(configuration.getProperties());
+ }
+ catch (HibernateException e) {
+ throw new SQLException(e.getMessage());
+ }
+ Connection connection = connectionProvider.getConnection();
+ if (connection.getAutoCommit() == false) {
+ connection.commit();
+ connection.setAutoCommit(true);
+ }
+ return connection;
+ }
+
+ private void closeConnection(Connection connection) {
+ if (connectionProvider != null) {
+ try {
+ if (connection != null) {
+ JDBCExceptionReporter.logAndClearWarnings(connection);
+ connectionProvider.closeConnection(connection);
+ }
+ }
+ catch (SQLException e) {
+ JDBCExceptionReporter.logExceptions(e);
+ }
+ finally {
+ connectionProvider.close();
+ connectionProvider = null;
+ }
+ }
+ }
+
+ protected int executeUpdate(Statement statement, String sql) throws SQLException {
+ int rowCount = statement.executeUpdate(sql);
+
+ SQLWarning warning = statement.getWarnings();
+ if (warning != null) {
+ JDBCExceptionReporter.logWarnings(warning);
+ statement.clearWarnings();
+ }
+
+ return rowCount;
+ }
+}
\ No newline at end of file
Property changes on: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/DbCmd.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/GetDeploymentPropertyCmd.java
===================================================================
--- jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/GetDeploymentPropertyCmd.java (rev 0)
+++ jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/GetDeploymentPropertyCmd.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -0,0 +1,46 @@
+/*
+ * 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.db.internal.cmd;
+
+import org.hibernate.Session;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.pvm.internal.repository.DeploymentImpl;
+
+public class GetDeploymentPropertyCmd implements Command<Object> {
+
+ private final String deploymentId, objectName, key;
+
+ private static final long serialVersionUID = 1L;
+
+ public GetDeploymentPropertyCmd(String deploymentId, String objectName, String key) {
+ this.deploymentId = deploymentId;
+ this.objectName = objectName;
+ this.key = key;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ DeploymentImpl deployment = (DeploymentImpl) environment.get(Session.class)
+ .load(DeploymentImpl.class, Long.valueOf(deploymentId));
+ return deployment.getObjectProperty(objectName, key);
+ }
+}
\ No newline at end of file
Property changes on: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/GetDeploymentPropertyCmd.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RemoveDeploymentPropertyCmd.java
===================================================================
--- jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RemoveDeploymentPropertyCmd.java (rev 0)
+++ jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RemoveDeploymentPropertyCmd.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -0,0 +1,46 @@
+/*
+ * 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.db.internal.cmd;
+
+import org.hibernate.Session;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.pvm.internal.repository.DeploymentImpl;
+
+public class RemoveDeploymentPropertyCmd implements Command<Object> {
+
+ private final String deploymentId, objectName, key;
+
+ private static final long serialVersionUID = 1L;
+
+ public RemoveDeploymentPropertyCmd(String deploymentId, String objectName, String key) {
+ this.deploymentId = deploymentId;
+ this.objectName = objectName;
+ this.key = key;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ DeploymentImpl deployment = (DeploymentImpl) environment.get(Session.class)
+ .load(DeploymentImpl.class, Long.valueOf(deploymentId));
+ return deployment.removeObjectProperty(objectName, key);
+ }
+}
\ No newline at end of file
Property changes on: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RemoveDeploymentPropertyCmd.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RunScriptCmd.java
===================================================================
--- jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RunScriptCmd.java (rev 0)
+++ jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RunScriptCmd.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -0,0 +1,78 @@
+/*
+ * 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.db.internal.cmd;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.util.JDBCExceptionReporter;
+
+public class RunScriptCmd extends DbCmd<Void> {
+
+ private final String resource;
+ private final List<SQLException> exceptions = new ArrayList<SQLException>();
+
+ private static final long serialVersionUID = 1L;
+
+ public RunScriptCmd(String resource) {
+ this.resource = resource;
+ }
+
+ protected Void execute(Connection connection) throws SQLException, IOException {
+ InputStream stream = getClass().getClassLoader().getResourceAsStream(resource);
+ if (stream == null) {
+ throw new FileNotFoundException(resource);
+ }
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+ try {
+ Statement statement = connection.createStatement();
+ try {
+ for (String sql; (sql = reader.readLine()) != null;) {
+ try {
+ executeUpdate(statement, sql);
+ }
+ catch (SQLException e) {
+ JDBCExceptionReporter.logExceptions(e);
+ exceptions.add(e);
+ }
+ }
+ }
+ finally {
+ statement.close();
+ }
+ }
+ finally {
+ reader.close();
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
Property changes on: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/RunScriptCmd.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/TableExistsCmd.java
===================================================================
--- jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/TableExistsCmd.java (rev 0)
+++ jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/TableExistsCmd.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -0,0 +1,35 @@
+package org.jbpm.db.internal.cmd;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Tell whether the named table exists in the database.
+ *
+ * @author Alejandro Guizar
+ */
+public class TableExistsCmd extends DbCmd<Boolean> {
+
+ private final String tableName;
+
+ private static final long serialVersionUID = 1L;
+ private static final String[] TABLE_TYPES = { "TABLE" };
+
+ public TableExistsCmd(String tableName) {
+ this.tableName = tableName;
+ }
+
+ protected Boolean execute(Connection connection) throws SQLException {
+ DatabaseMetaData metaData = connection.getMetaData();
+ ResultSet resultSet = metaData.getTables(getDefaultCatalog(), getDefaultSchema(), tableName, TABLE_TYPES);
+ try {
+ return resultSet.next();
+ }
+ finally {
+ resultSet.close();
+ }
+ }
+
+}
\ No newline at end of file
Property changes on: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/cmd/TableExistsCmd.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/upgrade/AddLangIdCmdTest.java
===================================================================
--- jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/upgrade/AddLangIdCmdTest.java 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/upgrade/AddLangIdCmdTest.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -21,9 +21,8 @@
*/
package org.jbpm.db.internal.upgrade;
-import org.hibernate.Session;
-import org.jbpm.api.cmd.Command;
-import org.jbpm.api.cmd.Environment;
+import org.jbpm.db.internal.cmd.GetDeploymentPropertyCmd;
+import org.jbpm.db.internal.cmd.RemoveDeploymentPropertyCmd;
import org.jbpm.pvm.internal.repository.DeploymentImpl;
import org.jbpm.test.JbpmTestCase;
@@ -33,13 +32,15 @@
public class AddLangIdCmdTest extends JbpmTestCase {
private String deploymentId;
+ private String processName;
@Override
protected void setUp() throws Exception {
super.setUp();
+ processName = getName();
deploymentId = repositoryService.createDeployment()
.addResourceFromString("process.jpdl.xml", "<process name='"
- + getName()
+ + processName
+ "'>"
+ " <start/>"
+ "</process>")
@@ -53,29 +54,12 @@
}
public void testAddLangId() {
- processEngine.execute(new Command<Void>() {
- private static final long serialVersionUID = 1L;
+ String langId = (String) processEngine.execute(new RemoveDeploymentPropertyCmd(deploymentId, processName, DeploymentImpl.KEY_PROCESS_LANGUAGE_ID));
+ assertEquals("jpdl-4.2", langId);
- public Void execute(Environment environment) throws Exception {
- DeploymentImpl deployment = (DeploymentImpl) environment.get(Session.class)
- .load(DeploymentImpl.class, Long.valueOf(deploymentId));
- Object langId = deployment.removeObjectProperty(getName(), DeploymentImpl.KEY_PROCESS_LANGUAGE_ID);
- assertEquals("jpdl-4.2", langId);
- return null;
- }
- });
-
processEngine.execute(new AddLangIdCmd());
- processEngine.execute(new Command<Void>() {
- private static final long serialVersionUID = 1L;
-
- public Void execute(Environment environment) throws Exception {
- DeploymentImpl deployment = (DeploymentImpl) environment.get(Session.class)
- .load(DeploymentImpl.class, Long.valueOf(deploymentId));
- assertEquals("jpdl-4.0", deployment.getProcessLanguageId(getName()));
- return null;
- }
- });
+ langId = (String) processEngine.execute(new GetDeploymentPropertyCmd(deploymentId, processName, DeploymentImpl.KEY_PROCESS_LANGUAGE_ID));
+ assertEquals("jpdl-4.0", langId);
}
}
Modified: jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/upgrade/UpdateSchemaCmdTest.java
===================================================================
--- jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/upgrade/UpdateSchemaCmdTest.java 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/src/test/java/org/jbpm/db/internal/upgrade/UpdateSchemaCmdTest.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -22,23 +22,12 @@
package org.jbpm.db.internal.upgrade;
import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.SQLWarning;
import java.sql.Statement;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import org.hibernate.HibernateException;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.connection.ConnectionProvider;
-import org.hibernate.connection.ConnectionProviderFactory;
-import org.hibernate.dialect.Dialect;
import org.hibernate.mapping.Table;
-import org.hibernate.util.JDBCExceptionReporter;
-import org.jbpm.api.cmd.Command;
-import org.jbpm.api.cmd.Environment;
+import org.jbpm.db.internal.cmd.DbCmd;
+import org.jbpm.db.internal.cmd.TableExistsCmd;
import org.jbpm.test.JbpmTestCase;
/**
@@ -49,99 +38,21 @@
public void testUpdateSchema() {
// drop some jbpm table
processEngine.execute(new DropTableCmd("JBPM4_PROPERTY"));
- assertFalse(processEngine.execute(new TableExistsCmd("JBPM4_PROPERTY")));
+ assert !processEngine.execute(new TableExistsCmd("JBPM4_PROPERTY"));
// run schema update tool
processEngine.execute(new UpdateSchemaCmd());
// verify jbpm table was created again
- assertTrue(processEngine.execute(new TableExistsCmd("JBPM4_PROPERTY")));
+ assert processEngine.execute(new TableExistsCmd("JBPM4_PROPERTY"));
}
/**
- * Base class for SQL commands on top of Hibernate.
- *
- * @author Alejandro Guizar
- */
- static abstract class SqlCmd<T> implements Command<T> {
-
- private Configuration configuration;
- private ConnectionProvider connectionProvider;
-
- private static final long serialVersionUID = 1L;
-
- public T execute(Environment environment) throws SQLException {
- configuration = environment.get(Configuration.class);
- Connection connection = null;
- try {
- connection = createConnection();
- return execute(connection);
- } finally {
- closeConnection(connection);
- configuration = null;
- }
- }
-
- protected abstract T execute(Connection connection) throws SQLException;
-
- protected Dialect getDialect() {
- return Dialect.getDialect(configuration.getProperties());
- }
-
- protected String getDefaultCatalog() {
- return configuration.getProperty(org.hibernate.cfg.Environment.DEFAULT_CATALOG);
- }
-
- protected String getDefaultSchema() {
- return configuration.getProperty(org.hibernate.cfg.Environment.DEFAULT_SCHEMA);
- }
-
- protected Table findTable(String tableName) {
- for (Iterator<?> i = configuration.getTableMappings(); i.hasNext();) {
- Table table = (Table) i.next();
- if (tableName.equals(table.getName()))
- return table;
- }
- throw new NoSuchElementException(tableName);
- }
-
- private Connection createConnection() throws SQLException {
- try {
- connectionProvider = ConnectionProviderFactory.newConnectionProvider(configuration.getProperties());
- } catch (HibernateException e) {
- throw new SQLException(e.getMessage());
- }
- Connection connection = connectionProvider.getConnection();
- if (connection.getAutoCommit() == false) {
- connection.commit();
- connection.setAutoCommit(true);
- }
- return connection;
- }
-
- private void closeConnection(Connection connection) {
- if (connectionProvider != null) {
- try {
- if (connection != null) {
- JDBCExceptionReporter.logAndClearWarnings(connection);
- connectionProvider.closeConnection(connection);
- }
- } catch (SQLException e) {
- JDBCExceptionReporter.logExceptions(e);
- } finally {
- connectionProvider.close();
- connectionProvider = null;
- }
- }
- }
- }
-
- /**
* Drop the named table from the database.
*
* @author Alejandro Guizar
*/
- static class DropTableCmd extends SqlCmd<Void> {
+ static class DropTableCmd extends DbCmd<Void> {
private final String tableName;
@@ -160,13 +71,7 @@
// execute sql to drop table
Statement statement = connection.createStatement();
try {
- statement.executeUpdate(dropSql);
-
- SQLWarning warning = statement.getWarnings();
- if (warning != null) {
- JDBCExceptionReporter.logWarnings(warning);
- statement.clearWarnings();
- }
+ executeUpdate(statement, dropSql);
} finally {
statement.close();
}
@@ -174,32 +79,4 @@
return null;
}
}
-
- /**
- * Tell whether the named table exists in the database.
- *
- * @author Alejandro Guizar
- */
- static class TableExistsCmd extends SqlCmd<Boolean> {
-
- private final String tableName;
-
- private static final long serialVersionUID = 1L;
- private static final String[] TABLE_TYPES = { "TABLE" };
-
- TableExistsCmd(String tableName) {
- this.tableName = tableName;
- }
-
- protected Boolean execute(Connection connection) throws SQLException {
- DatabaseMetaData metaData = connection.getMetaData();
- ResultSet resultSet = metaData.getTables(getDefaultCatalog(), getDefaultSchema(), tableName, TABLE_TYPES);
- try {
- return resultSet.next();
- } finally {
- resultSet.close();
- }
- }
-
- }
}
Modified: jbpm4/trunk/modules/db/src/test/resources/logging.properties
===================================================================
--- jbpm4/trunk/modules/db/src/test/resources/logging.properties 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/db/src/test/resources/logging.properties 2009-10-21 07:14:47 UTC (rev 5764)
@@ -12,7 +12,7 @@
org.hibernate.level=INFO
org.hibernate.cfg.SettingsFactory.level=SEVERE
org.hibernate.cfg.HbmBinder.level=SEVERE
-# org.hibernate.SQL.level=FINEST
+org.hibernate.SQL.level=FINEST
# org.hibernate.type.level=FINEST
# org.hibernate.tool.hbm2ddl.SchemaExport.level=FINEST
# org.hibernate.transaction.level=FINEST
\ No newline at end of file
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java 2009-10-20 16:43:28 UTC (rev 5763)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/id/PropertyImpl.java 2009-10-21 07:14:47 UTC (rev 5764)
@@ -25,6 +25,7 @@
import java.util.List;
import org.hibernate.Session;
+import org.hibernate.criterion.Restrictions;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.cfg.ProcessEngineImpl;
import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
@@ -143,8 +144,8 @@
for (String persistedType: persistedTypes) {
try {
Long typeMaxDbid = (Long) session.createQuery(
- "select max(object.dbid) " +
- "from "+persistedType+" as object"
+ "select max(id) " +
+ "from "+persistedType
).uniqueResult();
if ( (typeMaxDbid!=null)
@@ -169,22 +170,19 @@
}
protected static void setPropertyValue(Session session, String propertyKey, String propertyValue) {
- PropertyImpl dbidProperty = getProperty(session, propertyKey);
- if (dbidProperty==null) {
- dbidProperty = new PropertyImpl(PropertyImpl.NEXT_DBID_KEY, propertyValue);
- session.save(dbidProperty);
+ PropertyImpl property = getProperty(session, propertyKey);
+ if (property==null) {
+ property = new PropertyImpl(propertyKey, propertyValue);
+ session.save(property);
} else {
- dbidProperty.setValue(propertyValue);
- session.update(dbidProperty);
+ property.setValue(propertyValue);
}
}
protected static PropertyImpl getProperty(Session session, String key) {
- return (PropertyImpl) session.createQuery(
- "select property " +
- "from "+PropertyImpl.class.getName()+" as property " +
- "where property.key = '"+key+"'"
- ).uniqueResult();
+ return (PropertyImpl) session.createCriteria(PropertyImpl.class)
+ .add(Restrictions.eq("key", key))
+ .uniqueResult();
}
// getters and setters //////////////////////////////////////////////////////
More information about the jbpm-commits
mailing list