[jbpm-commits] JBoss JBPM SVN: r4193 - in jbpm3/branches/jbpm-3.2.5.SP/modules/core: src/main/java/org/jbpm/db and 3 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sat Mar 7 20:18:45 EST 2009
Author: alex.guizar at jboss.com
Date: 2009-03-07 20:18:45 -0500 (Sat, 07 Mar 2009)
New Revision: 4193
Modified:
jbpm3/branches/jbpm-3.2.5.SP/modules/core/pom.xml
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/SerializabilityTest.java
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/jbpm1755/JBPM1755Test.java
Log:
JBPM-2086: merge r3931 from trunk; fix clean, drop, create schema with JbpmSchema
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/pom.xml
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/pom.xml 2009-03-07 20:51:46 UTC (rev 4192)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/pom.xml 2009-03-08 01:18:45 UTC (rev 4193)
@@ -235,12 +235,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <excludes>
- <!-- [JBPM-1810] Fix clean, drop, create schema with JbpmSchema -->
- <exclude>org/jbpm/db/JbpmSchemaDbTest.java</exclude>
- </excludes>
- </configuration>
</plugin>
</plugins>
</build>
@@ -262,12 +256,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <excludes>
- <!-- [JBPM-1810] Fix clean, drop, create schema with JbpmSchema -->
- <exclude>org/jbpm/db/JbpmSchemaDbTest.java</exclude>
- </excludes>
- </configuration>
</plugin>
</plugins>
</build>
@@ -289,14 +277,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <excludes>
- <!-- [JBPM-1166] SEAM timer transaction integration -->
- <exclude>org/jbpm/seam/JobExecutorCustomizationTest.java</exclude>
- <!-- [JBPM-1810] Fix clean, drop, create schema with JbpmSchema -->
- <exclude>org/jbpm/db/JbpmSchemaDbTest.java</exclude>
- </excludes>
- </configuration>
</plugin>
</plugins>
</build>
@@ -318,12 +298,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <excludes>
- <!-- [JBPM-1810] Fix clean, drop, create schema with JbpmSchema -->
- <exclude>org/jbpm/db/JbpmSchemaDbTest.java</exclude>
- </excludes>
- </configuration>
</plugin>
</plugins>
</build>
@@ -345,12 +319,6 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <excludes>
- <!-- [JBPM-1810] Fix clean, drop, create schema with JbpmSchema -->
- <exclude>org/jbpm/db/JbpmSchemaDbTest.java</exclude>
- </excludes>
- </configuration>
</plugin>
</plugins>
</build>
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2009-03-07 20:51:46 UTC (rev 4192)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2009-03-08 01:18:45 UTC (rev 4193)
@@ -79,12 +79,11 @@
Configuration configuration = dbPersistenceServiceFactory.getConfiguration();
JbpmSchema jbpmSchema = new JbpmSchema(configuration);
- Map<String, Integer> recordCountPerTable = jbpmSchema.getRecordCountPerTable();
- for (Map.Entry<String, Integer> entry : recordCountPerTable.entrySet()) {
+ Map<String, Long> rowsPerTable = jbpmSchema.getRowsPerTable();
+ for (Map.Entry<String, Long> entry : rowsPerTable.entrySet()) {
// String tableName = entry.getKey();
- Integer count = entry.getValue();
-
- if ((count == null) || (count != 0)) {
+ Long count = entry.getValue();
+ if (count != 0) {
hasLeftOvers = true;
// [JBPM-1812] Fix tests that don't cleanup the database
// Only uncomment this if you intend to fix it. Otherwise it just generates noise.
@@ -94,8 +93,7 @@
}
if (hasLeftOvers) {
- // TODO: JBPM-1781
- // jbpmSchema.cleanSchema();
+ jbpmSchema.cleanSchema();
}
}
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java 2009-03-07 20:51:46 UTC (rev 4192)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java 2009-03-08 01:18:45 UTC (rev 4193)
@@ -27,26 +27,25 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
-import java.io.Serializable;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Settings;
import org.hibernate.connection.ConnectionProvider;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.engine.Mapping;
-import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.Table;
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
import org.hibernate.tool.hbm2ddl.TableMetadata;
@@ -56,16 +55,16 @@
/**
* utilities for the jBPM database schema.
*/
-public class JbpmSchema implements Serializable {
+public class JbpmSchema {
- private static final long serialVersionUID = 1L;
-
final Configuration configuration;
final Settings settings;
ConnectionProvider connectionProvider = null;
Connection connection = null;
+ final List<SQLException> exceptions = new ArrayList<SQLException>();
+
public JbpmSchema(Configuration configuration) {
this.configuration = configuration;
this.settings = configuration.buildSettings();
@@ -80,79 +79,65 @@
}
public String[] getCleanSql() {
- Dialect dialect = settings.getDialect();
- String catalog = settings.getDefaultCatalogName();
- String schema = settings.getDefaultSchemaName();
- Mapping mapping = configuration.buildMapping();
-
- // loop over all foreign key constraints
- List<String> dropForeignKeysSql = new ArrayList<String>();
- List<String> createForeignKeysSql = new ArrayList<String>();
- List<String> deleteSql = new ArrayList<String>();
-
- for (Iterator<?> ti = configuration.getTableMappings(); ti.hasNext();) {
- Table table = (Table) ti.next();
- if (!table.isPhysicalTable()) continue;
-
- for (Iterator<?> fki = table.getForeignKeyIterator(); fki.hasNext();) {
- ForeignKey fk = (ForeignKey) fki.next();
- if (!fk.isPhysicalConstraint()) continue;
-
- // collect the drop foreign key sql
- String sqlDropString = fk.sqlDropString(dialect, catalog, schema);
- dropForeignKeysSql.add(sqlDropString);
-
- // and collect the create foreign key sql
- String sqlCreateString = fk.sqlCreateString(dialect, mapping, catalog, schema);
- createForeignKeysSql.add(sqlCreateString);
- }
- 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
- return concat(dropForeignKeysSql, deleteSql, createForeignKeysSql);
+ return concat(getDropSql(), getCreateSql());
}
- private static String[] concat(List<?>... lists) {
- int length = 0;
- for (List<?> list : lists) {
- length += list.size();
- }
- String[] array = new String[length];
- int index = 0;
- for (List<?> list : lists) {
- for (Object element : list) {
- array[index++] = (String) element;
+ public Set<String> getJbpmTables() {
+ Set<String> jbpmTables = new HashSet<String>();
+ for (Iterator<?> i = configuration.getTableMappings(); i.hasNext();) {
+ Table table = (Table) i.next();
+ if (table.isPhysicalTable()) {
+ jbpmTables.add(table.getName());
}
}
- return array;
+ return jbpmTables;
}
- public List<String> getTableNames() {
- List<String> tableNames = new ArrayList<String>();
- for (Iterator<?> iter = configuration.getTableMappings(); iter.hasNext();) {
- Table table = (Table) iter.next();
- if (table.isPhysicalTable()) {
- tableNames.add(table.getName());
+ public Set<String> getExistingTables() {
+ try {
+ createConnection();
+ Set<String> existingTables = new HashSet<String>();
+
+ DatabaseMetaData metaData = connection.getMetaData();
+ boolean storesLowerCaseIdentifiers = metaData.storesLowerCaseIdentifiers();
+ ResultSet resultSet = metaData.getTables(settings.getDefaultCatalogName(),
+ settings.getDefaultSchemaName(), null, new String[] { "TABLE" });
+ try {
+ while (resultSet.next()) {
+ String tableName = resultSet.getString("TABLE_NAME");
+ if (storesLowerCaseIdentifiers) {
+ tableName = tableName.toUpperCase();
+ }
+ existingTables.add(tableName);
+ }
}
+ finally {
+ resultSet.close();
+ }
+ return existingTables;
}
- return tableNames;
+ catch (SQLException e) {
+ throw new JbpmException("could not get available table names", e);
+ }
+ finally {
+ closeConnection();
+ }
}
- public Map<String, Integer> getRecordCountPerTable() {
- Map<String, Integer> recordCounts = new HashMap<String, Integer>();
+ public Map<String, Long> getRowsPerTable() {
+ Map<String, Long> rowsPerTable = new HashMap<String, Long>();
try {
createConnection();
Statement statement = connection.createStatement();
- for (String tableName : getTableNames()) {
+ for (String tableName : getJbpmTables()) {
String sql = "SELECT COUNT(*) FROM " + tableName;
ResultSet resultSet = statement.executeQuery(sql);
- resultSet.next();
- recordCounts.put(tableName, resultSet.getInt(1));
+ if (!resultSet.next()) throw new JbpmException("empty result set: " + sql);
+
+ long count = resultSet.getLong(1);
+ if (resultSet.wasNull()) throw new JbpmException("count was null: " + sql);
+
+ rowsPerTable.put(tableName, count);
resultSet.close();
}
statement.close();
@@ -163,7 +148,7 @@
finally {
closeConnection();
}
- return recordCounts;
+ return rowsPerTable;
}
public void dropSchema() {
@@ -264,6 +249,10 @@
}
}
+ public List<SQLException> getExceptions() {
+ return exceptions;
+ }
+
private Table findTableMapping(String tableName) {
for (Iterator<?> i = configuration.getTableMappings(); i.hasNext();) {
Table table = (Table) i.next();
@@ -350,12 +339,20 @@
void execute(String... sqls) throws SQLException {
boolean showSql = settings.isShowSqlEnabled();
+ exceptions.clear();
try {
createConnection();
Statement statement = connection.createStatement();
for (String sql : sqls) {
if (showSql) System.out.println(sql);
- statement.executeUpdate(sql);
+ log.debug(sql);
+ try {
+ statement.executeUpdate(sql);
+ }
+ catch (SQLException e) {
+ exceptions.add(e);
+ log.debug(e.getMessage());
+ }
}
statement.close();
}
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/SerializabilityTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/SerializabilityTest.java 2009-03-07 20:51:46 UTC (rev 4192)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/SerializabilityTest.java 2009-03-08 01:18:45 UTC (rev 4193)
@@ -24,10 +24,6 @@
import java.io.File;
import java.io.Serializable;
import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
import org.jbpm.file.def.FileDefinitionFileSystemConfigTest;
import org.jbpm.util.ClassLoaderUtil;
@@ -36,18 +32,18 @@
String testRootDir = FileDefinitionFileSystemConfigTest.class.getProtectionDomain().getCodeSource().getLocation().getFile().toString();
- static Set excusedClasses = new HashSet(Arrays.asList(new String[] {
+ static final String[] excusedClasses = {
"org.jbpm.ant",
"org.jbpm.context.exe.JbpmType",
"org.jbpm.db.hibernate.ConverterEnumType",
"org.jbpm.db.hibernate.Converters",
"org.jbpm.db.hibernate.JbpmNamingStrategy",
- "org.jbpm.db.jmx.JbpmService",
"org.jbpm.db.AbstractDbTestCase",
"org.jbpm.db.ContextSession",
"org.jbpm.db.FileSession",
"org.jbpm.db.GraphSession",
"org.jbpm.db.JbpmSession",
+ "org.jbpm.db.JbpmSchema",
"org.jbpm.db.JobSession",
"org.jbpm.db.LoggingSession",
"org.jbpm.db.SchedulerSession",
@@ -62,11 +58,9 @@
"org.jbpm.instantiation.ProcessClassLoader",
"org.jbpm.instantiation.XmlInstantiator",
"org.jbpm.JbpmConfiguration",
- "org.jbpm.jmx.JbpmService",
"org.jbpm.job.executor.JobExecutorThread",
"org.jbpm.job.executor.LockMonitorThread",
"org.jbpm.jpdl.convert.Converter",
- "org.jbpm.jpdl.convert.Converter$1",
"org.jbpm.graph.action.ActionTypes",
"org.jbpm.graph.node.Fork$ForkedToken",
"org.jbpm.graph.node.InterleaveStart$DefaultInterleaver",
@@ -80,12 +74,6 @@
"org.jbpm.jpdl.xml.JpdlXmlReader",
"org.jbpm.jpdl.xml.JpdlXmlWriter",
"org.jbpm.jpdl.el",
- "org.jbpm.scheduler.impl.Scheduler",
- "org.jbpm.scheduler.impl.Scheduler$HistoryListener",
- "org.jbpm.scheduler.impl.SchedulerMain$1",
- "org.jbpm.scheduler.impl.SchedulerMain$LogListener",
- "org.jbpm.scheduler.impl.SchedulerMain",
- "org.jbpm.scheduler.impl.SchedulerThread",
"org.jbpm.security.authenticator.JBossAuthenticator",
"org.jbpm.security.authenticator.JbpmDefaultAuthenticator",
"org.jbpm.security.authenticator.SubjectAuthenticator",
@@ -95,22 +83,14 @@
"org.jbpm.security.authorizer.RolesAuthorizer",
"org.jbpm.security.filter.JbpmAuthenticationFilter",
"org.jbpm.command.service.CommandServiceImpl",
- "org.jbpm.msg.jms.JmsCommandFactory",
- "org.jbpm.msg.jms.JmsMessageConstants",
- "org.jbpm.msg.jms.JmsMessageUtils",
- "org.jbpm.bpel.ant.DBSchemaTask",
- "org.jbpm.bpel.ant.ServiceGeneratorTask",
- "org.jbpm.bpel.ant.DeployProcessTask",
- "org.jbpm.bpel.",
"org.jbpm.sim.",
- "org.jbpm.jsf.",
"org.jbpm.util.Clock",
"org.jbpm.util.CustomLoaderObjectInputStream",
"org.jbpm.web.JobExecutorLauncher",
"org.jbpm.web.JbpmConfigurationCloser",
"org.jbpm.JbpmContextTestHelper",
"org.jbpm.EventCallback$1"
- }));
+ };
public void testForNonSerializableClasses() {
File jbpmRoot = new File(testRootDir+"../classes/");
@@ -139,7 +119,7 @@
}
private void assertSerializabilityOfClass(String className) {
- Class clazz = ClassLoaderUtil.loadClass(className);
+ Class<?> clazz = ClassLoaderUtil.loadClass(className);
if ( ! ( Serializable.class.isAssignableFrom(clazz)
|| Modifier.isAbstract(clazz.getModifiers())
@@ -152,15 +132,11 @@
}
boolean isExcused(String className) {
- boolean isExcused = false;
- Iterator iter = excusedClasses.iterator();
- while (iter.hasNext() && !isExcused) {
- String excusedClassName = (String) iter.next();
- if (className.startsWith(excusedClassName)) {
- isExcused = true;
- }
+ for (String excusedClassName : excusedClasses) {
+ if (className.startsWith(excusedClassName))
+ return true;
}
- return isExcused;
+ return false;
}
}
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java 2009-03-07 20:51:46 UTC (rev 4192)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java 2009-03-08 01:18:45 UTC (rev 4193)
@@ -21,6 +21,9 @@
*/
package org.jbpm.db;
+import java.util.Map;
+import java.util.Set;
+
import org.hibernate.cfg.Configuration;
import org.jbpm.AbstractJbpmTestCase;
@@ -30,26 +33,38 @@
* @author thomas.diesler at jboss.com
* @since 06-Nov-2008
*/
-public class JbpmSchemaDbTest extends AbstractJbpmTestCase
-{
- public void testCleanSchema()
- {
- Configuration config = new Configuration().configure();
- JbpmSchema jbpmSchema = new JbpmSchema(config);
- jbpmSchema.cleanSchema();
+public class JbpmSchemaDbTest extends AbstractJbpmTestCase {
+
+ JbpmSchema jbpmSchema;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ jbpmSchema = new JbpmSchema(new Configuration().configure());
}
-
- public void testDropSchema()
- {
- Configuration config = new Configuration().configure();
- JbpmSchema jbpmSchema = new JbpmSchema(config);
+
+ public void testCreateSchema() {
+ jbpmSchema.createSchema();
+ Set<String> existingTables = jbpmSchema.getExistingTables();
+ assert existingTables.containsAll(jbpmSchema.getJbpmTables()) : existingTables;
+ }
+
+ public void testDropSchema() {
jbpmSchema.dropSchema();
+ Set<String> existingTables = jbpmSchema.getExistingTables();
+ for (String jbpmTable : jbpmSchema.getJbpmTables()) {
+ assert !existingTables.contains(jbpmTable) : existingTables;
+ }
}
- public void testCreateSchema()
- {
- Configuration config = new Configuration().configure();
- JbpmSchema jbpmSchema = new JbpmSchema(config);
- jbpmSchema.createSchema();
+ public void testCleanSchema() {
+ jbpmSchema.cleanSchema();
+ Map<String, Long> rowsPerTable = jbpmSchema.getRowsPerTable();
+ Set<String> existingTables = jbpmSchema.getExistingTables();
+ assert existingTables.containsAll(rowsPerTable.keySet()) : existingTables;
+
+ for (long rowCount : rowsPerTable.values()) {
+ assertEquals(0, rowCount);
+ }
}
}
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/jbpm1755/JBPM1755Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/jbpm1755/JBPM1755Test.java 2009-03-07 20:51:46 UTC (rev 4192)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/jbpm1755/JBPM1755Test.java 2009-03-08 01:18:45 UTC (rev 4193)
@@ -25,12 +25,10 @@
protected void setUp() throws Exception {
super.setUp();
processDefinition = ProcessDefinition.parseXmlResource("org/jbpm/jbpm1755/parallelprocess.xml");
- startJobExecutor();
}
@Override
protected void tearDown() throws Exception {
- stopJobExecutor();
graphSession.deleteProcessDefinition(processDefinition.getId());
EventCallback.clear();
super.tearDown();
@@ -65,9 +63,11 @@
commitAndCloseSession();
try {
+ startJobExecutor();
EventCallback.waitForEvent(processInstanceCount, Event.EVENTTYPE_PROCESS_END);
}
finally {
+ stopJobExecutor();
beginSessionTransaction();
}
More information about the jbpm-commits
mailing list