[jbpm-commits] JBoss JBPM SVN: r1869 - jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Aug 12 06:23:37 EDT 2008


Author: porcherg
Date: 2008-08-12 06:23:37 -0400 (Tue, 12 Aug 2008)
New Revision: 1869

Modified:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/Db.java
Log:
don't open environment to clean the db (get objects from environmentFactory)

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/Db.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/Db.java	2008-08-12 10:20:33 UTC (rev 1868)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/test/base/Db.java	2008-08-12 10:23:37 UTC (rev 1869)
@@ -25,6 +25,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.hibernate.FlushMode;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.cfg.Configuration;
@@ -33,8 +34,6 @@
 import org.hibernate.engine.SessionFactoryImplementor;
 import org.hibernate.mapping.ForeignKey;
 import org.hibernate.mapping.Table;
-import org.jbpm.pvm.env.Context;
-import org.jbpm.pvm.env.Environment;
 import org.jbpm.pvm.env.EnvironmentFactory;
 
 
@@ -46,81 +45,77 @@
   private static final String CLEAN_SQL_KEY = "cleanSql";
 
   public static void clean(EnvironmentFactory environmentFactory) {
-    Environment environment = environmentFactory.openEnvironment();
-    try {
-      SessionFactory sessionFactory = environment.get(SessionFactory.class);
-      String[] cleanSql = (String[]) environment.getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY).get(CLEAN_SQL_KEY);
-  
-      if (cleanSql == null) {
-        Configuration configuration = environment.get(Configuration.class);
-        
-        SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
-        Dialect dialect = sessionFactoryImplementor.getDialect();
-  
-        // loop over all foreign key constraints
-        List<String> dropForeignKeysSql = new ArrayList<String>();
-        List<String> createForeignKeysSql = new ArrayList<String>();
-        Iterator<Table> iter = configuration.getTableMappings();
-        while (iter.hasNext()) {
-          Table table = (Table) iter.next();
-          if (table.isPhysicalTable()) {
-            String catalog = table.getCatalog();
-            String schema = table.getSchema();
-            Iterator<ForeignKey> subIter = table.getForeignKeyIterator();
-            while (subIter.hasNext()) {
-              ForeignKey fk = (ForeignKey) subIter.next();
-              if (fk.isPhysicalConstraint()) {
-                // collect the drop foreign key constraint sql
-                dropForeignKeysSql.add(fk.sqlDropString(dialect, catalog, schema));
-                // MySQLDialect creates an index for each foreign key.
-                // see
-                // http://opensource.atlassian.com/projects/hibernate/browse/HHH-2155
-                // This index should be dropped or an error will be thrown during
-                // the creation phase
-                if (dialect instanceof MySQLDialect) {
-                  dropForeignKeysSql.add("alter table " + table.getName() + " drop key " + fk.getName());
-                }
-                // and collect the create foreign key constraint sql
-                createForeignKeysSql.add(fk.sqlCreateString(dialect, sessionFactoryImplementor, catalog, schema));
+    SessionFactory sessionFactory = environmentFactory.get(SessionFactory.class);
+    String[] cleanSql = (String[]) environmentFactory.get(CLEAN_SQL_KEY);
+
+    if (cleanSql == null) {
+      Configuration configuration = environmentFactory.get(Configuration.class);
+      
+      SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
+      Dialect dialect = sessionFactoryImplementor.getDialect();
+
+      // loop over all foreign key constraints
+      List<String> dropForeignKeysSql = new ArrayList<String>();
+      List<String> createForeignKeysSql = new ArrayList<String>();
+      Iterator<Table> iter = configuration.getTableMappings();
+      while (iter.hasNext()) {
+        Table table = (Table) iter.next();
+        if (table.isPhysicalTable()) {
+          String catalog = table.getCatalog();
+          String schema = table.getSchema();
+          Iterator<ForeignKey> subIter = table.getForeignKeyIterator();
+          while (subIter.hasNext()) {
+            ForeignKey fk = (ForeignKey) subIter.next();
+            if (fk.isPhysicalConstraint()) {
+              // collect the drop foreign key constraint sql
+              dropForeignKeysSql.add(fk.sqlDropString(dialect, catalog, schema));
+              // MySQLDialect creates an index for each foreign key.
+              // see
+              // http://opensource.atlassian.com/projects/hibernate/browse/HHH-2155
+              // This index should be dropped or an error will be thrown during
+              // the creation phase
+              if (dialect instanceof MySQLDialect) {
+                dropForeignKeysSql.add("alter table " + table.getName() + " drop key " + fk.getName());
               }
+              // and collect the create foreign key constraint sql
+              createForeignKeysSql.add(fk.sqlCreateString(dialect, sessionFactoryImplementor, catalog, schema));
             }
           }
         }
-  
-        List<String> deleteSql = new ArrayList<String>();
-        iter = configuration.getTableMappings();
-        while (iter.hasNext()) {
-          Table table = (Table) iter.next();
-          if (table.isPhysicalTable()) {
-            deleteSql.add("delete from " + table.getName());
-          }
-        }
-  
-        // glue
-        // - drop foreign key constraints
-        // - delete contents of all tables
-        // - create foreign key constraints
-        // together to form the clean script
-        List<String> cleanSqlList = new ArrayList<String>();
-        cleanSqlList.addAll(dropForeignKeysSql);
-        cleanSqlList.addAll(deleteSql);
-        cleanSqlList.addAll(createForeignKeysSql);
-  
-        cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
-        
-        environment.getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY).set(CLEAN_SQL_KEY, cleanSql);
       }
-  
-      Session session = sessionFactory.openSession();
-      try {
-        for (String query : cleanSql) {
-          session.createSQLQuery(query).executeUpdate();
+
+      List<String> deleteSql = new ArrayList<String>();
+      iter = configuration.getTableMappings();
+      while (iter.hasNext()) {
+        Table table = (Table) iter.next();
+        if (table.isPhysicalTable()) {
+          deleteSql.add("delete from " + table.getName());
         }
-      } finally {
-        session.close();
       }
+
+      // glue
+      // - drop foreign key constraints
+      // - delete contents of all tables
+      // - create foreign key constraints
+      // together to form the clean script
+      List<String> cleanSqlList = new ArrayList<String>();
+      cleanSqlList.addAll(dropForeignKeysSql);
+      cleanSqlList.addAll(deleteSql);
+      cleanSqlList.addAll(createForeignKeysSql);
+
+      cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
+      
+      environmentFactory.set(CLEAN_SQL_KEY, cleanSql);
+    }
+
+    Session session = sessionFactory.openSession();
+    session.setFlushMode(FlushMode.COMMIT);
+    try {
+      for (String query : cleanSql) {
+        session.createSQLQuery(query).executeUpdate();
+      }
     } finally {
-      environment.close();
+      session.close();
     }
   }
 




More information about the jbpm-commits mailing list