You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by sa...@apache.org on 2015/08/07 22:23:10 UTC

[2/3] ode git commit: ODE-666: Ported changes from trunk

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessHibTest.java
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessHibTest.java b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessHibTest.java
index 420a9d8..42e061d 100644
--- a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessHibTest.java
+++ b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessHibTest.java
@@ -24,7 +24,7 @@ import org.apache.ode.bpel.dao.ProcessInstanceDAO;
 public class CleanSuccessHibTest extends CleanSuccessTest {
     @Override
     public String getODEConfigDir() {
-        return HIB_DERBY_CONF_DIR; 
+        return HIB_H2_CONF_DIR;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessTest.java
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessTest.java b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessTest.java
index 1079053..d0b1752 100644
--- a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessTest.java
+++ b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanSuccessTest.java
@@ -90,13 +90,13 @@ public class CleanSuccessTest extends CleanTestBase {
     }
 
     public String getODEConfigDir() {
-    	return JPA_DERBY_CONF_DIR;
+        return JPA_H2_CONF_DIR;
     }
-    
+
     protected ProcessInstanceDAO getInstance() {
         return JpaDaoConnectionFactoryImpl.getInstance();
     }
-    
+
     @Override
     protected int getLargeDataCount(int echoCount) throws Exception {
         return echoCount;

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanTestBase.java
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanTestBase.java b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanTestBase.java
index 5841538..ee377af 100644
--- a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanTestBase.java
+++ b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/CleanTestBase.java
@@ -56,8 +56,9 @@ public abstract class CleanTestBase extends Axis2TestBase implements ODEConfigDi
                 //ignore 
             }
         }
-        EmbeddedGeronimoFactory factory = new EmbeddedGeronimoFactory();
-        txm = factory.getTransactionManager();
+        txm = server.getODEServer().getTransactionManager();
+/*        EmbeddedGeronimoFactory factory = new EmbeddedGeronimoFactory();
+        txm = factory.getTransactionManager();*/
         Database db = getDatabase();
         db.setTransactionManager(txm);
         db.start();
@@ -88,7 +89,7 @@ public abstract class CleanTestBase extends Axis2TestBase implements ODEConfigDi
         File configFile = new File(odeConfigDir);
         ODEConfigProperties odeProps = new ODEConfigProperties(configFile);
         odeProps.load();
-        Database db = new Database(odeProps);
+        Database db = Database.create(odeProps);
         String webappPath = getClass().getClassLoader().getResource("webapp").getFile();
         db.setWorkRoot(new File(webappPath, "/WEB-INF"));
         

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/ProcessCronCleanupTest.java
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/ProcessCronCleanupTest.java b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/ProcessCronCleanupTest.java
index ddb5ec8..af73f85 100644
--- a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/ProcessCronCleanupTest.java
+++ b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/ProcessCronCleanupTest.java
@@ -23,7 +23,7 @@ import org.apache.ode.bpel.dao.ProcessInstanceDAO;
 import org.testng.annotations.Test;
 
 public class ProcessCronCleanupTest extends CleanTestBase {
-//	@Test(dataProvider="configs")
+    //@Test(dataProvider="configs")
     public void _testCleanAll() throws Exception {
         go("TestProcessCronCleanup", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
     }
@@ -46,9 +46,9 @@ public class ProcessCronCleanupTest extends CleanTestBase {
     }
 
     public String getODEConfigDir() {
-    	return HIB_DERBY_CONF_DIR;
+        return HIB_H2_CONF_DIR;
     }
-    
+
     protected ProcessInstanceDAO getInstance() {
         return HibDaoConnectionFactoryImpl.getInstance();
     }

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/SystemCronCleanupTest.java
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/SystemCronCleanupTest.java b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/SystemCronCleanupTest.java
index 2b80a63..c647485 100644
--- a/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/SystemCronCleanupTest.java
+++ b/axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/SystemCronCleanupTest.java
@@ -73,7 +73,7 @@ public class SystemCronCleanupTest extends CleanTestBase {
     }
 
     public String getODEConfigDir() {
-        return HIB_DERBY_CONF_DIR;
+        return HIB_H2_CONF_DIR;
     }
     
     protected ProcessInstanceDAO getInstance() {

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java b/axis2-war/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java
index 3daad20..f1d6ca5 100644
--- a/axis2-war/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java
+++ b/axis2-war/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java
@@ -270,6 +270,6 @@ public class InstanceManagementTest extends Axis2TestBase implements ODEConfigDi
     }
 
     public String getODEConfigDir() {
-        return HIB_DERBY_CONF_DIR;
+        return HIB_H2_CONF_DIR;
     }
 }

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/webapp/WEB-INF/conf.hib-derby/ode-axis2.properties
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/webapp/WEB-INF/conf.hib-derby/ode-axis2.properties b/axis2-war/src/test/webapp/WEB-INF/conf.hib-derby/ode-axis2.properties
index 6e8afcf..c5a3e2f 100644
--- a/axis2-war/src/test/webapp/WEB-INF/conf.hib-derby/ode-axis2.properties
+++ b/axis2-war/src/test/webapp/WEB-INF/conf.hib-derby/ode-axis2.properties
@@ -16,8 +16,10 @@
 #
 
 ode-axis2.dao.factory=org.apache.ode.axis2.instancecleanup.HibDaoConnectionFactoryImpl
-ode-axis2.db.emb.name=hibdb
 ode-axis2.db.mode=EMBEDDED
+ode-axis2.db.emb.type=DERBY
+ode-axis2.db.emb.name=derby-hibdb
 ode-axis2.cluster.localRoute.targets=http://doesntexist:8080/ode/processes/
 ode-axis2.cluster.localRoute.base=http://localhost:8888/ode/processes/
 ode-axis2.event.listeners=org.apache.ode.bpel.common.evt.DebugBpelEventListener
+ode-axis2.acquireTransactionLocks=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/webapp/WEB-INF/conf.hib-h2/ode-axis2.properties
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/webapp/WEB-INF/conf.hib-h2/ode-axis2.properties b/axis2-war/src/test/webapp/WEB-INF/conf.hib-h2/ode-axis2.properties
index c081fb7..c83f242 100644
--- a/axis2-war/src/test/webapp/WEB-INF/conf.hib-h2/ode-axis2.properties
+++ b/axis2-war/src/test/webapp/WEB-INF/conf.hib-h2/ode-axis2.properties
@@ -16,11 +16,14 @@
 #
 
 ode-axis2.dao.factory=org.apache.ode.axis2.instancecleanup.HibDaoConnectionFactoryImpl
-ode-axis2.db.mode=INTERNAL
-ode-axis2.db.int.jdbcurl=jdbc:h2:file:axis2-war/target/test/classes/webapp/WEB-INF/h2-hibdb/ode-hib-h2;DB_CLOSE_ON_EXIT=false;user=sa;TRACE_LEVEL_FILE=3
-ode-axis2.db.int.driver=org.h2.Driver
+#ode-axis2.db.mode=INTERNAL
+#ode-axis2.db.int.jdbcurl=jdbc:h2:file:axis2-war/target/test/classes/webapp/WEB-INF/h2-hibdb/ode-hib-h2;DB_CLOSE_ON_EXIT=false;user=sa;TRACE_LEVEL_FILE=3
+#ode-axis2.db.int.driver=org.h2.Driver
+ode-axis2.db.mode=EMBEDDED
+ode-axis2.db.emb.type=H2
+ode-axis2.db.emb.name=h2-hibdb/ode-hib-h2
+
 ode-axis2.cluster.localRoute.targets=http://doesntexist:8080/ode/processes/
 ode-axis2.cluster.localRoute.base=http://localhost:8888/ode/processes/
 ode-axis2.event.listeners=org.apache.ode.bpel.common.evt.DebugBpelEventListener
-ode.acquireTransactionLocks=true
-hibernate.dialect=org.hibernate.dialect.H2Dialect
\ No newline at end of file
+ode-axis2.acquireTransactionLocks=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/webapp/WEB-INF/conf.jpa-derby/ode-axis2.properties
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/webapp/WEB-INF/conf.jpa-derby/ode-axis2.properties b/axis2-war/src/test/webapp/WEB-INF/conf.jpa-derby/ode-axis2.properties
index f8b7e93..01e78bf 100644
--- a/axis2-war/src/test/webapp/WEB-INF/conf.jpa-derby/ode-axis2.properties
+++ b/axis2-war/src/test/webapp/WEB-INF/conf.jpa-derby/ode-axis2.properties
@@ -15,4 +15,7 @@
 #    limitations under the License.
 #
 
-ode-axis2.dao.factory=org.apache.ode.axis2.instancecleanup.JpaDaoConnectionFactoryImpl
\ No newline at end of file
+ode-axis2.dao.factory=org.apache.ode.axis2.instancecleanup.JpaDaoConnectionFactoryImpl
+ode-axis2.db.mode=EMBEDDED
+ode-axis2.db.emb.type=DERBY
+ode-axis2.db.emb.name=derby-jpadb
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/webapp/WEB-INF/conf.jpa-h2/ode-axis2.properties
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/webapp/WEB-INF/conf.jpa-h2/ode-axis2.properties b/axis2-war/src/test/webapp/WEB-INF/conf.jpa-h2/ode-axis2.properties
index dbb191d..c186678 100644
--- a/axis2-war/src/test/webapp/WEB-INF/conf.jpa-h2/ode-axis2.properties
+++ b/axis2-war/src/test/webapp/WEB-INF/conf.jpa-h2/ode-axis2.properties
@@ -16,6 +16,6 @@
 #
 
 ode-axis2.dao.factory=org.apache.ode.axis2.instancecleanup.JpaDaoConnectionFactoryImpl
-ode-axis2.db.mode=INTERNAL
-ode-axis2.db.int.jdbcurl=jdbc:h2:file:axis2-war/target/test/classes/webapp/WEB-INF/h2-jpadb/ode-jpa-h2;DB_CLOSE_ON_EXIT=false;user=sa;TRACE_LEVEL_FILE=3
-ode-axis2.db.int.driver=org.h2.Driver
+ode-axis2.db.mode=EMBEDDED
+ode-axis2.db.emb.type=H2
+ode-axis2.db.emb.name=h2-jpadb/ode-jpa-h2
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2-war/src/test/webapp/WEB-INF/conf/ode-axis2.properties
----------------------------------------------------------------------
diff --git a/axis2-war/src/test/webapp/WEB-INF/conf/ode-axis2.properties b/axis2-war/src/test/webapp/WEB-INF/conf/ode-axis2.properties
index c081fb7..ae0efaa 100644
--- a/axis2-war/src/test/webapp/WEB-INF/conf/ode-axis2.properties
+++ b/axis2-war/src/test/webapp/WEB-INF/conf/ode-axis2.properties
@@ -16,11 +16,10 @@
 #
 
 ode-axis2.dao.factory=org.apache.ode.axis2.instancecleanup.HibDaoConnectionFactoryImpl
-ode-axis2.db.mode=INTERNAL
-ode-axis2.db.int.jdbcurl=jdbc:h2:file:axis2-war/target/test/classes/webapp/WEB-INF/h2-hibdb/ode-hib-h2;DB_CLOSE_ON_EXIT=false;user=sa;TRACE_LEVEL_FILE=3
-ode-axis2.db.int.driver=org.h2.Driver
+ode-axis2.db.emb.type=H2
+ode-axis2.db.emb.name=h2-hibdb/ode-hib-h2
 ode-axis2.cluster.localRoute.targets=http://doesntexist:8080/ode/processes/
 ode-axis2.cluster.localRoute.base=http://localhost:8888/ode/processes/
 ode-axis2.event.listeners=org.apache.ode.bpel.common.evt.DebugBpelEventListener
-ode.acquireTransactionLocks=true
-hibernate.dialect=org.hibernate.dialect.H2Dialect
\ No newline at end of file
+#hibernate.dialect=org.hibernate.dialect.H2Dialect
+ode.acquireTransactionLocks=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
----------------------------------------------------------------------
diff --git a/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java b/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
index 9020353..839babc 100644
--- a/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
+++ b/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
@@ -130,7 +130,9 @@ public class ODEServer {
 
     protected MultiThreadedHttpConnectionManager httpConnectionManager;
     protected IdleConnectionTimeoutThread idleConnectionTimeoutThread;
-    
+
+    public Runnable txMgrCreatedCallback;
+
     public void init(ServletConfig config, ConfigurationContext configContext) throws ServletException {
         init(config.getServletContext().getRealPath("/WEB-INF"), configContext);
     }
@@ -172,6 +174,9 @@ public class ODEServer {
 
         __log.debug("Initializing transaction manager");
         initTxMgr();
+        if (txMgrCreatedCallback != null) {
+            txMgrCreatedCallback.run();
+        }
         __log.debug("Creating data source.");
         initDataSource();
         __log.debug("Starting DAO.");
@@ -261,7 +266,7 @@ public class ODEServer {
     }
     
     private void initDataSource() throws ServletException {
-        _db = new Database(_odeConfig);
+        _db = Database.create(_odeConfig);
         _db.setTransactionManager(_txMgr);
         _db.setWorkRoot(_workRoot);
 
@@ -419,6 +424,10 @@ public class ODEServer {
         }
     }
 
+    public TransactionManager getTransactionManager() {
+        return _txMgr;
+    }
+
     private void initConnector() throws ServletException {
         int port = _odeConfig.getConnectorPort();
         if (port == 0) {

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java
----------------------------------------------------------------------
diff --git a/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java b/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java
index 328a211..6f16f7d 100644
--- a/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java
+++ b/bpel-epr/src/main/java/org/apache/ode/il/config/OdeConfigProperties.java
@@ -46,6 +46,10 @@ public class OdeConfigProperties {
 
     public static final String PROP_DB_EMBEDDED_NAME = "db.emb.name";
 
+    public static final String PROP_DB_EMBEDDED_TYPE = "db.emb.type";
+
+    public static final String PROP_DB_EMBEDDED_CREATE = "db.emb.create";
+
     public static final String PROP_DB_INTERNAL_URL = "db.int.jdbcurl";
 
     public static final String PROP_DB_INTERNAL_DRIVER = "db.int.driver";
@@ -73,7 +77,7 @@ public class OdeConfigProperties {
     public static final String PROP_WORKING_DIR = "working.dir";
 
     public static final String PROP_DEPLOY_DIR = "deploy.dir";
-    
+
     public static final String PROP_EVENT_LISTENERS = "event.listeners";
 
     public static final String PROP_MEX_INTERCEPTORS = "mex.interceptors";
@@ -83,23 +87,23 @@ public class OdeConfigProperties {
     public static final String PROP_PROCESS_DEHYDRATION = "process.dehydration";
 
     public static final String PROP_PROCESS_DEHYDRATION_MAXIMUM_AGE = "process.dehydration.maximum.age";
-    
+
     public static final String PROP_PROCESS_DEHYDRATION_MAXIMUM_COUNT = "process.dehydration.maximum.count";
-    
+
     public static final String PROP_PROCESS_HYDRATION_LAZY = "process.hydration.lazy";
-    
+
     public static final String PROP_PROCESS_HYDRATION_LAZY_MINIMUM_SIZE = "process.hydration.lazy.minimum.size";
-    
+
     public static final String PROP_PROCESS_HYDRATION_THROTTLED_MAXIMUM_COUNT = "process.hydration.throttled.maximum.count";
-    
+
     public static final String PROP_PROCESS_HYDRATION_THROTTLED_MAXIMUM_SIZE = "process.hydration.throttled.maximum.size";
-    
+
     public static final String PROP_PROCESS_INSTANCE_THROTTLED_MAXIMUM_COUNT = "process.instance.throttled.maximum.count";
-    
+
     public static final String PROP_DAOCF = "dao.factory";
-    
+
     public static final String PROP_MIGRATION_TRANSACTION_TIMEOUT = "migration.transaction.timeout";
-    
+
     public static final String DEFAULT_TX_FACTORY_CLASS_NAME = "org.apache.ode.il.EmbeddedGeronimoFactory";
 
     private File _cfgFile;
@@ -112,6 +116,10 @@ public class OdeConfigProperties {
     private static String __dbEmbName = "derby-jpadb";
     private static String __daoCfClass = "org.apache.ode.dao.jpa.BPELDAOConnectionFactoryImpl";
 
+    public static String DEFAULT_DB_EMB_NAME = "ode-db";
+    public static String DEFAULT_DB_EMB_TYPE = "h2";
+    public static String DEFAULT_DAOCF_CLASS = "org.apache.ode.dao.jpa.openjpa.BpelDAOConnectionFactoryImpl";
+
     static {
         String odep = System.getProperty("ode.persistence");
         if (odep != null &&
@@ -136,6 +144,16 @@ public class OdeConfigProperties {
         EMBEDDED
     }
 
+    /**
+     * Possible database implementation.
+     */
+    public enum EmbeddedDbType {
+
+        DERBY,
+
+        H2
+    }
+
     public OdeConfigProperties(File cfgFile, String prefix) {
         _cfgFile = cfgFile;
         _prefix = prefix;
@@ -188,6 +206,14 @@ public class OdeConfigProperties {
 
     }
 
+    public EmbeddedDbType getDbEmbeddedType() {
+        return EmbeddedDbType.valueOf(getProperty(OdeConfigProperties.PROP_DB_EMBEDDED_TYPE, DEFAULT_DB_EMB_TYPE).trim().toUpperCase());
+    }
+
+    public boolean isDbEmbeddedCreate() {
+        return Boolean.valueOf(getProperty(OdeConfigProperties.PROP_DB_EMBEDDED_CREATE, "true"));
+    }
+
     public DatabaseMode getDbMode() {
         return DatabaseMode.valueOf(getProperty(OdeConfigProperties.PROP_DB_MODE, DatabaseMode.EMBEDDED.toString()).trim()
                 .toUpperCase());

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-epr/src/main/java/org/apache/ode/il/dbutil/Database.java
----------------------------------------------------------------------
diff --git a/bpel-epr/src/main/java/org/apache/ode/il/dbutil/Database.java b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/Database.java
index 80a0a00..226382b 100644
--- a/bpel-epr/src/main/java/org/apache/ode/il/dbutil/Database.java
+++ b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/Database.java
@@ -19,65 +19,54 @@
 package org.apache.ode.il.dbutil;
 
 import java.io.File;
-import java.sql.SQLException;
-import java.util.Properties;
 
-import javax.naming.InitialContext;
 import javax.sql.DataSource;
 import javax.transaction.TransactionManager;
 
-import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.derby.jdbc.EmbeddedDriver;
-import org.apache.geronimo.connector.outbound.GenericConnectionManager;
-import org.apache.geronimo.connector.outbound.connectionmanagerconfig.LocalTransactions;
-import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
-import org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool;
-import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
-import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
-import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
-import org.apache.geronimo.transaction.manager.RecoverableTransactionManager;
 import org.apache.ode.bpel.dao.BpelDAOConnectionFactoryJDBC;
 import org.apache.ode.il.config.OdeConfigProperties;
 import org.apache.ode.utils.LoggingInterceptor;
-import org.tranql.connector.jdbc.JDBCDriverMCF;
 
 /**
  * Does the dirty work of setting up / obtaining a DataSource based on the configuration in the {@link OdeConfigProperties} object.
  *
  */
-public class Database {
-    private static final Log __log = LogFactory.getLog(Database.class);
+public abstract class Database {
+    protected static final Log __log = LogFactory.getLog(Database.class);
 
-    private static final Log __logSql = LogFactory.getLog("org.apache.ode.sql");
+    protected static final Log __logSql = LogFactory.getLog("org.apache.ode.sql");
 
-    private static final Messages __msgs = Messages.getMessages(Messages.class);
+    protected static final Messages __msgs = Messages.getMessages(Messages.class);
 
-    private static final int CONNECTION_MAX_WAIT_MILLIS = 30000;
+    protected OdeConfigProperties _odeConfig;
 
-    private static final int CONNECTION_MAX_IDLE_MINUTES = 5;
+    protected boolean _started;
 
-    private OdeConfigProperties _odeConfig;
+    protected TransactionManager _txm;
 
-    private boolean _started;
+    protected DataSource _datasource;
 
-    private GenericConnectionManager _connectionManager;
+    protected File _workRoot;
 
-    private TransactionManager _txm;
-
-    private DataSource _datasource;
-
-    private File _workRoot;
-
-    private boolean _needDerbyShutdown;
-
-    private String _derbyUrl;
-
-    public Database(OdeConfigProperties props) {
+    public static Database create(OdeConfigProperties props) {
         if (props == null)
             throw new NullPointerException("Must provide a configuration.");
 
+        switch (props.getDbMode()) {
+        case EMBEDDED: 
+            switch (props.getDbEmbeddedType()) {
+                case DERBY: return new DerbyEmbeddedDB(props);
+                case H2: return new H2EmbeddedDB(props);
+            }
+        case EXTERNAL: return new ExternalDB(props);
+        case INTERNAL: return new InternalDB(props);
+        default: throw new IllegalStateException();
+        }
+    }
+
+    public Database(OdeConfigProperties props) {
         _odeConfig = props;
     }
 
@@ -93,9 +82,7 @@ public class Database {
         if (_started)
             return;
 
-        _needDerbyShutdown = false;
         _datasource = null;
-        _connectionManager = null;
 
         initDataSource();
         _started = true;
@@ -105,32 +92,6 @@ public class Database {
         if (!_started)
             return;
 
-        if (_connectionManager != null)
-            try {
-                __log.debug("Stopping connection manager");
-                _connectionManager.doStop();
-            } catch (Throwable t) {
-                __log.warn("Exception while stopping connection manager: " + t.getMessage());
-            } finally {
-                _connectionManager = null;
-            }
-
-        if (_needDerbyShutdown) {
-            __log.debug("shutting down derby.");
-            EmbeddedDriver driver = new EmbeddedDriver();
-            try {
-                driver.connect(_derbyUrl + ";shutdown=true", new Properties());
-            } catch (SQLException ex) {
-                // Shutdown will always return an exeption!
-                if (ex.getErrorCode() != 45000)
-                    __log.error("Error shutting down Derby: " + ex.getErrorCode(), ex);
-
-            } catch (Throwable ex) {
-                __log.debug("Error shutting down Derby.", ex);
-            }
-        }
-
-        _needDerbyShutdown = false;
         _datasource = null;
         _started = false;
     }
@@ -140,137 +101,7 @@ public class Database {
         return __logSql.isDebugEnabled() ? LoggingInterceptor.createLoggingDS(_datasource, __logSql) : _datasource;
     }
 
-    private void initDataSource() throws DatabaseConfigException {
-        switch (_odeConfig.getDbMode()) {
-        case EXTERNAL:
-            initExternalDb();
-            break;
-        case EMBEDDED:
-            initEmbeddedDb();
-            break;
-        case INTERNAL:
-            initInternalDb();
-            break;
-        default:
-            break;
-        }
-    }
-
-    private void initExternalDb() throws DatabaseConfigException {
-        try {
-            _datasource = (DataSource) lookupInJndi(_odeConfig.getDbDataSource());
-            __log.info(__msgs.msgOdeUsingExternalDb(_odeConfig.getDbDataSource()));
-        } catch (Exception ex) {
-            String msg = __msgs.msgOdeInitExternalDbFailed(_odeConfig.getDbDataSource());
-            __log.error(msg, ex);
-            throw new DatabaseConfigException(msg, ex);
-        }
-    }
-
-    private void initInternalDb() throws DatabaseConfigException {
-        __log.info(__msgs.msgOdeUsingInternalDb(_odeConfig.getDbIntenralJdbcUrl(), _odeConfig.getDbInternalJdbcDriverClass()));
-        initInternalDb(_odeConfig.getDbIntenralJdbcUrl(), _odeConfig.getDbInternalJdbcDriverClass(),
-                _odeConfig.getDbInternalUserName(), _odeConfig.getDbInternalPassword());
-    }
-
-    private void initInternalDb(String url, String driverClass, String username,String password) throws DatabaseConfigException {
-
-        __log.debug("Creating connection pool for " + url + " with driver " + driverClass);
-        if (!(_txm instanceof RecoverableTransactionManager)) {
-            throw new RuntimeException("TransactionManager is not recoverable.");
-        }
-
-        TransactionSupport transactionSupport = LocalTransactions.INSTANCE;
-        ConnectionTracker connectionTracker = new ConnectionTrackingCoordinator();
-
-        PoolingSupport poolingSupport = new SinglePool(
-                _odeConfig.getPoolMaxSize(),
-                _odeConfig.getPoolMinSize(),
-                CONNECTION_MAX_WAIT_MILLIS,
-                CONNECTION_MAX_IDLE_MINUTES,
-                true, // match one
-                false, // match all
-                false); // select one assume match
-
-        _connectionManager = new GenericConnectionManager(
-                    transactionSupport,
-                    poolingSupport,
-                    null,
-                    connectionTracker,
-                    (RecoverableTransactionManager) _txm,
-                    getClass().getName(),
-                    getClass().getClassLoader());
-
-        
-        try {
-            javax.resource.spi.ManagedConnectionFactory mcf = null;
-            String mcfClass = _odeConfig.getDbInternalMCFClass();
-            if (mcfClass != null) {
-                Properties dbInternalMCFProps = _odeConfig.getDbInternalMCFProperties();
-                if (__log.isDebugEnabled()) {
-                    __log.debug("Using internal DB MCF " + mcfClass + " " + dbInternalMCFProps);
-                }
-                mcf = (javax.resource.spi.ManagedConnectionFactory) Class.forName(mcfClass).newInstance();
-                BeanUtils.copyProperties(mcf, dbInternalMCFProps);
-            } else {
-                if (__log.isDebugEnabled()) {
-                    __log.debug("Using internal DB JDBCDriverMCF");
-                }
-                JDBCDriverMCF mcf2 = new JDBCDriverMCF();
-                mcf = mcf2;
-                mcf2.setDriver(driverClass);
-                mcf2.setConnectionURL(url);
-                if (username != null) {
-                    mcf2.setUserName(username);
-                }
-                if (password != null) {
-                    mcf2.setPassword(password);
-                }
-            }
-            _connectionManager.doStart();
-            _datasource = (DataSource) mcf.createConnectionFactory(_connectionManager);
-        } catch (Exception ex) {
-            String errmsg = __msgs.msgOdeDbPoolStartupFailed(url);
-            __log.error(errmsg, ex);
-            throw new DatabaseConfigException(errmsg, ex);
-        }
-    }
-
-    /**
-     * Initialize embedded (DERBY) database.
-     */
-    private void initEmbeddedDb() throws DatabaseConfigException {
-
-        String db = _odeConfig.getDbEmbeddedName();
-
-        String url = "jdbc:derby:" + _workRoot + "/" + db ;
-        __log.info("Using Embedded Derby: " + url);
-        _derbyUrl = url;
-        initInternalDb(url, org.apache.derby.jdbc.EmbeddedDriver.class.getName(),"sa",null);
-        _needDerbyShutdown = true;
-    }
-
-    @SuppressWarnings("unchecked")
-    private <T> T lookupInJndi(String objName) throws Exception {
-        ClassLoader old = Thread.currentThread().getContextClassLoader();
-        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-        try {
-            InitialContext ctx = null;
-            try {
-                ctx = new InitialContext();
-                return (T) ctx.lookup(objName);
-            } finally {
-                if (ctx != null)
-                    try {
-                        ctx.close();
-                    } catch (Exception ex1) {
-                        __log.error("Error closing JNDI connection.", ex1);
-                    }
-            }
-        } finally {
-            Thread.currentThread().setContextClassLoader(old);
-        }
-    }
+    protected abstract void initDataSource() throws DatabaseConfigException;
 
     public BpelDAOConnectionFactoryJDBC createDaoCF() throws DatabaseConfigException  {
         String pClassName = _odeConfig.getDAOConnectionFactory();
@@ -293,4 +124,4 @@ public class Database {
         return cf;
     }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-epr/src/main/java/org/apache/ode/il/dbutil/DatabaseConnectionManager.java
----------------------------------------------------------------------
diff --git a/bpel-epr/src/main/java/org/apache/ode/il/dbutil/DatabaseConnectionManager.java b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/DatabaseConnectionManager.java
new file mode 100644
index 0000000..2ef9732
--- /dev/null
+++ b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/DatabaseConnectionManager.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.il.dbutil;
+
+
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.connector.outbound.GenericConnectionManager;
+import org.apache.geronimo.connector.outbound.connectionmanagerconfig.LocalTransactions;
+import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
+import org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool;
+import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
+import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
+import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
+import org.apache.geronimo.transaction.manager.RecoverableTransactionManager;
+import org.apache.ode.il.config.OdeConfigProperties;
+import org.tranql.connector.jdbc.JDBCDriverMCF;
+
+public class DatabaseConnectionManager {
+
+    private static final long serialVersionUID = 1L;
+    private static final Log __log = LogFactory.getLog(DatabaseConnectionManager.class);
+    private static final Messages __msgs = Messages.getMessages(Messages.class);
+    private static final int CONNECTION_MAX_WAIT_MILLIS = 30000;
+    private static final int CONNECTION_MAX_IDLE_MINUTES = 5;
+    private GenericConnectionManager _connectionManager;
+    private TransactionManager _txm = null;
+    private String _url = null;
+    private OdeConfigProperties _odeConfig = null;
+    private DataSource _dataSource = null;
+
+    public DatabaseConnectionManager(TransactionManager txm, OdeConfigProperties odeConfig) {
+        _txm = txm;
+        _odeConfig = odeConfig;
+    }
+
+    public void init(String url, String driverClass, String username, String password) throws DatabaseConfigException {
+        __log.debug("Creating connection pool for " + url + " with driver " + driverClass);
+
+        if (!(_txm instanceof RecoverableTransactionManager)) {
+            throw new RuntimeException("TransactionManager is not recoverable.");
+        }
+
+        _url = url;
+        TransactionSupport transactionSupport = LocalTransactions.INSTANCE;
+        ConnectionTracker connectionTracker = new ConnectionTrackingCoordinator();
+
+        PoolingSupport poolingSupport = new SinglePool(
+                _odeConfig.getPoolMaxSize(),
+                _odeConfig.getPoolMinSize(),
+                CONNECTION_MAX_WAIT_MILLIS,
+                CONNECTION_MAX_IDLE_MINUTES,
+                true, // match one
+                false, // match all
+                false); // select one assume match
+
+        _connectionManager = new GenericConnectionManager(
+                transactionSupport,
+                poolingSupport,
+                null,
+                connectionTracker,
+                (RecoverableTransactionManager) _txm,
+                getClass().getName(),
+                getClass().getClassLoader());
+
+        JDBCDriverMCF mcf = new JDBCDriverMCF();
+        try {
+            mcf.setDriver(driverClass);
+            mcf.setConnectionURL(url);
+            if (username != null) {
+                mcf.setUserName(username);
+            }
+            if (password != null) {
+                mcf.setPassword(password);
+            }
+            _connectionManager.doStart();
+            _dataSource = (DataSource) mcf.createConnectionFactory(_connectionManager);
+        } catch (Exception ex) {
+            String errmsg = __msgs.msgOdeDbPoolStartupFailed(url);
+            __log.error(errmsg, ex);
+            throw new DatabaseConfigException(errmsg, ex);
+        }
+    }
+
+    public void shutdown() throws DatabaseConfigException {
+        try {
+            _connectionManager.doStop();
+        } catch (Exception ex) {
+            String errmsg = __msgs.msgOdeDbPoolStartupFailed(_url);
+            __log.error(errmsg, ex);
+            throw new DatabaseConfigException(errmsg, ex);
+        }
+    }
+
+    public DataSource getDataSource() {
+        return _dataSource;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-epr/src/main/java/org/apache/ode/il/dbutil/DerbyEmbeddedDB.java
----------------------------------------------------------------------
diff --git a/bpel-epr/src/main/java/org/apache/ode/il/dbutil/DerbyEmbeddedDB.java b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/DerbyEmbeddedDB.java
new file mode 100644
index 0000000..52d367a
--- /dev/null
+++ b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/DerbyEmbeddedDB.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.il.dbutil;
+
+import java.io.File;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.derby.impl.io.VFMemoryStorageFactory;
+import org.apache.derby.jdbc.EmbeddedDataSource;
+import org.apache.ode.il.config.OdeConfigProperties;
+
+public class DerbyEmbeddedDB extends InternalDB {
+
+    private String _dbUrl = null;
+    private String _dbName = null;
+
+    public DerbyEmbeddedDB(OdeConfigProperties props) {
+        super(props);
+    }
+
+    /**
+     * Initialize embedded (DERBY) database.
+     */
+    @Override
+    protected void initDataSource() throws DatabaseConfigException {
+        _dbName = _odeConfig.getDbEmbeddedName();
+        if (_workRoot == null) {
+            _dbUrl = "jdbc:derby:memory:" + _dbName + ";create=true";
+            try {
+                DriverManager.getConnection(_dbUrl).close();
+            } catch (SQLException se) {
+                __log.error(se);
+            }
+            EmbeddedDataSource dds = new EmbeddedDataSource();
+            dds.setDatabaseName("memory:" + _dbName);
+            dds.setUser("sa");
+            dds.setCreateDatabase("true");
+            _datasource = dds;
+        } else {
+            _dbUrl = "jdbc:derby:" + _workRoot + File.separator + _dbName;
+            if (_odeConfig.isDbEmbeddedCreate()) {
+                _dbUrl += ";create=true";
+            }
+            String clazz = org.apache.derby.jdbc.EmbeddedDriver.class.getName();
+            _connectionManager = new DatabaseConnectionManager(_txm, _odeConfig);
+            try {
+                _connectionManager.init(_dbUrl, clazz, "sa", null);
+            } catch (DatabaseConfigException ex) {
+                __log.error("Unable to initialize connection pool", ex);
+            }
+            _datasource = _connectionManager.getDataSource();
+            __log.debug("Using Embedded Database: " + _dbUrl);
+        }
+    }
+
+    public void shutdownDB() {
+        if (_connectionManager != null) {
+            try {
+                _connectionManager.shutdown();
+            } catch (DatabaseConfigException ex) {
+                __log.error("unable to shutdown connection pool", ex);
+            }
+        }
+        try {
+            DriverManager.getConnection(_dbUrl + ";shutdown=true").close();
+        } catch (SQLException ex) {
+            // Shutdown will always return an exeption!
+            if (ex.getErrorCode() != 45000) {
+                __log.error("Error shutting down Derby: " + ex.getErrorCode(), ex);
+            }
+        } catch (Throwable ex) {
+            __log.debug("Error shutting down Derby.", ex);
+        }
+        if (_workRoot == null) {
+            try {
+                //Don't worry about File IO, this is only virtual
+                VFMemoryStorageFactory.purgeDatabase(new File(_dbName).getCanonicalPath());
+            } catch (Exception e) {
+                __log.debug("Error shutting down Derby.", e);
+            }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-epr/src/main/java/org/apache/ode/il/dbutil/ExternalDB.java
----------------------------------------------------------------------
diff --git a/bpel-epr/src/main/java/org/apache/ode/il/dbutil/ExternalDB.java b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/ExternalDB.java
new file mode 100644
index 0000000..0fa8dd3
--- /dev/null
+++ b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/ExternalDB.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.il.dbutil;
+
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+import org.apache.ode.il.config.OdeConfigProperties;
+
+public class ExternalDB extends Database {
+
+    public ExternalDB(OdeConfigProperties props) {
+        super(props);
+    }
+
+    @Override
+    protected void initDataSource() throws DatabaseConfigException {
+        try {
+            _datasource = (DataSource) lookupInJndi(_odeConfig.getDbDataSource());
+            __log.info(__msgs.msgOdeUsingExternalDb(_odeConfig.getDbDataSource()));
+        } catch (Exception ex) {
+            String msg = __msgs.msgOdeInitExternalDbFailed(_odeConfig.getDbDataSource());
+            __log.error(msg, ex);
+            throw new DatabaseConfigException(msg, ex);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> T lookupInJndi(String objName) throws Exception {
+        ClassLoader old = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+        try {
+            InitialContext ctx = null;
+            try {
+                ctx = new InitialContext();
+                return (T) ctx.lookup(objName);
+            } finally {
+                if (ctx != null)
+                    try {
+                        ctx.close();
+                    } catch (Exception ex1) {
+                        __log.error("Error closing JNDI connection.", ex1);
+                    }
+            }
+        } finally {
+            Thread.currentThread().setContextClassLoader(old);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-epr/src/main/java/org/apache/ode/il/dbutil/H2EmbeddedDB.java
----------------------------------------------------------------------
diff --git a/bpel-epr/src/main/java/org/apache/ode/il/dbutil/H2EmbeddedDB.java b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/H2EmbeddedDB.java
new file mode 100644
index 0000000..6e08b62
--- /dev/null
+++ b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/H2EmbeddedDB.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.il.dbutil;
+
+import java.io.File;
+import java.sql.Connection;
+
+import org.apache.ode.il.config.OdeConfigProperties;
+import org.h2.jdbcx.JdbcDataSource;
+
+public class H2EmbeddedDB extends InternalDB {
+
+    private String _dbUrl = null;
+    private String _dbName = null;
+
+    public H2EmbeddedDB(OdeConfigProperties props) {
+        super(props);
+    }
+
+    /**
+     * Initialize embedded (DERBY) database.
+     */
+    @Override
+    protected void initDataSource() throws DatabaseConfigException {
+        String db = _odeConfig.getDbEmbeddedName();
+        if (_workRoot == null) {
+            _dbUrl = "jdbc:h2:mem:" + db + ";DB_CLOSE_DELAY=-1";
+            JdbcDataSource hds = new JdbcDataSource();
+            hds.setURL(_dbUrl);
+            hds.setUser("sa");
+            _datasource = hds;
+        } else {
+            _dbUrl = "jdbc:h2:" + _workRoot + File.separator + db +";DB_CLOSE_ON_EXIT=FALSE";
+            if (!_odeConfig.isDbEmbeddedCreate()) {
+                _dbUrl += ";IFEXISTS=TRUE";
+            }
+            String clazz = org.h2.Driver.class.getName();
+            _connectionManager = new DatabaseConnectionManager(_txm, _odeConfig);
+            try {
+                _connectionManager.init(_dbUrl, clazz, "sa", null);
+            } catch (DatabaseConfigException ex) {
+                __log.error("Unable to initialize connection pool", ex);
+            }
+            _datasource = _connectionManager.getDataSource();
+        }
+        __log.debug("Using Embedded Database: " + _dbUrl);
+    }
+
+    public void shutdownDB() {
+        if (_connectionManager != null) {
+            try {
+                _connectionManager.shutdown();
+            } catch (DatabaseConfigException ex) {
+                __log.error("unable to shutdown connection pool", ex);
+            }
+        }
+        try {
+            Connection conn = getDataSource().getConnection();
+            conn.createStatement().execute("SHUTDOWN");
+        } catch (Throwable ex) {
+            __log.debug("Error shutting down H2.", ex);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-epr/src/main/java/org/apache/ode/il/dbutil/InternalDB.java
----------------------------------------------------------------------
diff --git a/bpel-epr/src/main/java/org/apache/ode/il/dbutil/InternalDB.java b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/InternalDB.java
new file mode 100644
index 0000000..3c8deaf
--- /dev/null
+++ b/bpel-epr/src/main/java/org/apache/ode/il/dbutil/InternalDB.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.il.dbutil;
+
+import org.apache.ode.il.config.OdeConfigProperties;
+
+public class InternalDB extends Database {
+    protected static final int CONNECTION_MAX_WAIT_MILLIS = 30000;
+    protected static final int CONNECTION_MAX_IDLE_MINUTES = 5;
+
+    protected DatabaseConnectionManager _connectionManager;
+
+    public InternalDB(OdeConfigProperties props) {
+        super(props);
+    }
+
+    @Override
+    public synchronized void start() throws DatabaseConfigException {
+        if (_started)
+            return;
+
+        _datasource = null;
+        _connectionManager = null;
+
+        initDataSource();
+        _started = true;
+    }
+
+    @Override
+    public synchronized void shutdown() {
+        if (!_started)
+            return;
+
+        if (_connectionManager != null) {
+            try {
+                __log.debug("Stopping connection manager");
+                _connectionManager.shutdown();
+            } catch (Throwable t) {
+                __log.warn("Exception while stopping connection manager: " + t.getMessage());
+            } finally {
+                _connectionManager = null;
+            }
+        }
+
+        shutdownDB();
+
+        _datasource = null;
+        _started = false;
+    }
+
+    protected void shutdownDB() {}
+
+    protected void initDataSource() throws DatabaseConfigException {
+        __log.info(__msgs.msgOdeUsingInternalDb(_odeConfig.getDbIntenralJdbcUrl(), _odeConfig.getDbInternalJdbcDriverClass()));
+        initInternalDb(_odeConfig.getDbIntenralJdbcUrl(), _odeConfig.getDbInternalJdbcDriverClass(),
+                _odeConfig.getDbInternalUserName(), _odeConfig.getDbInternalPassword());
+    }
+
+    protected void initInternalDb(String url, String driverClass, String username,String password) throws DatabaseConfigException {
+        _connectionManager = new DatabaseConnectionManager(_txm,_odeConfig);
+        _connectionManager.init(url, driverClass, username, password);
+        _datasource = _connectionManager.getDataSource();
+     }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-runtime/src/test/java/org/apache/ode/bpel/engine/cron/CronSchedulerTest.java
----------------------------------------------------------------------
diff --git a/bpel-runtime/src/test/java/org/apache/ode/bpel/engine/cron/CronSchedulerTest.java b/bpel-runtime/src/test/java/org/apache/ode/bpel/engine/cron/CronSchedulerTest.java
index b848a9f..dfa5407 100644
--- a/bpel-runtime/src/test/java/org/apache/ode/bpel/engine/cron/CronSchedulerTest.java
+++ b/bpel-runtime/src/test/java/org/apache/ode/bpel/engine/cron/CronSchedulerTest.java
@@ -45,13 +45,13 @@ public class CronSchedulerTest extends TestCase {
     private CronScheduler cronScheduler;
     private ExecutorService execService;
 
-    static {
+  /*  static {
         BasicConfigurator.configure();
         LogManager.getRootLogger().setLevel(Level.DEBUG);
         LogManager.getLogger(RuntimeDataCleanupRunnable.class).setLevel(Level.DEBUG);
         LogManager.getLogger(BpelDAOConnectionImpl.class).setLevel(Level.DEBUG);
         LogManager.getLogger("org.apache.ode").setLevel(Level.DEBUG);
-    }
+    }*/
     
     protected void setUp() throws Exception {
         contexts = new Contexts();

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java
----------------------------------------------------------------------
diff --git a/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java b/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java
index aa6195a..572512b 100644
--- a/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java
+++ b/bpel-runtime/src/test/java/org/apache/ode/bpel/runtime/MockBpelServer.java
@@ -18,15 +18,23 @@
  */
 package org.apache.ode.bpel.runtime;
 
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
 
-import org.apache.geronimo.connector.outbound.GenericConnectionManager;
-import org.apache.geronimo.connector.outbound.connectionmanagerconfig.LocalTransactions;
-import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
-import org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool;
-import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
-import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
-import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
-import org.apache.geronimo.transaction.manager.RecoverableTransactionManager;
 import org.apache.ode.bpel.dao.BpelDAOConnectionFactory;
 import org.apache.ode.bpel.engine.BpelServerImpl;
 import org.apache.ode.bpel.iapi.BindingContext;
@@ -48,27 +56,9 @@ import org.apache.ode.il.dbutil.Database;
 import org.apache.ode.store.ProcessStoreImpl;
 import org.apache.ode.utils.DOMUtils;
 import org.apache.ode.utils.GUID;
-import org.tranql.connector.derby.EmbeddedLocalMCF;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.resource.spi.ConnectionManager;
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-import javax.wsdl.PortType;
-import javax.xml.namespace.QName;
-import java.io.File;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Collections;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
 
 class MockBpelServer {
 
@@ -83,13 +73,14 @@ class MockBpelServer {
     MessageExchangeContext    _mexContext;
     BindingContext            _bindContext;
     HashMap<String, QName>    _activated = new HashMap<String, QName>();
-
-    HashMap<String,EndpointReference> _endpoints = new HashMap<String,EndpointReference>();
+    @SuppressWarnings("unchecked")
+    HashMap                   _endpoints = new HashMap();
 
      public MockBpelServer() {
         try {
             _server = new BpelServerImpl();
             createTransactionManager();
+            org.springframework.mock.jndi.SimpleNamingContextBuilder.emptyActivatedContextBuilder().bind("java:comp/UserTransaction", _txManager);
             createDataSource();
             createScheduler();
             createDAOConnection();
@@ -111,6 +102,7 @@ class MockBpelServer {
             _server.start();
         } catch (Exception except) {
             System.err.println(except.getMessage());
+            except.printStackTrace(System.err);
             throw new RuntimeException(except);
         }
     }
@@ -167,6 +159,7 @@ class MockBpelServer {
         _server.stop();
         _scheduler.stop();
         _scheduler.shutdown();
+        _database.shutdown();
     }
 
     protected TransactionManager createTransactionManager() throws Exception {
@@ -177,45 +170,14 @@ class MockBpelServer {
     }
 
     protected DataSource createDataSource() throws Exception {
-        TransactionSupport transactionSupport = LocalTransactions.INSTANCE;
-        ConnectionTracker connectionTracker = new ConnectionTrackingCoordinator();
-
-        PoolingSupport poolingSupport = new SinglePool(
-                10,
-                0,
-                1000,
-                1,
-                true,
-                false,
-                false);
-
-        ConnectionManager connectionManager = new GenericConnectionManager(
-                    transactionSupport,
-                    poolingSupport,
-                    null,
-                    connectionTracker,
-                    (RecoverableTransactionManager) _txManager,
-                    getClass().getName(),
-                    getClass().getClassLoader());
-
-        
-            EmbeddedLocalMCF mcf = new org.tranql.connector.derby.EmbeddedLocalMCF();
-            mcf.setCreateDatabase(true);
-            mcf.setDatabaseName("target/testdb");
-            mcf.setUserName("sa");
-            mcf.setPassword("");
-            _dataSource = (DataSource) mcf.createConnectionFactory(connectionManager);
-            return _dataSource;
-        
-        
-//        d = org.tranql.connector.jdbc.JDBCDriverMCF();
-//        EmbeddedXADataSource ds = new EmbeddedXADataSource();
-//        ds.setCreateDatabase("create");
-//        ds.setDatabaseName("target/testdb");
-//        ds.setUser("sa");
-//        ds.setPassword("");
-//        _dataSource = ds;
-//        return _dataSource;
+        Properties props = new Properties();
+        props.setProperty(OdeConfigProperties.PROP_DAOCF, System.getProperty(OdeConfigProperties.PROP_DAOCF, OdeConfigProperties.DEFAULT_DAOCF_CLASS));
+        OdeConfigProperties odeProps = new OdeConfigProperties(props,"");
+        _database = Database.create(odeProps);
+        _database.setTransactionManager(_txManager);
+        _database.start();
+        _dataSource = _database.getDataSource();
+        return _dataSource;
     }
 
     protected Scheduler createScheduler() throws Exception {
@@ -235,7 +197,7 @@ class MockBpelServer {
         if (_dataSource == null)
             throw new RuntimeException("No data source");
 
-//        
+//
 //        BpelDAOConnectionFactoryJDBC daoCF = new BPELDAOConnectionFactoryImpl();
 //        daoCF.setDataSource(_dataSource);
 //        daoCF.setTransactionManager(_txManager);
@@ -367,9 +329,9 @@ class MockBpelServer {
         public <T> T execTransaction(Callable<T> transaction) throws Exception, ContextException {
             return _scheduler.execTransaction(transaction, 0);
         }
-        
+
         public <T> T execTransaction(Callable<T> transaction, int timeout) throws Exception, ContextException {
-       		return _scheduler.execTransaction(transaction, timeout);
+            return _scheduler.execTransaction(transaction, timeout);
         }
 
         public void beginTransaction() throws Exception {
@@ -399,7 +361,6 @@ class MockBpelServer {
         public void start() { _scheduler.start(); }
         public void stop() { _scheduler.stop(); }
         public void shutdown() { _scheduler.shutdown(); }
-        public void acquireTransactionLocks() { _scheduler.acquireTransactionLocks(); }
 
         public void registerSynchronizer(Synchronizer synch) throws ContextException {
             _scheduler.registerSynchronizer(synch);
@@ -413,8 +374,14 @@ class MockBpelServer {
         public void setPolledRunnableProcesser(JobProcessor delegatedRunnableProcessor) {
         }
 
-		public boolean amICoordinator() {
-			return true;
-		}
+        public boolean amICoordinator() {
+            return true;
+        }
+
+
+        public void acquireTransactionLocks() {
+            // TODO Auto-generated method stub
+
+        }
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
----------------------------------------------------------------------
diff --git a/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java b/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
index a0cbc22..156a727 100644
--- a/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
+++ b/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
@@ -109,6 +109,7 @@ public class ProcessStoreImpl implements ProcessStore {
     }
 
     public ProcessStoreImpl(EndpointReferenceContext eprContext, DataSource ds, String persistenceType, OdeConfigProperties props, boolean createDatamodel) {
+        __log.debug("ds:"+ds+" persistenceType:"+persistenceType+" createDatamodel:"+createDatamodel);
         this.eprContext = eprContext;
         this.generateProcessEventsAll = props.getProperty("generateProcessEvents", "all").equals("all");
         if (ds != null) {

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-store/src/main/java/org/apache/ode/store/hib/DbConfStoreConnectionFactory.java
----------------------------------------------------------------------
diff --git a/bpel-store/src/main/java/org/apache/ode/store/hib/DbConfStoreConnectionFactory.java b/bpel-store/src/main/java/org/apache/ode/store/hib/DbConfStoreConnectionFactory.java
index 624f5ee..2c39f1b 100644
--- a/bpel-store/src/main/java/org/apache/ode/store/hib/DbConfStoreConnectionFactory.java
+++ b/bpel-store/src/main/java/org/apache/ode/store/hib/DbConfStoreConnectionFactory.java
@@ -19,9 +19,7 @@
 package org.apache.ode.store.hib;
 
 import java.sql.Connection;
-import java.sql.DatabaseMetaData;
 import java.sql.SQLException;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
@@ -31,7 +29,6 @@ import javax.transaction.TransactionManager;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.ode.bpel.iapi.BpelEngineException;
 import org.apache.ode.daohib.HibernateTransactionManagerLookup;
 import org.apache.ode.daohib.SessionManager;
 import org.apache.ode.store.ConfStoreConnectionFactory;
@@ -44,70 +41,39 @@ import org.hibernate.SessionFactory;
 import org.hibernate.cfg.Configuration;
 import org.hibernate.cfg.Environment;
 import org.hibernate.connection.ConnectionProvider;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.DialectFactory;
 
 public class DbConfStoreConnectionFactory implements ConfStoreConnectionFactory {
     private static final Log __log = LogFactory.getLog(DbConfStoreConnectionFactory.class);
 
     private static final Messages __msgs = MessageBundle.getMessages(Messages.class);
 
-    private static final String DEFAULT_HIBERNATE_DIALECT = "org.hibernate.dialect.DerbyDialect";
-
-    private static final HashMap<String, DialectFactory.VersionInsensitiveMapper> HIBERNATE_DIALECTS = new HashMap<String, DialectFactory.VersionInsensitiveMapper>();
-
     private static final String _guid = new GUID().toString();
 
     private static final Map<String, DataSource> _dataSources = new ConcurrentHashMap<String, DataSource>();
 
-    static {
-        // Hibernate has a nice table that resolves the dialect from the database
-        // product name,
-        // but doesn't include all the drivers. So this is supplementary, and some
-        // day in the
-        // future they'll add more drivers and we can get rid of this.
-        // Drivers already recognized by Hibernate:
-        // HSQL Database Engine
-        // DB2/NT
-        // MySQL
-        // PostgreSQL
-        // Microsoft SQL Server Database, Microsoft SQL Server
-        // Sybase SQL Server
-        // Informix Dynamic Server
-        // Oracle 8 and Oracle >8
-        HIBERNATE_DIALECTS.put("Apache Derby", new DialectFactory.VersionInsensitiveMapper(DEFAULT_HIBERNATE_DIALECT));
-        HIBERNATE_DIALECTS.put("H2", new DialectFactory.VersionInsensitiveMapper("org.hibernate.dialect.H2Dialect"));
-    }
-
     private TransactionManager _txMgr;
 
+    private final DataSource _ds;
+
     final SessionFactory _sessionFactory;
 
     public DbConfStoreConnectionFactory(DataSource ds, Properties initialProps, boolean createDatamodel, String txFactoryClassName) {
+        _ds = ds;
+
         // Don't want to pollute original properties
         Properties properties = new Properties();
         for (Object prop : initialProps.keySet()) {
             properties.put(prop, initialProps.get(prop));
         }
 
-        __log.debug("using data source: " + ds);
-        _dataSources.put(_guid, ds);
-
-        if (properties.get(Environment.DIALECT) == null) {
-            try {
-                properties.put(Environment.DIALECT, guessDialect(ds));
-            } catch (Exception ex) {
-                String errmsg = __msgs.msgOdeInitHibernateDialectDetectFailed();
-                __log.error(errmsg, ex);
-                throw new BpelEngineException(errmsg, ex);
-            }
-        }
+        __log.debug("using data source: " + _ds);
+        _dataSources.put(_guid, _ds);
 
         if (createDatamodel) {
             properties.put(Environment.HBM2DDL_AUTO, "create-drop");
         }
 
-        
+
         // Note that we don't allow the following properties to be overriden by the client.
         if (properties.containsKey(Environment.CONNECTION_PROVIDER))
             __log.warn("Ignoring user-specified Hibernate property: " + Environment.CONNECTION_PROVIDER);
@@ -134,76 +100,42 @@ public class DbConfStoreConnectionFactory implements ConfStoreConnectionFactory
         return new ConfStoreConnectionHib(_sessionFactory.getCurrentSession());
     }
 
-	private void initTxMgr(String txFactoryClassName) {
-		__log.info("ProcessStore initializing transaction manager using " + txFactoryClassName);
-		try {
-			Class<?> txFactClass = getClass().getClassLoader().loadClass(txFactoryClassName);
-			Object txFact = txFactClass.newInstance();
-			_txMgr = (TransactionManager) txFactClass.getMethod("getTransactionManager", (Class[]) null).invoke(txFact);
-		} catch (Exception e) {
-			__log.fatal("Couldn't initialize a transaction manager with factory: " + txFactoryClassName, e);
-			throw new RuntimeException("Couldn't initialize a transaction manager with factory: " + txFactoryClassName, e);
-		}
-	}
-
-    private String guessDialect(DataSource dataSource) throws Exception {
-
-        String dialect = null;
-        // Open a connection and use that connection to figure out database
-        // product name/version number in order to decide which Hibernate
-        // dialect to use.
-        Connection conn = dataSource.getConnection();
+    @SuppressWarnings("unchecked")
+    private void initTxMgr(String txFactoryClassName) {
+        __log.info("ProcessStore initializing transaction manager using " + txFactoryClassName);
         try {
-            DatabaseMetaData metaData = conn.getMetaData();
-            if (metaData != null) {
-                String dbProductName = metaData.getDatabaseProductName();
-                int dbMajorVer = metaData.getDatabaseMajorVersion();
-                __log.info("Using database " + dbProductName + " major version " + dbMajorVer);
-                DialectFactory.DatabaseDialectMapper mapper = HIBERNATE_DIALECTS.get(dbProductName);
-                if (mapper != null) {
-                    dialect = mapper.getDialectClass(dbMajorVer);
-                } else {
-                    Dialect hbDialect = DialectFactory.determineDialect(dbProductName, dbMajorVer);
-                    if (hbDialect != null)
-                        dialect = hbDialect.getClass().getName();
-                }
-            }
-        } finally {
-            conn.close();
+            Class<?> txFactClass = getClass().getClassLoader().loadClass(txFactoryClassName);
+            Object txFact = txFactClass.newInstance();
+            _txMgr = (TransactionManager) txFactClass.getMethod("getTransactionManager", (Class[]) null).invoke(txFact);
+        } catch (Exception e) {
+            __log.fatal("Couldn't initialize a transaction manager with factory: " + txFactoryClassName, e);
+            throw new RuntimeException("Couldn't initialize a transaction manager with factory: " + txFactoryClassName, e);
         }
+    }
 
-        if (dialect == null) {
-            __log.info("Cannot determine hibernate dialect for this database: using the default one.");
-            dialect = DEFAULT_HIBERNATE_DIALECT;
+    public void beginTransaction() {
+        try {
+            _txMgr.begin();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
         }
+    }
 
-        return dialect;
-
+    public void commitTransaction() {
+        try {
+            _txMgr.commit();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
 
-    public void beginTransaction() {
-		try {
-			_txMgr.begin();
-		} catch (Exception e) {
-			throw new RuntimeException(e);
-		}
-	}
-
-	public void commitTransaction() {
-		try {
-			_txMgr.commit();
-		} catch (Exception e) {
-			throw new RuntimeException(e);
-		}
-	}
-
-	public void rollbackTransaction() {
-		try {
-			_txMgr.rollback();
-		} catch (Exception e) {
-			throw new RuntimeException(e);
-		}
-	}
+    public void rollbackTransaction() {
+        try {
+            _txMgr.rollback();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
 
     static Configuration getDefaultConfiguration() throws MappingException {
         return new Configuration().addClass(ProcessConfDaoImpl.class).addClass(DeploymentUnitDaoImpl.class)
@@ -217,7 +149,7 @@ public class DbConfStoreConnectionFactory implements ConfStoreConnectionFactory
         }
 
         public void configure(Properties props) throws HibernateException {
-        	_guid = props.getProperty(SessionManager.PROP_GUID);
+            _guid = props.getProperty(SessionManager.PROP_GUID);
         }
 
         public Connection getConnection() throws SQLException {
@@ -236,4 +168,4 @@ public class DbConfStoreConnectionFactory implements ConfStoreConnectionFactory
         }
     }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ode/blob/28085edc/bpel-store/src/test/java/org/apache/ode/store/hib/DaoTest.java
----------------------------------------------------------------------
diff --git a/bpel-store/src/test/java/org/apache/ode/store/hib/DaoTest.java b/bpel-store/src/test/java/org/apache/ode/store/hib/DaoTest.java
index 5dfe899..92a13ca 100644
--- a/bpel-store/src/test/java/org/apache/ode/store/hib/DaoTest.java
+++ b/bpel-store/src/test/java/org/apache/ode/store/hib/DaoTest.java
@@ -18,32 +18,56 @@
  */
 package org.apache.ode.store.hib;
 
+import java.util.Properties;
+
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+import javax.xml.namespace.QName;
+
 import junit.framework.TestCase;
 
+import org.apache.ode.bpel.dao.BpelDAOConnection;
+import org.apache.ode.il.EmbeddedGeronimoFactory;
 import org.apache.ode.il.config.OdeConfigProperties;
+import org.apache.ode.il.dbutil.Database;
+import org.apache.ode.il.dbutil.DatabaseConfigException;
 import org.apache.ode.store.ConfStoreConnection;
 import org.apache.ode.store.ConfStoreConnectionFactory;
 import org.apache.ode.store.DeploymentUnitDAO;
 import org.apache.ode.store.ProcessConfDAO;
-import org.apache.ode.utils.GUID;
-import org.h2.jdbcx.JdbcDataSource;
-import java.util.Properties;
-import javax.xml.namespace.QName;
 
 public class DaoTest extends TestCase {
-    JdbcDataSource h2;
-
+    protected BpelDAOConnection daoConn;
+    protected TransactionManager txm;
+    private DataSource ds;
+    private Database db;
     ConfStoreConnectionFactory cf;
 
+    protected DataSource getDataSource() throws DatabaseConfigException {
+        if (ds == null) {
+            Properties props = new Properties();
+            props.setProperty(OdeConfigProperties.PROP_DAOCF, System.getProperty(OdeConfigProperties.PROP_DAOCF, OdeConfigProperties.DEFAULT_DAOCF_CLASS));
+            OdeConfigProperties odeProps = new OdeConfigProperties(props,"");
+            db = Database.create(odeProps);
+            db.setTransactionManager(txm);
+            db.start();
+            this.ds = db.getDataSource();
+        }
+        return ds;
+    }
+
     public void setUp() throws Exception {
-        h2 = new JdbcDataSource();
-        h2.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
-        h2.setUser("sa");
-        cf = new DbConfStoreConnectionFactory(h2, new Properties(), true, OdeConfigProperties.DEFAULT_TX_FACTORY_CLASS_NAME);
+        EmbeddedGeronimoFactory factory = new EmbeddedGeronimoFactory();
+        txm = factory.getTransactionManager();
+        ds = getDataSource();
+        org.springframework.mock.jndi.SimpleNamingContextBuilder.emptyActivatedContextBuilder().bind("java:comp/UserTransaction", txm);
+        txm.begin();
+
+        cf = new DbConfStoreConnectionFactory(ds, new Properties(), true, OdeConfigProperties.DEFAULT_TX_FACTORY_CLASS_NAME);
     }
 
     public void tearDown() throws Exception {
-        h2.getConnection().createStatement().execute("SHUTDOWN");
+        db.shutdown();
     }
 
     public void testEmpty() {
@@ -99,7 +123,7 @@ public class DaoTest extends TestCase {
             cf.commitTransaction();
         }
     }
-    
+
     public void testGetDeploymentUnits() {
         cf.beginTransaction();
         ConfStoreConnection conn = cf.getConnection();
@@ -124,7 +148,7 @@ public class DaoTest extends TestCase {
             cf.commitTransaction();
         }
     }
-    
+
     public void testCreateProcess() {
         QName foobar = new QName("foo","bar");
         cf.beginTransaction();
@@ -139,7 +163,7 @@ public class DaoTest extends TestCase {
         } finally {
             cf.commitTransaction();
         }
-        
+
         cf.beginTransaction();
         conn = cf.getConnection();
         try {
@@ -147,14 +171,14 @@ public class DaoTest extends TestCase {
             ProcessConfDAO p = du.getProcess(foobar);
             assertNotNull(p);
             assertNotNull(du.getProcesses());
-            
+
             assertEquals(foobar,p.getPID());
             assertEquals(foobar,p.getType());
         } finally {
             cf.commitTransaction();
         }
     }
-    
+
     public void testProcessProperties() {
         QName foobar = new QName("foo","bar");
         cf.beginTransaction();
@@ -166,7 +190,7 @@ public class DaoTest extends TestCase {
         } finally {
             cf.commitTransaction();
         }
-        
+
         cf.beginTransaction();
         conn = cf.getConnection();
         try {
@@ -179,5 +203,5 @@ public class DaoTest extends TestCase {
         } finally {
             cf.commitTransaction();
         }
-    }    
+    }
 }
\ No newline at end of file