Author: mszefler
Date: Mon Jan 15 13:32:09 2007
New Revision: 496500

URL: http://svn.apache.org/viewvc?view=rev&rev=496500
Log:
Removed direct dependnecy on DAO impl.

Added:
    incubator/ode/trunk/jbi/ode-jbi.properties
Modified:
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/Messages.java
    
incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConfigProperties.java
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java

Added: incubator/ode/trunk/jbi/ode-jbi.properties
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/ode-jbi.properties?view=auto&rev=496500
==============================================================================
--- incubator/ode/trunk/jbi/ode-jbi.properties (added)
+++ incubator/ode/trunk/jbi/ode-jbi.properties Mon Jan 15 13:32:09 2007
@@ -0,0 +1,63 @@
+#
+# 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.
+#
+
+# ODE-JBI Configuraiton Properties (TEST CASE) 
+
+# Process Identifier Namespace [QNAME]
+# Namespace for processes created using the JBI integartion.
+# This will be the namespace of the process identifiers (PIDs)
+ode-jbi.pidNamespace=urn:ode-jbi
+
+# Allow Incomplete Deployment ("true","false")
+# Should incomplete deployments be allowed? An incomplete deployment
+# arises when a service unit contains multiple processes and not all
+# of the processes can be deployed. If incomplete deployments are 
+# allowed (true), the service unit will report success if any of the
+# processes can be deployed. If not allowed (false), a failure in
+# one process will prevent all processes from being deployed.
+ode-jbi.allowIncompleteDeployment=false
+
+# Database Mode ("INTERNAL", "EXTERNAL", "EMBEDDED")
+# What kind of database should ODE use?
+#   * "EMBEDDED" - ODE will create its own embbeded database (Derby)
+#                 and connection pool (Minerva).
+#   * "EXTERNAL" - ODE will use an app-server provided database and pool. 
+#                  The "ode-jbi.db.ext.dataSource" property will need to
+#                  be set.
+#   * "INTERNAL" - ODE will create its own connection pool for a user-
+#                  specified JDBC URL and driver.
+ode-jbi.db.mode=EMBEDDED
+
+# External Database [JNDI Name]
+# JNDI Name of the DataSource for the ODE database. This is only
+# used if the "ode-jbi.db.mode" property is set to "EXTERNAL"
+ode-jbi.db.ext.dataSource=java:comp/env/jdbc/ode
+
+# Embedded Database Name [String]
+# Name of the embedded Derby database. This is only used if the
+# "ode-jbi.db.mode" property is set to "EMBEDDED".
+ode-jbi.db.emb.name=data
+
+# Class name of the message mapper that should be used to convert message
+# between ODE / NMS. 
+# org.apache.ode.jbi.msgmap.JbiWsdl11WrapperMapper - use JBI WSDL 1.1 
"warapped" 
+# org.apache.ode.jbi.msgmap.ServiceMixMapper
+ode-jbi.messageMapper=org.apache.ode.jbi.msgmap.DocLitMapper
+#ode-jbi.messageMapper=org.apache.ode.jbi.msgmap.ServiceMixMapper
+

Modified: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/Messages.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/Messages.java?view=diff&rev=496500&r1=496499&r2=496500
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/Messages.java 
(original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/Messages.java Mon 
Jan 15 13:32:09 2007
@@ -40,10 +40,6 @@
 
     }
 
-    public String msgOdeInitHibernatePropertiesNotFound(File expected) {
-        return format("Hibernate configuration file \"{0}\" not found!", 
expected);
-    }
-
     public String msgOdeUsingExternalDb(String dbDataSource) {
         return format("ODE using external DataSource \"{0}\".", dbDataSource);
     }
@@ -125,7 +121,25 @@
     }
 
     public String msgOdeEmbeddedDbNotFoundUsingTemp(File dbDir, File tmpDir) {
-        return format("Embedded database directory \"{0}\" does not exist, 
creating temporary database in \"{1}\"!", dbDir,tmpDir);
+        return format("Embedded database directory \"{0}\" does not exist, 
creating temporary database in \"{1}\"!",
+                dbDir, tmpDir);
+    }
+
+    public Object msgOdeUsingDAOImpl(String className) {
+        return format("Using DAO Connection Factory class {0}.", className);
+    }
+
+    public String msgDAOInstantiationFailed(String className) {
+        return format("Failed to instantiate DAO Connection Factory class 
{0}.", className);
+    }
+
+    public String msgOdeInitDAOErrorReadingProperties(File daoPropFile) {
+        return format("Error reading DAO property file \"{0}\".", daoPropFile);
+
+    }
+
+    public String msgOdeInitDAOPropertiesNotFound(File daoPropFile) {
+        return format("DAO property file \"{0}\" not found.", daoPropFile);
     }
 
 }

Modified: 
incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConfigProperties.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConfigProperties.java?view=diff&rev=496500&r1=496499&r2=496500
==============================================================================
--- 
incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConfigProperties.java
 (original)
+++ 
incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConfigProperties.java
 Mon Jan 15 13:32:09 2007
@@ -28,7 +28,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.ode.jbi.msgmap.JbiWsdl11WrapperMapper;
 
 public class OdeConfigProperties extends Properties {
@@ -43,6 +42,8 @@
     private static final String PROP_NAMESPACE = "ode-jbi.pidNamespace";
 
     private static final String PROP_ALLOW_INCOMPLETE_DEPLOYMENT = 
"ode-jbi.allowIncompleteDeployment";
+   
+    private static final String PROP_DAOCF = "ode-jbi.dao.factory";
 
     private static final String PROP_DB_MODE = "ode-jbi.db.mode";
 
@@ -60,6 +61,7 @@
 
     private static final String PROP_CONNECTOR_NAME = 
"ode-jbi.connector.registryName";
 
+
     private String _installDir;
 
     public OdeConfigProperties(String installRoot) {
@@ -160,5 +162,9 @@
 
     public String getConnectorName() {
         return getProperty(PROP_CONNECTOR_NAME, "ode");
+    }
+
+    public String getDAOConnectionFactory() {
+        return getProperty(PROP_DAOCF, 
"org.apache.ode.dao.jpa.ojpa.BPELDAOConnectionFactoryImpl");        
     }
 }

Modified: 
incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java?view=diff&rev=496500&r1=496499&r2=496500
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java 
(original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java 
Mon Jan 15 13:32:09 2007
@@ -19,49 +19,40 @@
 
 package org.apache.ode.jbi;
 
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Properties;
+import java.util.concurrent.Executors;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.component.ComponentLifeCycle;
+import javax.jbi.component.ServiceUnitManager;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.transaction.TransactionManager;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.derby.jdbc.EmbeddedDriver;
 import org.apache.ode.bpel.connector.BpelServerConnector;
+import org.apache.ode.bpel.dao.BpelDAOConnectionFactoryJDBC;
 import org.apache.ode.bpel.engine.BpelServerImpl;
 import org.apache.ode.bpel.scheduler.quartz.QuartzSchedulerImpl;
-import org.apache.ode.dao.jpa.ojpa.BPELDAOConnectionFactoryImpl;
 import org.apache.ode.jbi.msgmap.Mapper;
 import org.apache.ode.store.ProcessStoreImpl;
 import org.apache.ode.utils.fs.TempFileManager;
-import org.apache.openjpa.ee.ManagedRuntime;
 import org.opentools.minerva.MinervaPool;
 import org.opentools.minerva.MinervaPool.PoolType;
 
-import javax.jbi.JBIException;
-import javax.jbi.component.ComponentContext;
-import javax.jbi.component.ComponentLifeCycle;
-import javax.jbi.component.ServiceUnitManager;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Properties;
-import java.util.concurrent.Executors;
-
 /**
  * This class implements ComponentLifeCycle. The JBI framework will start this
  * engine class automatically when JBI framework starts up.
  */
 public class OdeLifeCycle implements ComponentLifeCycle {
-
-    private static final String DEFAULT_HIBERNATE_DIALECT = 
"org.hibernate.dialect.DerbyDialect";
     private static final Messages __msgs = 
Messages.getMessages(Messages.class);
     private static final Log __log = LogFactory.getLog(OdeLifeCycle.class);
 
@@ -269,25 +260,33 @@
      * @throws JBIException
      */
     private void initDao() throws JBIException {
-        HashMap propMap = new HashMap();
-        propMap.put("openjpa.jdbc.DBDictionary", 
"org.apache.openjpa.jdbc.sql.DerbyDictionary");
-        propMap.put("openjpa.ManagedRuntime", new ManagedRuntime() {
-            public TransactionManager getTransactionManager() throws Exception 
{
-                return _ode.getTransactionManager();
-            }            
-        });
-        propMap.put("openjpa.ConnectionDriverName", 
org.apache.derby.jdbc.EmbeddedDriver.class.getName());
-        propMap.put("javax.persistence.nonJtaDataSource", _ode._dataSource);
-        propMap.put("openjpa.Log", "DefaultLevel=TRACE");
-        EntityManagerFactory emf = 
Persistence.createEntityManagerFactory("ode-dao", propMap);
-//        propMap.put("openjpa.ConnectionUserName", "sa");
-//        propMap.put("openjpa.ConnectionPassword", "");
-//        propMap.put("openjpa.ConnectionDriverName", 
org.apache.derby.jdbc.EmbeddedDriver.class.getName());
-//        propMap.put("ConnectionDriverName", 
org.apache.derby.jdbc.EmbeddedDriver.class.getName());
-//        propMap.put("openjpa.ConnectionURL", url);
-        EntityManager em = emf.createEntityManager();
-//        ((EntityManagerImpl)em).
-        _ode._daocf = new BPELDAOConnectionFactoryImpl(em);
+    
+        Properties properties = new Properties();
+        File daoPropFile;
+        String confDir = _ode.getContext().getInstallRoot();
+        daoPropFile = new File((confDir != null) ? new File(confDir) : new 
File(""), "bpel-dao.properties");
+    
+        if (daoPropFile.exists()) {
+            FileInputStream fis;
+            try {
+                fis = new FileInputStream(daoPropFile);
+                properties.load(new BufferedInputStream(fis));
+            } catch (IOException e) {
+                String errmsg = 
__msgs.msgOdeInitDAOErrorReadingProperties(daoPropFile);
+                __log.error(errmsg, e);
+                throw new JBIException(errmsg, e);
+            }
+        } else {
+            __log.info(__msgs.msgOdeInitDAOPropertiesNotFound(daoPropFile));
+        }
+    
+        BpelDAOConnectionFactoryJDBC cf = createDaoCF();
+        cf.setDataSource(_ode._dataSource);
+        cf.setTransactionManager(_ode.getTransactionManager());
+        cf.init(properties);
+
+
+        _ode._daocf = cf;
     }
 
     private void initConnector() throws JBIException {
@@ -311,6 +310,22 @@
         }
     }
 
+    private BpelDAOConnectionFactoryJDBC createDaoCF() throws JBIException {
+        String pClassName = _ode._config.getDAOConnectionFactory();
+
+        __log.info(__msgs.msgOdeUsingDAOImpl(pClassName));
+
+        BpelDAOConnectionFactoryJDBC cf;
+        try {
+            cf = (BpelDAOConnectionFactoryJDBC) 
Class.forName(pClassName).newInstance();
+        } catch (Exception ex) {
+            String errmsg = __msgs.msgDAOInstantiationFailed(pClassName);
+            __log.error(errmsg, ex);
+            throw new JBIException(errmsg, ex);
+        }
+
+        return cf;
+    }
 
     public synchronized void start() throws JBIException {
         if (_started)
@@ -464,68 +479,5 @@
 
     }
 
-    /*
-    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();
-        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 = 
(DialectFactory.DatabaseDialectMapper) 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();
-        }
-
-        if (dialect == null) {
-            __log
-                    .info("Cannot determine hibernate dialect for this 
database: using the default one.");
-            dialect = DEFAULT_HIBERNATE_DIALECT;
-        }
-
-        assert dialect != null;
-
-        return dialect;
-
-    }
-
-    private static final HashMap<String, 
DialectFactory.VersionInsensitiveMapper> HIBERNATE_DIALECTS = new 
HashMap<String, DialectFactory.VersionInsensitiveMapper>();
-
-    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(
-                        "org.hibernate.dialect.DerbyDialect"));
-    }
-    */
-
+  
 }


Reply via email to