[jbpm-commits] JBoss JBPM SVN: r2999 - in jbpm3/trunk/modules: db and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Nov 19 11:16:01 EST 2008
Author: thomas.diesler at jboss.com
Date: 2008-11-19 11:16:01 -0500 (Wed, 19 Nov 2008)
New Revision: 2999
Added:
jbpm3/trunk/modules/db/src/main/resources/mysql.properties
jbpm3/trunk/modules/db/src/main/resources/sybase.properties
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/ant/AntHelper.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/ant/JbpmSchemaTask.java
jbpm3/trunk/modules/db/pom.xml
jbpm3/trunk/modules/db/scripts/antrun-jbpmschema.xml
Log:
Restore SchemaUpdate functionality
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/ant/AntHelper.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/ant/AntHelper.java 2008-11-19 13:05:33 UTC (rev 2998)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/ant/AntHelper.java 2008-11-19 16:16:01 UTC (rev 2999)
@@ -37,43 +37,60 @@
/**
* common strategy for jbpm ant tasks to obtain a hibernate SessionFactory.
*/
-public abstract class AntHelper {
-
+public abstract class AntHelper
+{
+
final static Map configurations = new HashMap();
final static Map jbpmConfigurations = new HashMap();
- public static Configuration getConfiguration(String hibernateCfgResource, String hibernatePropertiesResource) {
- Object key = getKey(hibernateCfgResource,hibernatePropertiesResource);
- Configuration configuration = (Configuration) configurations.get(key);
- if (configuration==null) {
- log.debug("creating hibernate configuration from cfg '"+hibernateCfgResource+"' and properties '"+hibernatePropertiesResource+"'");
+ public static Configuration getConfiguration(String hibernateCfgResource, String hibernatePropertiesResource)
+ {
+ Object key = getKey(hibernateCfgResource, hibernatePropertiesResource);
+ Configuration configuration = (Configuration)configurations.get(key);
+ if (configuration == null)
+ {
+ log.debug("creating hibernate configuration from cfg '" + hibernateCfgResource + "' and properties '" + hibernatePropertiesResource + "'");
configuration = new Configuration();
configuration.configure(hibernateCfgResource);
- if (hibernatePropertiesResource!=null) {
- try {
- InputStream propertiesInputStream = AntHelper.class.getClassLoader().getResourceAsStream(hibernatePropertiesResource);
- log.debug("properties input stream: "+propertiesInputStream);
+ if (hibernatePropertiesResource != null)
+ {
+ try
+ {
+ InputStream propertiesInputStream = AntHelper.class.getResourceAsStream(hibernatePropertiesResource);
+ if (propertiesInputStream == null)
+ throw new IllegalArgumentException("Cannot read properties: " + hibernatePropertiesResource);
+
Properties properties = new Properties();
properties.load(propertiesInputStream);
configuration.setProperties(properties);
- } catch (Exception e) {
- throw new JbpmException("couldn't set properties '"+hibernatePropertiesResource+"'", e);
}
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ throw new JbpmException("couldn't set properties '" + hibernatePropertiesResource + "'", ex);
+ }
}
configurations.put(key, configuration);
- } else {
- log.debug("got hibernate configuration from cfg '"+hibernateCfgResource+"' and properties '"+hibernatePropertiesResource+"' from the cache");
}
+ else
+ {
+ log.debug("got hibernate configuration from cfg '" + hibernateCfgResource + "' and properties '" + hibernatePropertiesResource + "' from the cache");
+ }
return configuration;
}
- public static JbpmConfiguration getJbpmConfiguration(String jbpmCfg) {
- JbpmConfiguration jbpmConfiguration = (JbpmConfiguration) jbpmConfigurations.get(jbpmCfg);
- if (jbpmConfiguration==null) {
- if (jbpmCfg==null) {
+ public static JbpmConfiguration getJbpmConfiguration(String jbpmCfg)
+ {
+ JbpmConfiguration jbpmConfiguration = (JbpmConfiguration)jbpmConfigurations.get(jbpmCfg);
+ if (jbpmConfiguration == null)
+ {
+ if (jbpmCfg == null)
+ {
jbpmConfiguration = JbpmConfiguration.getInstance();
- } else {
+ }
+ else
+ {
jbpmConfiguration = JbpmConfiguration.getInstance(jbpmCfg);
}
@@ -82,7 +99,8 @@
return jbpmConfiguration;
}
- static Object getKey(String cfg, String properties) {
+ static Object getKey(String cfg, String properties)
+ {
List key = new ArrayList();
key.add(cfg);
key.add(properties);
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/ant/JbpmSchemaTask.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/ant/JbpmSchemaTask.java 2008-11-19 13:05:33 UTC (rev 2998)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/ant/JbpmSchemaTask.java 2008-11-19 16:16:01 UTC (rev 2999)
@@ -21,31 +21,107 @@
*/
package org.jbpm.ant;
-import java.util.StringTokenizer;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.List;
+import java.util.Properties;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.tool.hbm2ddl.SchemaUpdate;
+import org.hibernate.util.ConfigHelper;
public class JbpmSchemaTask extends Task
{
- String hibernateCfg;
+ String config;
+ String properties;
+ String action;
String output;
String delimiter;
- String action;
public void execute() throws BuildException
{
if (action == null)
action = "create";
- if (hibernateCfg == null)
- hibernateCfg = "hibernate.cfg.xml";
+ if (config == null)
+ config = "hibernate.cfg.xml";
- log("using hibernate configuration " + hibernateCfg);
- Configuration configuration = AntHelper.getConfiguration(hibernateCfg, null);
+ List<Exception> exceptions = null;
+ try
+ {
+ Configuration configuration = getConfiguration();
+ if ("drop".equalsIgnoreCase(action))
+ {
+ SchemaExport schemaExport = getSchemaExport(configuration);
+ schemaExport.execute(false, false, true, false);
+ exceptions = schemaExport.getExceptions();
+ }
+ else if ("create".equalsIgnoreCase(action))
+ {
+ SchemaExport schemaExport = getSchemaExport(configuration);
+ schemaExport.execute(false, false, false, true);
+ exceptions = schemaExport.getExceptions();
+ }
+ else if ("update".equalsIgnoreCase(action))
+ {
+ PrintStream sysout = System.out;
+ try
+ {
+ if (output != null)
+ {
+ PrintStream prstr = new PrintStream(new FileOutputStream(output));
+ System.setOut(prstr);
+ }
+ SchemaUpdate schemaUpdate = getSchemaUpdate(configuration);
+ schemaUpdate.execute(true, false);
+ exceptions = schemaUpdate.getExceptions();
+ }
+ finally
+ {
+ System.setOut(sysout);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unsupported action: " + action);
+ }
+ }
+ catch (IOException ex)
+ {
+ throw new BuildException(ex);
+ }
+ // Print the exceptions if there are any
+ for (Exception ex : exceptions)
+ log(ex.toString());
+ }
+
+ private Configuration getConfiguration() throws IOException
+ {
+ log("Action '" + action + "' using " + config + "," + properties);
+ Configuration configuration = new Configuration();
+ configuration.configure(config);
+
+ if (properties != null)
+ {
+ InputStream inStream = ConfigHelper.getResourceAsStream(properties);
+ if (inStream == null)
+ throw new IllegalArgumentException("Cannot read properties: " + properties);
+
+ Properties properties = new Properties();
+ properties.load(inStream);
+ configuration.setProperties(properties);
+ }
+ return configuration;
+ }
+
+ private SchemaExport getSchemaExport(Configuration configuration)
+ {
SchemaExport schemaExport = new SchemaExport(configuration);
if (output != null)
@@ -55,15 +131,13 @@
schemaExport.setDelimiter(delimiter);
schemaExport.setFormat(false);
+ return schemaExport;
+ }
- if ("drop".equalsIgnoreCase(action))
- {
- schemaExport.execute(false, false, true, false);
- }
- else if ("create".equalsIgnoreCase(action))
- {
- schemaExport.execute(false, false, false, true);
- }
+ private SchemaUpdate getSchemaUpdate(Configuration configuration)
+ {
+ SchemaUpdate schemaUpdate = new SchemaUpdate(configuration);
+ return schemaUpdate;
}
public void setAction(String action)
@@ -71,11 +145,16 @@
this.action = action;
}
- public void setHibernateCfg(String hibernateCfg)
+ public void setConfig(String config)
{
- this.hibernateCfg = hibernateCfg;
+ this.config = config;
}
+ public void setProperties(String properties)
+ {
+ this.properties = properties;
+ }
+
public void setDelimiter(String delimiter)
{
this.delimiter = delimiter;
Modified: jbpm3/trunk/modules/db/pom.xml
===================================================================
--- jbpm3/trunk/modules/db/pom.xml 2008-11-19 13:05:33 UTC (rev 2998)
+++ jbpm3/trunk/modules/db/pom.xml 2008-11-19 16:16:01 UTC (rev 2999)
@@ -53,11 +53,22 @@
<classifier>config</classifier>
<version>${version}</version>
</dependency>
+
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.jtds</groupId>
+ <artifactId>jtds</artifactId>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
<!-- Plugins -->
@@ -75,7 +86,8 @@
<configuration>
<tasks>
<property name="maven.runtime.classpath" refid="maven.runtime.classpath" />
- <ant antfile="scripts/antrun-jbpmschema.xml" target="jbpmschema" />
+ <ant antfile="scripts/antrun-jbpmschema.xml" target="create-schema" />
+ <ant antfile="scripts/antrun-jbpmschema.xml" target="update-schema" />
</tasks>
</configuration>
</execution>
Modified: jbpm3/trunk/modules/db/scripts/antrun-jbpmschema.xml
===================================================================
--- jbpm3/trunk/modules/db/scripts/antrun-jbpmschema.xml 2008-11-19 13:05:33 UTC (rev 2998)
+++ jbpm3/trunk/modules/db/scripts/antrun-jbpmschema.xml 2008-11-19 16:16:01 UTC (rev 2999)
@@ -14,36 +14,47 @@
<!-- jBPM Database schema -->
<!-- ================================================================== -->
- <target name="jbpmschema" description="Generate jBPM Database schemas">
+ <target name="setup-schema">
- <!--echo message="${maven.runtime.classpath}"/-->
+ <!-- echo message="${maven.runtime.classpath}"/ -->
<taskdef name="jbpmschema" classname="org.jbpm.ant.JbpmSchemaTask">
- <classpath path="${maven.runtime.classpath}" />
+ <classpath path="${maven.runtime.classpath}"/>
</taskdef>
- <property name="scriptsdir" value="${basedir}/target/classes" />
- <mkdir dir="${scriptsdir}" />
+ <property name="scriptsdir" value="${basedir}/target/classes"/>
+ <mkdir dir="${scriptsdir}"/>
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.db2.sql" hibernateCfg="hibernate.cfg.db2.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.derby.sql" hibernateCfg="hibernate.cfg.derby.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.firebird.sql" hibernateCfg="hibernate.cfg.firebird.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.hsqldb.sql" hibernateCfg="hibernate.cfg.hsqldb.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.ingres.sql" hibernateCfg="hibernate.cfg.ingres.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.interbase.sql" hibernateCfg="hibernate.cfg.interbase.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.mckoi.sql" hibernateCfg="hibernate.cfg.mckoi.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.mssql.sql" hibernateCfg="hibernate.cfg.mssql.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.mysql.sql" hibernateCfg="hibernate.cfg.mysql.xml" action="create" delimiter=";"/>
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.oracle.sql" hibernateCfg="hibernate.cfg.oracle.xml" delimiter=";" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.postgresql.sql" hibernateCfg="hibernate.cfg.postgresql.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.sapdb.sql" hibernateCfg="hibernate.cfg.sapdb.xml" action="create" />
- <jbpmschema output="${scriptsdir}/jbpm.jpdl.sybase.sql" hibernateCfg="hibernate.cfg.sybase.xml" action="create" />
-
- <!--[JBPM-1813] Fix create schema generation -->
- <!--jbpmschema output="${scriptsdir}/jbpm.jpdl.informix.sql" hibernateCfg="hibernate.cfg.informix.xml" action="create"/-->
- <!--jbpmschema output="${scriptsdir}/jbpm.jpdl.pointbase.sql" hibernateCfg="hibernate.cfg.pointbase.xml" action="create"/-->
- <!--jbpmschema output="${scriptsdir}/jbpm.jpdl.progress.sql" hibernateCfg="hibernate.cfg.progress.xml" action="create"/-->
-
</target>
+ <target name="create-schema" depends="setup-schema" description="Generate jBPM Database Schemas">
+
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.db2.sql" config="hibernate.cfg.db2.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.derby.sql" config="hibernate.cfg.derby.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.firebird.sql" config="hibernate.cfg.firebird.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.hsqldb.sql" config="hibernate.cfg.hsqldb.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.ingres.sql" config="hibernate.cfg.ingres.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.interbase.sql" config="hibernate.cfg.interbase.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.mckoi.sql" config="hibernate.cfg.mckoi.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.mssql.sql" config="hibernate.cfg.mssql.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.mysql.sql" config="hibernate.cfg.mysql.xml" action="create" delimiter=";"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.oracle.sql" config="hibernate.cfg.oracle.xml" action="create" delimiter=";"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.postgresql.sql" config="hibernate.cfg.postgresql.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.sapdb.sql" config="hibernate.cfg.sapdb.xml" action="create"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.sybase.sql" config="hibernate.cfg.sybase.xml" action="create"/>
+
+ <!--[JBPM-1813] Fix create schema generation -->
+ <!--jbpmschema output="${scriptsdir}/jbpm.jpdl.informix.sql" config="hibernate.cfg.informix.xml" action="create"/-->
+ <!--jbpmschema output="${scriptsdir}/jbpm.jpdl.pointbase.sql" config="hibernate.cfg.pointbase.xml" action="create"/-->
+ <!--jbpmschema output="${scriptsdir}/jbpm.jpdl.progress.sql" config="hibernate.cfg.progress.xml" action="create"/-->
+
+ </target>
+
+ <target name="update-schema" depends="setup-schema" description="Generate jBPM Database Update Scripts">
+
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.mysql.update322.sql" config="hibernate.cfg.mysql.xml" properties="mysql.properties" action="update" delimiter=";"/>
+ <jbpmschema output="${scriptsdir}/jbpm.jpdl.sybase.update322.sql" config="hibernate.cfg.sybase.xml" properties="sybase.properties" action="update" delimiter=";"/>
+
+ </target>
+
</project>
Added: jbpm3/trunk/modules/db/src/main/resources/mysql.properties
===================================================================
--- jbpm3/trunk/modules/db/src/main/resources/mysql.properties (rev 0)
+++ jbpm3/trunk/modules/db/src/main/resources/mysql.properties 2008-11-19 16:16:01 UTC (rev 2999)
@@ -0,0 +1,6 @@
+hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
+hibernate.connection.driver_class=com.mysql.jdbc.Driver
+hibernate.connection.url=jdbc:mysql://localhost:3306/jbpm322
+hibernate.connection.username=jbpmtest
+hibernate.connection.password=
+hibernate.query.substitutions=true 1, false 0
\ No newline at end of file
Added: jbpm3/trunk/modules/db/src/main/resources/sybase.properties
===================================================================
--- jbpm3/trunk/modules/db/src/main/resources/sybase.properties (rev 0)
+++ jbpm3/trunk/modules/db/src/main/resources/sybase.properties 2008-11-19 16:16:01 UTC (rev 2999)
@@ -0,0 +1,5 @@
+hibernate.dialect=org.hibernate.dialect.SybaseDialect
+hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver
+hibernate.connection.url=jdbc:jtds:sybase://localhost:5000/jbpm322
+hibernate.connection.username=jbpmtest
+hibernate.connection.password=jbpmtest
More information about the jbpm-commits
mailing list