[jbpm-commits] JBoss JBPM SVN: r5054 - in jbpm3/branches/jbpm-3.2-soa: modules/core/src/main/java/org/jbpm/db and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Jun 17 17:20:43 EDT 2009


Author: alex.guizar at jboss.com
Date: 2009-06-17 17:20:43 -0400 (Wed, 17 Jun 2009)
New Revision: 5054

Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceServiceFactory.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java
   jbpm3/branches/jbpm-3.2-soa/profiles.xml.example
Log:
JBPM-2292: Move jBPM3-SOA continuous integration to QA lab (RESOLVED)
Have JbpmSchema recreate the connection provider in each operation as SchemaExport does

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java	2009-06-17 17:24:36 UTC (rev 5053)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java	2009-06-17 21:20:43 UTC (rev 5054)
@@ -25,7 +25,6 @@
 
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -80,9 +79,8 @@
     Configuration configuration = persistenceServiceFactory.getConfiguration();
     JbpmSchema jbpmSchema = new JbpmSchema(configuration);
 
-    Map rowsPerTable = jbpmSchema.getRowsPerTable();
-    for (Iterator i = rowsPerTable.entrySet().iterator(); i.hasNext();) {
-      Map.Entry entry = (Entry) i.next();
+    for (Iterator i = jbpmSchema.getRowsPerTable().entrySet().iterator(); i.hasNext();) {
+      Map.Entry entry = (Map.Entry) i.next();
       Long count = (Long) entry.getValue();
       if (count.intValue() != 0) {
         hasLeftOvers = true;

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java	2009-06-17 17:24:36 UTC (rev 5053)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java	2009-06-17 21:20:43 UTC (rev 5054)
@@ -46,6 +46,7 @@
 import org.hibernate.cfg.Configuration;
 import org.hibernate.cfg.Settings;
 import org.hibernate.connection.ConnectionProvider;
+import org.hibernate.connection.ConnectionProviderFactory;
 import org.hibernate.mapping.Table;
 import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
 import org.hibernate.tool.hbm2ddl.TableMetadata;
@@ -58,17 +59,17 @@
  */
 public class JbpmSchema {
 
-  final Configuration configuration;
-  final Settings settings;
+  private final Configuration configuration;
+  private final Settings settings;
 
-  ConnectionProvider connectionProvider = null;
-  Connection connection = null;
+  private ConnectionProvider connectionProvider;
+  private Connection connection;
 
-  final List exceptions = new ArrayList();
+  private final List exceptions = new ArrayList();
 
   public JbpmSchema(Configuration configuration) {
     this.configuration = configuration;
-    this.settings = configuration.buildSettings();
+    settings = configuration.buildSettings();
   }
 
   public String[] getCreateSql() {
@@ -101,8 +102,7 @@
 
       DatabaseMetaData metaData = connection.getMetaData();
       boolean storesLowerCaseIdentifiers = metaData.storesLowerCaseIdentifiers();
-      ResultSet resultSet = metaData.getTables(settings.getDefaultCatalogName(),
-          settings.getDefaultSchemaName(), null, new String[] { "TABLE" });
+      ResultSet resultSet = metaData.getTables(settings.getDefaultCatalogName(), settings.getDefaultSchemaName(), null, new String[] { "TABLE" });
       try {
         while (resultSet.next()) {
           String tableName = resultSet.getString("TABLE_NAME");
@@ -218,8 +218,7 @@
 
   public void createTable(String tableName) {
     Table table = findTableMapping(tableName);
-    String sql = table.sqlCreateString(settings.getDialect(), configuration.buildMapping(),
-        settings.getDefaultCatalogName(), settings.getDefaultSchemaName());
+    String sql = table.sqlCreateString(settings.getDialect(), configuration.buildMapping(), settings.getDefaultCatalogName(), settings.getDefaultSchemaName());
     try {
       execute(new String[] { sql });
     }
@@ -232,9 +231,7 @@
     Table table = findTableMapping(tableName);
     try {
       createConnection();
-      Iterator sqls = table.sqlAlterStrings(settings.getDialect(), configuration.buildMapping(),
-          getTableMetadata(table), settings.getDefaultCatalogName(),
-          settings.getDefaultSchemaName());
+      Iterator sqls = table.sqlAlterStrings(settings.getDialect(), configuration.buildMapping(), getTableMetadata(table), settings.getDefaultCatalogName(), settings.getDefaultSchemaName());
 
       Statement statement = connection.createStatement();
       while (sqls.hasNext()) {
@@ -267,43 +264,47 @@
 
   private TableMetadata getTableMetadata(Table table) throws SQLException {
     DatabaseMetadata databaseMetadata = new DatabaseMetadata(connection, settings.getDialect());
-    return databaseMetadata.getTableMetadata(table.getName(),
-        table.getSchema() == null ? settings.getDefaultSchemaName() : table.getSchema(),
-        table.getCatalog() == null ? settings.getDefaultCatalogName() : table.getCatalog(),
-        table.isQuoted());
+    return databaseMetadata.getTableMetadata(table.getName(), table.getSchema() == null ? settings.getDefaultSchemaName()
+        : table.getSchema(), table.getCatalog() == null ? settings.getDefaultCatalogName()
+        : table.getCatalog(), table.isQuoted());
   }
 
   public static void main(String[] args) {
-    if ((args == null) || (args.length == 0)) {
-      syntax();
+    if (args.length == 0) syntax();
+
+    if ("scripts".equalsIgnoreCase(args[0]) && args.length >= 3 && args.length <= 5) {
+      JbpmSchema jbpmSchema = new JbpmSchema(createConfiguration(args, 3));
+      jbpmSchema.saveSqlScripts(args[1], args[2]);
     }
-    else if ("create".equalsIgnoreCase(args[0]) && args.length <= 3) {
-      Configuration configuration = createConfiguration(args, 1);
-      new JbpmSchema(configuration).createSchema();
+    else if (args.length <= 3) {
+      if ("create".equalsIgnoreCase(args[0])) {
+        JbpmSchema jbpmSchema = new JbpmSchema(createConfiguration(args, 1));
+        jbpmSchema.createSchema();
+      }
+      else if ("drop".equalsIgnoreCase(args[0])) {
+        JbpmSchema jbpmSchema = new JbpmSchema(createConfiguration(args, 1));
+        jbpmSchema.dropSchema();
+      }
+      else if ("clean".equalsIgnoreCase(args[0])) {
+        JbpmSchema jbpmSchema = new JbpmSchema(createConfiguration(args, 1));
+        jbpmSchema.cleanSchema();
+      }
+      else {
+        syntax();
+      }
     }
-    else if ("drop".equalsIgnoreCase(args[0]) && args.length <= 3) {
-      Configuration configuration = createConfiguration(args, 1);
-      new JbpmSchema(configuration).dropSchema();
-    }
-    else if ("clean".equalsIgnoreCase(args[0]) && args.length <= 3) {
-      Configuration configuration = createConfiguration(args, 1);
-      new JbpmSchema(configuration).cleanSchema();
-    }
-    else if ("scripts".equalsIgnoreCase(args[0]) && args.length >= 3 && args.length <= 5) {
-      Configuration configuration = createConfiguration(args, 3);
-      new JbpmSchema(configuration).saveSqlScripts(args[1], args[2]);
-    }
     else {
       syntax();
     }
   }
 
   private static void syntax() {
-    System.err.println("syntax:");
+    System.err.println("Syntax:");
     System.err.println("JbpmSchema create [<hibernate.cfg.xml> [<hibernate.properties>]]");
     System.err.println("JbpmSchema drop [<hibernate.cfg.xml> [<hibernate.properties>]]");
     System.err.println("JbpmSchema clean [<hibernate.cfg.xml> [<hibernate.properties>]]");
     System.err.println("JbpmSchema scripts <dir> <prefix> [<hibernate.cfg.xml> [<hibernate.properties>]]");
+    System.exit(1);
   }
 
   static Configuration createConfiguration(String[] args, int index) {
@@ -365,9 +366,9 @@
   }
 
   void createConnection() throws SQLException {
-    connectionProvider = settings.getConnectionProvider();
+    connectionProvider = ConnectionProviderFactory.newConnectionProvider(configuration.getProperties());
     connection = connectionProvider.getConnection();
-    if (!connection.getAutoCommit()) {
+    if (connection.getAutoCommit() == false) {
       connection.commit();
       connection.setAutoCommit(true);
     }
@@ -383,7 +384,10 @@
         log.debug("could not close " + connection, e);
       }
       finally {
+        connection = null;
+
         connectionProvider.close();
+        connectionProvider = null;
       }
     }
   }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceServiceFactory.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceServiceFactory.java	2009-06-17 17:24:36 UTC (rev 5053)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceServiceFactory.java	2009-06-17 21:20:43 UTC (rev 5054)
@@ -35,8 +35,7 @@
 import org.jbpm.svc.ServiceFactory;
 import org.jbpm.util.JndiUtil;
 
-public class DbPersistenceServiceFactory implements ServiceFactory
-{
+public class DbPersistenceServiceFactory implements ServiceFactory {
 
   private static final long serialVersionUID = 1L;
 
@@ -52,25 +51,21 @@
   boolean isCurrentSessionEnabled = false;
 
   SchemaExport schemaExport = null;
+  JbpmSchema jbpmSchema = null;
 
-  public Service openService()
-  {
+  public Service openService() {
     log.debug("creating persistence service");
     return new DbPersistenceService(this);
   }
 
-  public synchronized Configuration getConfiguration()
-  {
-    if (configuration == null)
-    {
+  public synchronized Configuration getConfiguration() {
+    if (configuration == null) {
       String hibernateCfgXmlResource = null;
-      if (JbpmConfiguration.Configs.hasObject("resource.hibernate.cfg.xml"))
-      {
+      if (JbpmConfiguration.Configs.hasObject("resource.hibernate.cfg.xml")) {
         hibernateCfgXmlResource = JbpmConfiguration.Configs.getString("resource.hibernate.cfg.xml");
       }
       String hibernatePropertiesResource = null;
-      if (JbpmConfiguration.Configs.hasObject("resource.hibernate.properties"))
-      {
+      if (JbpmConfiguration.Configs.hasObject("resource.hibernate.properties")) {
         hibernatePropertiesResource = JbpmConfiguration.Configs.getString("resource.hibernate.properties");
       }
       configuration = HibernateHelper.createConfiguration(hibernateCfgXmlResource, hibernatePropertiesResource);
@@ -78,29 +73,31 @@
     return configuration;
   }
 
-  public synchronized SchemaExport getSchemaExport()
-  {
-    if (schemaExport == null)
-    {
+  public synchronized SchemaExport getSchemaExport() {
+    if (schemaExport == null) {
       log.debug("creating schema export");
       schemaExport = new SchemaExport(getConfiguration());
     }
     return schemaExport;
   }
 
-  public synchronized SessionFactory getSessionFactory()
-  {
-    if (sessionFactory == null)
-    {
+  public synchronized JbpmSchema getJbpmSchema() {
+    if (jbpmSchema == null) {
+      log.debug("creating jbpm schema tool");
+      jbpmSchema = new JbpmSchema(getConfiguration());
+    }
+    return jbpmSchema;
+  }
 
-      if (sessionFactoryJndiName != null)
-      {
+  public synchronized SessionFactory getSessionFactory() {
+    if (sessionFactory == null) {
+
+      if (sessionFactoryJndiName != null) {
         log.debug("looking up hibernate session factory in jndi '" + sessionFactoryJndiName + "'");
-        sessionFactory = (SessionFactory)JndiUtil.lookup(sessionFactoryJndiName, SessionFactory.class);
+        sessionFactory = (SessionFactory) JndiUtil.lookup(sessionFactoryJndiName, SessionFactory.class);
 
       }
-      else
-      {
+      else {
         log.debug("building hibernate session factory");
         sessionFactory = getConfiguration().buildSessionFactory();
       }
@@ -108,116 +105,94 @@
     return sessionFactory;
   }
 
-  public DataSource getDataSource()
-  {
-    if ((dataSource == null) && (dataSourceJndiName != null))
-    {
+  public DataSource getDataSource() {
+    if ((dataSource == null) && (dataSourceJndiName != null)) {
       log.debug("looking up datasource from jndi location '" + dataSourceJndiName + "'");
-      dataSource = (DataSource)JndiUtil.lookup(dataSourceJndiName, DataSource.class);
+      dataSource = (DataSource) JndiUtil.lookup(dataSourceJndiName, DataSource.class);
     }
     return dataSource;
   }
 
-  public void cleanSchema()
-  {
-    new JbpmSchema(getConfiguration()).cleanSchema();
+  public void cleanSchema() {
+    getJbpmSchema().cleanSchema();
     HibernateHelper.clearHibernateCache(getSessionFactory());
   }
 
-  public void createSchema()
-  {
-    getSchemaExport().create(getScript(), true);
+  public void createSchema() {
+    getJbpmSchema().createSchema();
     HibernateHelper.clearHibernateCache(getSessionFactory());
   }
 
-  public void dropSchema()
-  {
+  public void dropSchema() {
+    getJbpmSchema().dropSchema();
     HibernateHelper.clearHibernateCache(getSessionFactory());
-    getSchemaExport().drop(getScript(), true);
   }
 
-  boolean getScript()
-  {
+  boolean getScript() {
     boolean script = false;
     String showSql = getConfiguration().getProperty("hibernate.show_sql");
-    if ("true".equalsIgnoreCase(showSql))
-    {
+    if ("true".equalsIgnoreCase(showSql)) {
       script = true;
     }
     return script;
   }
 
-  public void close()
-  {
-    if (sessionFactory != null)
-    {
+  public void close() {
+    if (sessionFactory != null) {
       log.debug("closing hibernate session factory");
       sessionFactory.close();
     }
   }
 
-  public void finalize() throws Throwable
-  {
+  public void finalize() throws Throwable {
     close();
   }
 
-  public String getDataSourceJndiName()
-  {
+  public String getDataSourceJndiName() {
     return dataSourceJndiName;
   }
 
-  public void setDataSourceJndiName(String dataSourceJndiName)
-  {
+  public void setDataSourceJndiName(String dataSourceJndiName) {
     this.dataSourceJndiName = dataSourceJndiName;
   }
 
-  public String getSessionFactoryJndiName()
-  {
+  public String getSessionFactoryJndiName() {
     return sessionFactoryJndiName;
   }
 
-  public void setSessionFactoryJndiName(String sessionFactoryJndiName)
-  {
+  public void setSessionFactoryJndiName(String sessionFactoryJndiName) {
     this.sessionFactoryJndiName = sessionFactoryJndiName;
   }
 
-  public void setConfiguration(Configuration configuration)
-  {
+  public void setConfiguration(Configuration configuration) {
     this.configuration = configuration;
   }
 
-  public void setDataSource(DataSource dataSource)
-  {
+  public void setDataSource(DataSource dataSource) {
     this.dataSource = dataSource;
   }
 
-  public void setSchemaExport(SchemaExport schemaExport)
-  {
+  public void setSchemaExport(SchemaExport schemaExport) {
     this.schemaExport = schemaExport;
   }
 
-  public void setSessionFactory(SessionFactory sessionFactory)
-  {
+  public void setSessionFactory(SessionFactory sessionFactory) {
     this.sessionFactory = sessionFactory;
   }
 
-  public boolean isTransactionEnabled()
-  {
+  public boolean isTransactionEnabled() {
     return isTransactionEnabled;
   }
 
-  public void setTransactionEnabled(boolean isTransactionEnabled)
-  {
+  public void setTransactionEnabled(boolean isTransactionEnabled) {
     this.isTransactionEnabled = isTransactionEnabled;
   }
 
-  public boolean isCurrentSessionEnabled()
-  {
+  public boolean isCurrentSessionEnabled() {
     return isCurrentSessionEnabled;
   }
 
-  public void setCurrentSessionEnabled(boolean isCurrentSessionEnabled)
-  {
+  public void setCurrentSessionEnabled(boolean isCurrentSessionEnabled) {
     this.isCurrentSessionEnabled = isCurrentSessionEnabled;
   }
 

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java	2009-06-17 17:24:36 UTC (rev 5053)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java	2009-06-17 21:20:43 UTC (rev 5054)
@@ -53,7 +53,10 @@
   public void testDropSchema() {
     jbpmSchema.dropSchema();
     Set existingTables = jbpmSchema.getExistingTables();
-    assert existingTables.removeAll(jbpmSchema.getJbpmTables()) == false : existingTables;
+    for (Iterator i = jbpmSchema.getJbpmTables().iterator(); i.hasNext();) {
+      String jbpmTable = (String) i.next();
+      assert !existingTables.contains(jbpmTable) : jbpmTable;
+    }
   }
 
   public void testCleanSchema() {

Modified: jbpm3/branches/jbpm-3.2-soa/profiles.xml.example
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/profiles.xml.example	2009-06-17 17:24:36 UTC (rev 5053)
+++ jbpm3/branches/jbpm-3.2-soa/profiles.xml.example	2009-06-17 21:20:43 UTC (rev 5054)
@@ -1,21 +1,19 @@
-<profilesXml 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/xsd/profiles-1.0.0.xsd">
+<profilesXml 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/xsd/profiles-1.0.0.xsd">
   <profiles>
-
     <!-- This profile can also be defined in ~/.m2/settings.xml -->   
     <profile>
-      <id>jboss-home-profile</id>
+      <id>local</id>
       <activation>
-        <property>
-          <name>user.name</name>
-        </property>
+        <activeByDefault>true</activeByDefault>
       </activation>
       <properties>
-        <jboss405.home>${user.home}/Downloads/jboss/jboss-4.0.5.GA</jboss405.home>
-        <jboss423.home>${user.home}/Downloads/jboss/jboss-4.2.3.GA</jboss423.home>
-        <jboss501.home>${user.home}/Downloads/jboss/jboss-5.0.1.GA</jboss501.home>
+        <jboss405.home>${user.home}/jboss-4.0.5.GA</jboss405.home>
+        <jboss423.home>${user.home}/jboss-4.2.3.GA</jboss423.home>
+        <jboss501.home>${user.home}/jboss-5.0.1.GA</jboss501.home>
 
-        <!--   
         <jdbc.mysql.server>localhost</jdbc.mysql.server>
         <jdbc.mysql.port>3306</jdbc.mysql.port>
         <jdbc.mysql.database>jbpmtest</jdbc.mysql.database>
@@ -38,9 +36,14 @@
         <jdbc.sybase.password>jbpmtest</jdbc.sybase.password>
         <jdbc.sybase.driver>com.sybase.jdbc3.jdbc.SybDriver</jdbc.sybase.driver>
         <jdbc.sybase.datasource>com.sybase.jdbc3.jdbc.SybXADataSource</jdbc.sybase.datasource>
-        -->
+        
+        <jdbc.oracle.server>localhost</jdbc.oracle.server>
+        <jdbc.oracle.port>1521</jdbc.oracle.port>
+        <jdbc.oracle.database>XE</jdbc.oracle.database>
+        <jdbc.oracle.url>jdbc:oracle:thin:@${jdbc.oracle.server}:${jdbc.oracle.port}:${jdbc.oracle.database}</jdbc.oracle.url>
+        <jdbc.oracle.username>jbpmtest</jdbc.oracle.username>
+        <jdbc.oracle.password>jbpmtest</jdbc.oracle.password>
       </properties>
     </profile>
-    
   </profiles>
 </profilesXml>




More information about the jbpm-commits mailing list