You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2006/12/03 18:32:07 UTC

svn commit: r481832 - in /incubator/openejb/trunk/openejb3/container/openejb-core: ./ src/main/java/org/apache/openejb/alt/containers/castor_cmp11/ src/main/java/org/apache/openejb/core/ src/main/java/org/apache/openejb/core/cmp/ src/main/resources/ sr...

Author: dain
Date: Sun Dec  3 09:32:06 2006
New Revision: 481832

URL: http://svn.apache.org/viewvc?view=rev&rev=481832
Log:
Extensive refactoring of the CastorCMP11_EntityContainer
Encapsulated Castor specific code into a CastorCmpEngine
Renamed remaining CastorCMP11_EntityContainer to org.apache.openejb.core.cmp.CmpContainer.java
CmpEngine implementation is created with a pluggable CmpEngineFactory specified with a property of the same name and the default being org.apache.openejb.alt.containers.castor_cmp11.CastorCmpEngineFactory

Added:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngine.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngineFactory.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpCallback.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngine.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngineFactory.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpTxPolicy.java   (contents, props changed)
      - copied, changed from r481685, incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEntityTxPolicy.java
Removed:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCMP11_EntityContainer.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEntityTxPolicy.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/LocalCastorContainer.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring.xml
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring2.xml
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml?view=diff&rev=481832&r1=481831&r2=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/pom.xml Sun Dec  3 09:32:06 2006
@@ -114,6 +114,10 @@
   </build>
   <dependencies>
     <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-jpa_3.0_spec</artifactId>
+    </dependency>
+    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
     </dependency>

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngine.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngine.java?view=auto&rev=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngine.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngine.java Sun Dec  3 09:32:06 2006
@@ -0,0 +1,529 @@
+/**
+ *
+ * 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.openejb.alt.containers.castor_cmp11;
+
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.SystemException;
+import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.openejb.core.ThreadContext;
+import org.apache.openejb.core.cmp.CmpCallback;
+import org.apache.openejb.core.cmp.CmpEngine;
+import org.apache.openejb.resource.jdbc.JdbcConnectionFactory;
+import org.apache.openejb.util.Logger;
+import org.exolab.castor.jdo.Database;
+import org.exolab.castor.jdo.JDOManager;
+import org.exolab.castor.jdo.OQLQuery;
+import org.exolab.castor.jdo.PersistenceException;
+import org.exolab.castor.jdo.QueryResults;
+import org.exolab.castor.jdo.TransactionNotInProgressException;
+import org.exolab.castor.mapping.AccessMode;
+import org.exolab.castor.persist.spi.CallbackInterceptor;
+import org.exolab.castor.persist.spi.Complex;
+import org.exolab.castor.persist.spi.InstanceFactory;
+
+import javax.ejb.CreateException;
+import javax.ejb.DuplicateKeyException;
+import javax.ejb.EJBException;
+import javax.ejb.EJBObject;
+import javax.ejb.EntityBean;
+import javax.ejb.FinderException;
+import javax.ejb.RemoveException;
+import javax.naming.InitialContext;
+import javax.persistence.EntityTransaction;
+import javax.transaction.TransactionManager;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class CastorCmpEngine implements CmpEngine {
+    private static final Logger logger = Logger.getInstance("OpenEJB", "org.apache.openejb.core.cmp");
+    private static final Object[] NO_ARGS = new Object[0];
+
+    private final JDOManager localJdoManager;
+    private final JDOManager globalJdoManager;
+    private final CmpCallback cmpCallback;
+
+    public CastorCmpEngine(CmpCallback cmpCallback, TransactionManager transactionManager, DeploymentInfo[] deploys, String engine, String connectorName) throws OpenEJBException {
+        this.cmpCallback = cmpCallback;
+        String transactionManagerJndiName = "java:openejb/TransactionManager";
+
+        Map<String, URL> mappings = new HashMap<String, URL>();
+        JndiTxReference txReference = new JndiTxReference(transactionManager);
+        for (DeploymentInfo deploymentInfo : deploys) {
+            CoreDeploymentInfo di = (CoreDeploymentInfo) deploymentInfo;
+
+            if (di.getJarPath() == null) {
+                // DMB: This may pull in more than we like
+                try {
+                    ClassLoader classLoader = di.getBeanClass().getClassLoader();
+                    Enumeration<URL> resources = classLoader.getResources("META-INF/cmp.mapping.xml");
+                    while (resources.hasMoreElements()) {
+                        URL url = resources.nextElement();
+                        mappings.put(url.toExternalForm(), url);
+                    }
+                } catch (IOException e) {
+                    throw new OpenEJBException("Error locating mapping file via classloader for deployment " + di.getDeploymentID(), e);
+                }
+            } else {
+                URL url = null;
+                try {
+                    String jarPath = di.getJarPath();
+                    File file = new File(jarPath);
+
+                    if (file.isDirectory()) {
+                        file = new File(file, "META-INF");
+                        file = new File(file, "cmp.mapping.xml");
+                        url = file.toURL();
+                    } else {
+                        url = file.toURL();
+                        url = new URL("jar:" + url.toExternalForm() + "!/META-INF/cmp.mapping.xml");
+                    }
+                    mappings.put(url.toExternalForm(), url);
+                } catch (MalformedURLException e) {
+                    throw new OpenEJBException("Error locating mapping file " + url + " for deployment " + di.getDeploymentID(), e);
+                }
+            }
+
+            bindTransactionManagerReference(di, transactionManagerJndiName, txReference);
+
+            configureKeyGenerator(di);
+            addFindByPrimaryKeyQueries(di);
+        }
+
+
+        try {
+            JDOManagerBuilder jdoManagerBuilder = new JDOManagerBuilder(engine, transactionManagerJndiName, new JoinedClassLoader(deploys));
+
+            Collection<URL> urls = mappings.values();
+            for (Iterator<URL> iterator = urls.iterator(); iterator.hasNext();) {
+                URL url = iterator.next();
+                logger.debug("Mapping file: " + url.toExternalForm());
+                jdoManagerBuilder.addMapping(url);
+            }
+
+            String jdbcName = "java:openejb/connector/" + connectorName;
+            JdbcConnectionFactory connectionFactory = (JdbcConnectionFactory) new InitialContext().lookup(jdbcName);
+            if (connectionFactory == null) {
+                throw new OpenEJBException(jdbcName + " does not exist");
+            }
+
+            globalJdoManager = jdoManagerBuilder.buildGlobalJDOManager(jdbcName);
+            globalJdoManager.setDatabasePooling(true);
+            globalJdoManager.setCallbackInterceptor(new CastorCallbackInterceptor());
+            globalJdoManager.setInstanceFactory(new CastorInstanceFactory());
+
+            localJdoManager = jdoManagerBuilder.buildLocalJDOManager(connectionFactory.getJdbcDriver(), connectionFactory.getJdbcUrl(), connectionFactory.getDefaultUserName(), connectionFactory.getDefaultPassword());
+            localJdoManager.setCallbackInterceptor(new CastorCallbackInterceptor());
+            localJdoManager.setInstanceFactory(new CastorInstanceFactory());
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new OpenEJBException("Unable to construct the Castor JDOManager objects: " + e.getClass().getName() + ": " + e.getMessage(), e);
+        }
+    }
+
+    public EntityTransaction getTransaction() {
+        try {
+            Database database = localJdoManager.getDatabase();
+            return new CastorEntityTransaction(database);
+        } catch (PersistenceException e) {
+            throw new javax.persistence.PersistenceException(e);
+        }
+    }
+
+    public Object createBean(EntityBean bean, ThreadContext callContext) throws CreateException {
+        try {
+            Database db = getDatabase(callContext);
+
+            // Create a Castor Transaction if there isn't one in progress
+            if (!db.isActive()) db.begin();
+
+            // Use Castor JDO to insert the entity bean into the database
+            db.create(bean);
+
+            // extract the primary key from the bean
+            CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
+            KeyGenerator kg = deploymentInfo.getKeyGenerator();
+            Object primaryKey = kg.getPrimaryKey(bean);
+
+            return primaryKey;
+        } catch (org.exolab.castor.jdo.DuplicateIdentityException e) {
+            throw new DuplicateKeyException("Attempt to create an entity bean (DeploymentID=\"" + callContext.getDeploymentInfo().getDeploymentID() + "\") with an primary key that already exsists. Castor nested exception message = " + e.getMessage());
+        } catch (PersistenceException e) {
+            throw (CreateException) new CreateException("Unable to create ejb (DeploymentID=\"" + callContext.getDeploymentInfo().getDeploymentID() + "\")").initCause(e);
+        }
+    }
+
+    public Object loadBean(ThreadContext callContext) {
+        try {
+            Database db = getDatabase(callContext);
+
+            Object primaryKey = getPrimaryKey(callContext);
+            Object bean = db.load(callContext.getDeploymentInfo().getBeanClass(), primaryKey);
+            return bean;
+        } catch (org.exolab.castor.jdo.PersistenceException e) {
+            throw new EJBException("Unable to load ejb (DeploymentID=\"" + callContext.getDeploymentInfo().getDeploymentID() + "\")", e);
+        }
+    }
+
+    public void removeBean(ThreadContext callContext) {
+        try {
+            Database db = getDatabase(callContext);
+
+            if (!db.isActive()) db.begin();
+
+            Object primaryKey = getPrimaryKey(callContext);
+            Object bean = db.load(callContext.getDeploymentInfo().getBeanClass(), primaryKey);
+            db.remove(bean);
+        } catch (org.exolab.castor.jdo.PersistenceException e) {
+            throw new EJBException("Unable to remove ejb (DeploymentID=\"" + callContext.getDeploymentInfo().getDeploymentID() + "\")", e);
+        }
+    }
+
+    public List<Object> queryBeans(ThreadContext callContext, String queryString, Method callMethod, Object[] args) throws FinderException {
+        try {
+            Database db = getDatabase(callContext);
+
+            // Create a Castor Transaction if there isn't one in progress
+            if (!db.isActive()) db.begin();
+
+            /*
+              Obtain a OQLQuery object based on the String query
+            */
+            OQLQuery query = db.getOQLQuery(queryString);
+
+            // process args
+            Object[] queryArgs;
+            if (args == null) {
+                queryArgs = NO_ARGS;
+            } else {
+                queryArgs = args.clone();
+            }
+            if (callMethod.getName().equals("findByPrimaryKey")) {
+
+                KeyGenerator kg = callContext.getDeploymentInfo().getKeyGenerator();
+
+                if (kg.isKeyComplex()) {
+                    /*
+                    * This code moves the fields of the primary key into a JDO Complex object
+                    * which can then be used in the database.bind operation
+                    */
+                    Complex c = kg.getJdoComplex(queryArgs[0]);
+                    queryArgs = new Object[c.size()];
+                    for (int i = 0; i < queryArgs.length; i++)
+                        queryArgs[i] = c.get(i);
+                }
+            }
+
+            for (int i = 0; i < queryArgs.length; i++) {
+                if (queryArgs[i] instanceof EJBObject) {
+                    /*
+                    Its possible that the finder method's arguments are actually EJBObject reference in
+                    which case the EJBObject reference is replaced with the EJB object's primary key.
+                    The limitation of this facility is that the EJB object must use a single field primary key
+                    and not a complex primary key. Complex primary keys of EJBObject argumetns are not supported.
+                    For Example:
+
+                    EJB Home Interface Find method:
+                    public Collection findThings(Customer customer);
+
+                    OQL in deployment descriptor
+                    "SELECT t FROM Thing t WHERE t.customer_id = $1"
+
+                    */
+                    try {
+                        queryArgs[i] = ((EJBObject) queryArgs[i]).getPrimaryKey();
+                    } catch (RemoteException re) {
+
+                        throw new FinderException("Could not extract primary key from EJBObject reference; argument number " + i);
+                    }
+                }
+
+                /*
+                Bind the arguments of the home interface find method to the query.
+                The big assumption here is that the arguments of the find operation
+                are in the same order as the arguments in the query.  The bean developer
+                must declare the OQL arguments with the proper number so that match the order
+                of the find arguments.
+                For Example:
+
+                EJB Home Interface Find method:
+                public Collection findThings(String name, double weight, String Type);
+
+                OQL in deployment descriptor
+                "SELECT t FROM Thing t WHERE t.weight = $2 AND t.type = $3 AND t.name = $1"
+                */
+
+                query.bind(queryArgs[i]);
+            }
+
+            /*  execute the query */
+            List<Object> results;
+            QueryResults queryResults = null;
+            try {
+                queryResults = query.execute();
+
+                results = new ArrayList<Object>();
+                while (queryResults.hasMore()) {
+                    Object item = queryResults.next();
+                    results.add(item);
+                }
+            } finally {
+                if (queryResults != null) queryResults.close();
+            }
+            return results;
+        } catch (PersistenceException e) {
+            throw (FinderException) new FinderException("Error executing query").initCause(e);
+        }
+    }
+
+    private Object getPrimaryKey(ThreadContext callContext) {
+        Object primaryKey = callContext.getPrimaryKey();
+        KeyGenerator kg = callContext.getDeploymentInfo().getKeyGenerator();
+        if (kg.isKeyComplex()) {
+            primaryKey = kg.getJdoComplex(callContext.getPrimaryKey());
+        }
+        return primaryKey;
+    }
+
+    private Database getDatabase(ThreadContext callContext) throws PersistenceException {
+        CastorEntityTransaction castorEntityTransaction = (CastorEntityTransaction) callContext.getUnspecified();
+        if (castorEntityTransaction != null) {
+            return castorEntityTransaction.database;
+        } else {
+            /*
+             BIG PROBLEM: Transacitons should use the same Database object.
+             If Thomas won't put this into JDO then I'll have to put into the
+             container.
+
+             1. Check thread to see if current transacion is mapped to any
+                existing Database object.
+
+             2. If it is, return that Database object.
+
+             3. If not obtain new Database object
+
+             4. Register the Tranaction and Database object in a hashmap keyed
+                by tx.
+
+             5. When transaction completes, remove tx-to-database mapping from
+                hashmap.
+
+             */
+            return globalJdoManager.getDatabase();
+        }
+    }
+
+
+    private static class JoinedClassLoader extends ClassLoader {
+        private final DeploymentInfo[] deploymentInfos;
+
+        public JoinedClassLoader(DeploymentInfo[] deploymentInfos) {
+            this.deploymentInfos = deploymentInfos;
+        }
+
+        protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+            for (DeploymentInfo info : deploymentInfos) {
+                try {
+                    ClassLoader classLoader = info.getBeanClass().getClassLoader();
+                    return classLoader.loadClass(name);
+                } catch (ClassNotFoundException keepTrying) {
+                }
+            }
+            throw new ClassNotFoundException(name);
+        }
+    }
+
+    /**
+     * Castor JDO obtains a reference to the TransactionManager throught the InitialContext.
+     * The new InitialContext will use the deployment's JNDI Context, which is normal inside
+     * the container system, so we need to bind the TransactionManager to the deployment's name space
+     * The biggest problem with this is that the bean itself may access the TransactionManager if it
+     * knows the JNDI name, so we bind the TransactionManager into dynamically created transient name
+     * space based every time the container starts. It nearly impossible for the bean to anticipate
+     * and use the binding directly.  It may be possible, however, to locate it using a Context listing method.
+     */
+    private void bindTransactionManagerReference(CoreDeploymentInfo di, String transactionManagerJndiName, JndiTxReference txReference) throws SystemException {
+        try {
+            di.getJndiEnc().bind(transactionManagerJndiName, txReference);
+        } catch (Exception e) {
+            logger.error("Unable to bind TransactionManager to deployment id = " + di.getDeploymentID() + " using JNDI name = \"" + transactionManagerJndiName + "\"", e);
+            throw new SystemException("Unable to bind TransactionManager to deployment id = " + di.getDeploymentID() + " using JNDI name = \"" + transactionManagerJndiName + "\"", e);
+        }
+    }
+
+    private void configureKeyGenerator(CoreDeploymentInfo di) throws SystemException {
+        try {
+            KeyGenerator kg = KeyGeneratorFactory.createKeyGenerator(di);
+            di.setKeyGenerator(kg);
+        } catch (Exception e) {
+            logger.error("Unable to create KeyGenerator for deployment id = " + di.getDeploymentID(), e);
+            throw new SystemException("Unable to create KeyGenerator for deployment id = " + di.getDeploymentID(), e);
+        }
+    }
+
+    private void addFindByPrimaryKeyQueries(CoreDeploymentInfo di) throws SystemException {
+        try {
+            StringBuffer findByPrimarKeyQuery = new StringBuffer("SELECT e FROM " + di.getBeanClass().getName() + " e WHERE ");
+
+            Field primaryKeyField = di.getPrimaryKeyField();
+            if (primaryKeyField != null) {
+                findByPrimarKeyQuery.append("e.").append(primaryKeyField.getName()).append(" = $1");
+            } else {
+                Field[] pkFields = di.getPrimaryKeyClass().getFields();
+                for (int i = 1; i <= pkFields.length; i++) {
+                    findByPrimarKeyQuery.append("e.").append(pkFields[i - 1].getName()).append(" = $").append(i);
+                    if ((i + 1) <= pkFields.length) findByPrimarKeyQuery.append(" AND ");
+                }
+
+            }
+
+            if (di.getHomeInterface() != null) {
+                Method findByPrimaryKeyMethod = di.getHomeInterface().getMethod("findByPrimaryKey", di.getPrimaryKeyClass());
+                di.addQuery(findByPrimaryKeyMethod, findByPrimarKeyQuery.toString());
+            }
+            if (di.getLocalHomeInterface() != null) {
+                Method findByPrimaryKeyMethod = di.getLocalHomeInterface().getMethod("findByPrimaryKey", di.getPrimaryKeyClass());
+                di.addQuery(findByPrimaryKeyMethod, findByPrimarKeyQuery.toString());
+            }
+        } catch (Exception e) {
+            throw new SystemException("Could not generate a query statement for the findByPrimaryKey method of the deployment = " + di.getDeploymentID(), e);
+        }
+    }
+
+    private class CastorInstanceFactory implements InstanceFactory {
+        public Object newInstance(String className, ClassLoader loader) {
+            EntityBean bean;
+            try {
+                ThreadContext callContext = ThreadContext.getThreadContext();
+                CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
+                bean = (EntityBean) deploymentInfo.getBeanClass().newInstance();
+            } catch (Exception e) {
+                throw new EJBException("Unable to create new entity bean instance");
+            }
+
+            cmpCallback.setEntityContext(bean);
+            return bean;
+        }
+    }
+
+    private class CastorCallbackInterceptor implements CallbackInterceptor {
+        public Class loaded(Object bean, AccessMode mode) throws Exception {
+            cmpCallback.ejbActivate((EntityBean) bean);
+            cmpCallback.ejbLoad((EntityBean) bean);
+            return null;
+        }
+
+        public void storing(Object bean, boolean modified) {
+            cmpCallback.ejbStore((EntityBean) bean);
+        }
+
+        public void removing(Object bean) throws RemoveException {
+            cmpCallback.ejbRemove((EntityBean) bean);
+        }
+
+        public void releasing(Object bean, boolean committed) {
+            cmpCallback.ejbPassivate((EntityBean) bean);
+            cmpCallback.unsetEntityContext((EntityBean) bean);
+        }
+
+        public void creating(Object bean, Database db) {
+        }
+
+        public void created(Object bean) {
+        }
+
+        public void removed(Object bean) {
+        }
+
+        public void using(Object bean, Database db) {
+        }
+
+        public void updated(Object bean) {
+        }
+    }
+
+    public static class CastorEntityTransaction implements EntityTransaction {
+        private final Database database;
+        private boolean rollbackOnly;
+
+        public CastorEntityTransaction(Database database) {
+            this.database = database;
+        }
+
+        public Database getDatabase() {
+            return database;
+        }
+
+        public void begin() {
+            if (database.isActive()) throw new IllegalStateException("Transaction already in progress");
+
+            try {
+                database.begin();
+            } catch (PersistenceException e) {
+                throw new javax.persistence.PersistenceException(e);
+            }
+        }
+
+        public void commit() {
+            try {
+                if (rollbackOnly) {
+                    database.rollback();
+                    throw new javax.persistence.RollbackException();
+                } else {
+                    database.commit();
+                }
+            } catch (TransactionNotInProgressException e) {
+                throw new IllegalStateException("Transaction not in progress");
+            } catch (PersistenceException e) {
+                throw new javax.persistence.PersistenceException(e);
+            }
+        }
+
+        public void rollback() {
+            try {
+                database.rollback();
+            } catch (TransactionNotInProgressException e) {
+                throw new IllegalStateException("Transaction not in progress");
+            }
+        }
+
+        public boolean isActive() {
+            return database.isActive();
+        }
+
+        public void setRollbackOnly() {
+            rollbackOnly = true;
+        }
+
+        public boolean getRollbackOnly() {
+            return rollbackOnly;
+        }
+    }
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngineFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngineFactory.java?view=auto&rev=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngineFactory.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEngineFactory.java Sun Dec  3 09:32:06 2006
@@ -0,0 +1,78 @@
+/**
+ *
+ * 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.openejb.alt.containers.castor_cmp11;
+
+import org.apache.openejb.core.cmp.CmpEngine;
+import org.apache.openejb.core.cmp.CmpCallback;
+import org.apache.openejb.core.cmp.CmpEngineFactory;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.OpenEJBException;
+
+import javax.transaction.TransactionManager;
+
+public class CastorCmpEngineFactory implements CmpEngineFactory {
+    private TransactionManager transactionManager;
+    private DeploymentInfo[] deploys;
+    private String engine;
+    private String connectorName;
+    private CmpCallback cmpCallback;
+
+    public TransactionManager getTransactionManager() {
+        return transactionManager;
+    }
+
+    public void setTransactionManager(TransactionManager transactionManager) {
+        this.transactionManager = transactionManager;
+    }
+
+    public DeploymentInfo[] getDeploys() {
+        return deploys;
+    }
+
+    public void setDeploymentInfos(DeploymentInfo[] deploys) {
+        this.deploys = deploys;
+    }
+
+    public String getEngine() {
+        return engine;
+    }
+
+    public void setEngine(String engine) {
+        this.engine = engine;
+    }
+
+    public String getConnectorName() {
+        return connectorName;
+    }
+
+    public void setConnectorName(String connectorName) {
+        this.connectorName = connectorName;
+    }
+
+    public CmpCallback getCmpCallback() {
+        return cmpCallback;
+    }
+
+    public void setCmpCallback(CmpCallback cmpCallback) {
+        this.cmpCallback = cmpCallback;
+    }
+
+    public CmpEngine create() throws OpenEJBException {
+        return new CastorCmpEngine(cmpCallback, transactionManager, deploys, engine, connectorName);
+    }
+}

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java?view=diff&rev=481832&r1=481831&r2=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java Sun Dec  3 09:32:06 2006
@@ -40,7 +40,7 @@
 import org.apache.openejb.InterfaceType;
 import org.apache.openejb.DeploymentInfo;
 import org.apache.openejb.BeanType;
-import org.apache.openejb.alt.containers.castor_cmp11.CastorCmpEntityTxPolicy;
+import org.apache.openejb.core.cmp.CmpTxPolicy;
 import org.apache.openejb.alt.containers.castor_cmp11.KeyGenerator;
 import org.apache.openejb.core.entity.EntityEjbHomeHandler;
 import org.apache.openejb.core.ivm.EjbHomeProxyHandler;
@@ -232,7 +232,7 @@
                 policy = new StatefulContainerManagedTxPolicy(policy);
             } else if (componentType == BeanType.CMP_ENTITY) {
                 policy = new TxNotSupported((TransactionContainer) container);
-                policy = new CastorCmpEntityTxPolicy(policy);
+                policy = new CmpTxPolicy(policy);
             } else {
                 policy = new TxNotSupported((TransactionContainer) container);
             }
@@ -468,7 +468,7 @@
             }
 
         } else if (componentType == BeanType.CMP_ENTITY) {
-            policy = new CastorCmpEntityTxPolicy(policy);
+            policy = new CmpTxPolicy(policy);
         }
         methodTransactionAttributes.put(method, byteValue);
         methodTransactionPolicies.put(method, policy);

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpCallback.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpCallback.java?view=auto&rev=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpCallback.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpCallback.java Sun Dec  3 09:32:06 2006
@@ -0,0 +1,37 @@
+/**
+ *
+ * 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.openejb.core.cmp;
+
+import javax.ejb.EntityBean;
+import javax.ejb.RemoveException;
+
+public interface CmpCallback {
+    void setEntityContext(EntityBean entity);
+
+    void unsetEntityContext(EntityBean entity);
+
+    void ejbActivate(EntityBean entity);
+
+    void ejbPassivate(EntityBean entity);
+
+    void ejbLoad(EntityBean entity);
+
+    void ejbStore(EntityBean entity);
+
+    void ejbRemove(EntityBean entity) throws RemoveException;
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java?view=auto&rev=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java Sun Dec  3 09:32:06 2006
@@ -0,0 +1,584 @@
+/**
+ *
+ * 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.openejb.core.cmp;
+
+import org.apache.openejb.RpcContainer;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.Container;
+import org.apache.openejb.ApplicationException;
+import org.apache.openejb.InvalidateReferenceException;
+import org.apache.openejb.ProxyInfo;
+import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.util.Enumerator;
+import org.apache.openejb.alt.containers.castor_cmp11.KeyGenerator;
+import org.apache.openejb.core.transaction.TransactionContainer;
+import org.apache.openejb.core.transaction.TransactionPolicy;
+import org.apache.openejb.core.transaction.TransactionContext;
+import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.openejb.core.ThreadContext;
+import org.apache.openejb.core.Operations;
+import org.apache.openejb.core.entity.EntityContext;
+
+import javax.ejb.EntityBean;
+import javax.ejb.RemoveException;
+import javax.ejb.EJBException;
+import javax.ejb.EJBHome;
+import javax.ejb.EJBLocalHome;
+import javax.ejb.EJBObject;
+import javax.ejb.EJBLocalObject;
+import javax.ejb.CreateException;
+import javax.ejb.ObjectNotFoundException;
+import javax.transaction.TransactionManager;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.rmi.RemoteException;
+import java.util.List;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Vector;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @org.apache.xbean.XBean element="cmpContainer"
+ */
+public class CmpContainer implements RpcContainer, TransactionContainer {
+    protected final Object containerID;
+    protected final TransactionManager transactionManager;
+    protected final SecurityService securityService;
+    protected final Map<Object, DeploymentInfo> deploymentsById = new HashMap<Object, DeploymentInfo>();
+    protected final Map<Class, DeploymentInfo> deploymentsByClass = new HashMap<Class, DeploymentInfo>();
+    protected final CmpEngine cmpEngine;
+
+    public CmpContainer(Object id, TransactionManager transactionManager, SecurityService securityService, HashMap<Object, DeploymentInfo> registry, String cmpEngineFactory, String engine, String connectorName) throws OpenEJBException {
+        this.transactionManager = transactionManager;
+        this.securityService = securityService;
+        this.containerID = id;
+        this.deploymentsById.putAll(registry);
+
+        /*
+        * This block of code is necessary to avoid a chicken and egg problem.
+        * The DeploymentInfo objects must have a reference to their container
+        * during this assembly process, but the container is created after the
+        * DeploymentInfo necessitating this loop to assign all deployment info
+        * object's their containers.
+        *
+        * In addition the loop is leveraged for other oprations like creating
+        * the method ready pool and the keyGenerator pool.
+        */
+        DeploymentInfo[] deploys = this.deployments();
+
+        for (DeploymentInfo deploymentInfo : deploys) {
+            CoreDeploymentInfo di = (CoreDeploymentInfo) deploymentInfo;
+            di.setContainer(this);
+            deploymentsByClass.put(di.getBeanClass(), di);
+        }
+
+        CmpEngineFactory factory = null;
+        try {
+            Class<?> cmpEngineFactoryClass = getClass().getClassLoader().loadClass(cmpEngineFactory);
+            factory = (CmpEngineFactory) cmpEngineFactoryClass.newInstance();
+        } catch (Exception e) {
+            throw new OpenEJBException("Unable to create cmp engine factory " + cmpEngineFactory, e);
+        }
+        factory.setTransactionManager(transactionManager);
+        factory.setDeploymentInfos(deploys);
+        factory.setConnectorName(connectorName);
+        factory.setCmpCallback(new ContainerCmpCallback());
+        factory.setEngine(engine);
+        cmpEngine = factory.create();
+    }
+
+    public CmpEngine getCmpEngine() {
+        return cmpEngine;
+    }
+
+    public DeploymentInfo[] deployments() {
+        return deploymentsById.values().toArray(new DeploymentInfo[deploymentsById.size()]);
+    }
+
+    public DeploymentInfo getDeploymentInfo(Object deploymentID) {
+        return deploymentsById.get(deploymentID);
+    }
+
+    public DeploymentInfo getDeploymentInfoByClass(Class beanType) {
+        return deploymentsByClass.get(beanType);
+    }
+
+    public int getContainerType() {
+        return Container.ENTITY;
+    }
+
+    public Object getContainerID() {
+        return containerID;
+    }
+
+    public void deploy(Object deploymentID, DeploymentInfo deploymentInfo) throws OpenEJBException {
+        if (true) throw new UnsupportedClassVersionError("DISABLED");
+        deploymentsById.put(deploymentID, deploymentInfo);
+        deploymentsByClass.put(deploymentInfo.getBeanClass(), deploymentInfo);
+        CoreDeploymentInfo di = (CoreDeploymentInfo) deploymentInfo;
+        di.setContainer(this);
+    }
+
+    public Object invoke(Object deployID, Method callMethod, Object[] args, Object primKey, Object securityIdentity) throws OpenEJBException {
+        CoreDeploymentInfo deployInfo = (CoreDeploymentInfo) this.getDeploymentInfo(deployID);
+        ThreadContext callContext = new ThreadContext();
+        callContext.set(deployInfo, primKey, securityIdentity);
+
+        ThreadContext oldCallContext = ThreadContext.getThreadContext();
+        ThreadContext.setThreadContext(callContext);
+        try {
+
+            boolean authorized = securityService.isCallerAuthorized(securityIdentity, deployInfo.getAuthorizedRoles(callMethod));
+            if (!authorized) {
+                throw new ApplicationException(new RemoteException("Unauthorized Access by Principal Denied"));
+            }
+
+            Class declaringClass = callMethod.getDeclaringClass();
+            String methodName = callMethod.getName();
+
+            if (EJBHome.class.isAssignableFrom(declaringClass) || EJBLocalHome.class.isAssignableFrom(declaringClass)) {
+                if (declaringClass != EJBHome.class && declaringClass != EJBLocalHome.class) {
+                    if (methodName.equals("create")) {
+                        return createEJBObject(callMethod, args, callContext);
+                    } else if (methodName.startsWith("find")) {
+                        return findEJBObject(callMethod, args, callContext);
+                    } else {
+                        throw new InvalidateReferenceException(new RemoteException("Invalid method " + methodName + " only find<METHOD>( ) and create( ) method are allowed in EJB 1.1 container-managed persistence"));
+                    }
+                } else if (methodName.equals("remove")) {
+                    removeEJBObject(callMethod, callContext);
+                    return null;
+                }
+            } else if ((EJBObject.class == declaringClass || EJBLocalObject.class == declaringClass) && methodName.equals("remove")) {
+                removeEJBObject(callMethod, callContext);
+                return null;
+            }
+
+            // business method
+            callContext.setCurrentOperation(Operations.OP_BUSINESS);
+            Method runMethod = deployInfo.getMatchingBeanMethod(callMethod);
+
+            Object retValue = businessMethod(callMethod, runMethod, args, callContext);
+
+            return retValue;
+        } finally {
+            /*
+                The thread context must be stripped from the thread before returning or throwing an exception
+                so that an object outside the container does not have access to a
+                bean's JNDI ENC.  In addition, its important for the
+                org.apache.openejb.core.ivm.java.javaURLContextFactory, which determines the context
+                of a JNDI lookup based on the presence of a ThreadContext object.  If no ThreadContext
+                object is available, then the request is assumed to be made from outside the container
+                system and is given the global OpenEJB JNDI name space instead.  If there is a thread context,
+                then the request is assumed to be made from within the container system and so the
+                javaContextFactory must return the JNDI ENC of the current enterprise bean which it
+                obtains from the DeploymentInfo object associated with the current thread context.
+            */
+            ThreadContext.setThreadContext(oldCallContext);
+        }
+    }
+
+    public void discardInstance(Object bean, ThreadContext threadContext) {
+    }
+
+    private EntityBean createNewInstance(ThreadContext callContext) {
+        CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
+        try {
+            EntityBean bean = (EntityBean) deploymentInfo.getBeanClass().newInstance();
+            return bean;
+        } catch (Exception e) {
+            throw new EJBException("Unable to create new entity bean instance");
+        }
+    }
+
+    private ThreadContext createThreadContext(EntityBean entityBean) {
+        if (entityBean == null) throw new NullPointerException("entityBean is null");
+
+        CoreDeploymentInfo deployInfo = (CoreDeploymentInfo) getDeploymentInfoByClass(entityBean.getClass());
+        KeyGenerator keyGenerator = deployInfo.getKeyGenerator();
+        Object primaryKey = keyGenerator.getPrimaryKey(entityBean);
+
+        ThreadContext callContext = new ThreadContext();
+        callContext.set(deployInfo, primaryKey, null);
+        return callContext;
+    }
+
+    private void setEntityContext(EntityBean entityBean) {
+        if (entityBean == null) throw new NullPointerException("entityBean is null");
+
+        // activating entity doen't have a primary key
+        CoreDeploymentInfo deployInfo = (CoreDeploymentInfo) getDeploymentInfoByClass(entityBean.getClass());
+
+        ThreadContext callContext = new ThreadContext();
+        callContext.setDeploymentInfo(deployInfo);
+        callContext.setCurrentOperation(Operations.OP_SET_CONTEXT);
+
+        ThreadContext oldCallContext = ThreadContext.getThreadContext();
+        ThreadContext.setThreadContext(callContext);
+        try {
+            entityBean.setEntityContext(new EntityContext(transactionManager, securityService));
+        } catch (RemoteException e) {
+            throw new EJBException(e);
+        } finally {
+            ThreadContext.setThreadContext(oldCallContext);
+        }
+    }
+
+    private void unsetEntityContext(EntityBean entityBean) {
+        if (entityBean == null) throw new NullPointerException("entityBean is null");
+
+        ThreadContext callContext = createThreadContext(entityBean);
+        callContext.setCurrentOperation(Operations.OP_UNSET_CONTEXT);
+
+        ThreadContext oldCallContext = ThreadContext.getThreadContext();
+        ThreadContext.setThreadContext(callContext);
+        try {
+            entityBean.unsetEntityContext();
+        } catch (RemoteException e) {
+            throw new EJBException(e);
+        } finally {
+            ThreadContext.setThreadContext(oldCallContext);
+        }
+    }
+
+    private void ejbLoad(EntityBean entityBean) {
+        if (entityBean == null) throw new NullPointerException("entityBean is null");
+
+        ThreadContext callContext = createThreadContext(entityBean);
+        callContext.setCurrentOperation(Operations.OP_LOAD);
+
+        ThreadContext oldCallContext = ThreadContext.getThreadContext();
+        ThreadContext.setThreadContext(callContext);
+        try {
+            entityBean.ejbLoad();
+        } catch (RemoteException e) {
+            throw new EJBException(e);
+        } finally {
+            ThreadContext.setThreadContext(oldCallContext);
+        }
+    }
+
+    private void ejbStore(EntityBean entityBean) {
+        if (entityBean == null) throw new NullPointerException("entityBean is null");
+
+        ThreadContext callContext = createThreadContext(entityBean);
+        callContext.setCurrentOperation(Operations.OP_STORE);
+
+        ThreadContext oldCallContext = ThreadContext.getThreadContext();
+        ThreadContext.setThreadContext(callContext);
+        try {
+            entityBean.ejbStore();
+        } catch (RemoteException e) {
+            throw new EJBException(e);
+        } finally {
+            ThreadContext.setThreadContext(oldCallContext);
+        }
+    }
+
+    private void ejbRemove(EntityBean entityBean) throws RemoveException {
+        if (entityBean == null) throw new NullPointerException("entityBean is null");
+
+        ThreadContext callContext = createThreadContext(entityBean);
+        callContext.setCurrentOperation(Operations.OP_REMOVE);
+
+        ThreadContext oldCallContext = ThreadContext.getThreadContext();
+        ThreadContext.setThreadContext(callContext);
+        try {
+            entityBean.ejbRemove();
+        } catch (RemoteException e) {
+            throw new EJBException(e);
+        } finally {
+            ThreadContext.setThreadContext(oldCallContext);
+        }
+    }
+
+    private void ejbActivate(EntityBean entityBean) {
+        if (entityBean == null) throw new NullPointerException("entityBean is null");
+
+        // activating entity doen't have a primary key
+        CoreDeploymentInfo deployInfo = (CoreDeploymentInfo) getDeploymentInfoByClass(entityBean.getClass());
+
+        ThreadContext callContext = new ThreadContext();
+        callContext.setDeploymentInfo(deployInfo);
+        callContext.setCurrentOperation(Operations.OP_ACTIVATE);
+
+        ThreadContext oldCallContext = ThreadContext.getThreadContext();
+        ThreadContext.setThreadContext(callContext);
+        try {
+            entityBean.ejbActivate();
+        } catch (RemoteException e) {
+            throw new EJBException(e);
+        } finally {
+            ThreadContext.setThreadContext(oldCallContext);
+        }
+    }
+
+    private void ejbPassivate(EntityBean entityBean) {
+        if (entityBean == null) throw new NullPointerException("entityBean is null");
+
+        ThreadContext callContext = createThreadContext(entityBean);
+        callContext.setCurrentOperation(Operations.OP_PASSIVATE);
+
+        ThreadContext oldCallContext = ThreadContext.getThreadContext();
+        ThreadContext.setThreadContext(callContext);
+        try {
+            entityBean.ejbPassivate();
+        } catch (RemoteException e) {
+            throw new EJBException(e);
+        } finally {
+            ThreadContext.setThreadContext(oldCallContext);
+        }
+    }
+
+    private Object businessMethod(Method callMethod, Method runMethod, Object[] args, ThreadContext callContext) throws OpenEJBException {
+        TransactionPolicy txPolicy = callContext.getDeploymentInfo().getTransactionPolicy(callMethod);
+        TransactionContext txContext = new TransactionContext(callContext, transactionManager);
+
+        txPolicy.beforeInvoke(null, txContext);
+
+        EntityBean bean = null;
+        Object returnValue = null;
+        try {
+            bean = (EntityBean) cmpEngine.loadBean(callContext);
+
+            returnValue = runMethod.invoke(bean, args);
+
+        } catch (InvocationTargetException ite) {
+
+            if (ite.getTargetException() instanceof RuntimeException) {
+                /* System Exception ****************************/
+                txPolicy.handleSystemException(ite.getTargetException(), bean, txContext);
+
+            } else {
+                /* Application Exception ***********************/
+                txPolicy.handleApplicationException(ite.getTargetException(), txContext);
+            }
+        } catch (Throwable e) {
+            /* System Exception ****************************/
+            txPolicy.handleSystemException(e, bean, txContext);
+        } finally {
+            txPolicy.afterInvoke(bean, txContext);
+        }
+
+        return returnValue;
+    }
+
+    private ProxyInfo createEJBObject(Method callMethod, Object[] args, ThreadContext callContext) throws OpenEJBException {
+        CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
+
+        EntityBean bean = null;
+        Object primaryKey = null;
+
+        TransactionPolicy txPolicy = callContext.getDeploymentInfo().getTransactionPolicy(callMethod);
+        TransactionContext txContext = new TransactionContext(callContext, transactionManager);
+
+        txPolicy.beforeInvoke(bean, txContext);
+
+        try {
+
+            /*
+              Obtain a bean instance from the method ready pool
+            */
+            bean = createNewInstance(callContext);
+
+            // set the entity context
+            setEntityContext(bean);
+
+            /*
+               Obtain the proper ejbCreate() method
+            */
+            Method ejbCreateMethod = deploymentInfo.getMatchingBeanMethod(callMethod);
+
+            /*
+              Set the context for allowed operations
+            */
+            callContext.setCurrentOperation(Operations.OP_CREATE);
+
+            /*
+              Invoke the proper ejbCreate() method on the instance
+            */
+            ejbCreateMethod.invoke(bean, args);
+
+            // create the new bean
+            primaryKey = cmpEngine.createBean(bean, callContext);
+
+            /*
+              place the primary key into the current ThreadContext so its available for
+              the ejbPostCreate()
+            */
+            callContext.setPrimaryKey(primaryKey);
+
+            /*
+              Set the current operation for the allowed operations check
+            */
+            callContext.setCurrentOperation(Operations.OP_POST_CREATE);
+
+            /*
+              Obtain the ejbPostCreate method that matches the ejbCreate method
+            */
+            Method ejbPostCreateMethod = deploymentInfo.getMatchingPostCreateMethod(ejbCreateMethod);
+
+            /*
+              Invoke the ejbPostCreate method on the bean instance
+            */
+            ejbPostCreateMethod.invoke(bean, args);
+
+            /*
+            According to section 9.1.5.1 of the EJB 1.1 specification, the "ejbPostCreate(...)
+            method executes in the same transaction context as the previous ejbCreate(...) method."
+
+            The bean is first insterted using db.create( ) and then after ejbPostCreate( ) its
+            updated using db.update(). This protocol allows for visablity of the bean after ejbCreate
+            within the current trasnaction.
+            */
+
+            /*
+              Reset the primary key in the ThreadContext to null, its original value
+            */
+            callContext.setPrimaryKey(null);
+
+        } catch (InvocationTargetException ite) {// handle enterprise bean exceptions
+            if (ite.getTargetException() instanceof RuntimeException) {
+                /* System Exception ****************************/
+                txPolicy.handleSystemException(ite.getTargetException(), bean, txContext);
+            } else {
+                /* Application Exception ***********************/
+                txPolicy.handleApplicationException(ite.getTargetException(), txContext);
+            }
+        } catch (CreateException e) {
+            txPolicy.handleSystemException(e, bean, txContext);
+        } catch (Throwable e) {
+            txPolicy.handleSystemException(e, bean, txContext);
+        } finally {
+            txPolicy.afterInvoke(bean, txContext);
+        }
+
+        Class callingClass = callMethod.getDeclaringClass();
+        Class objectInterface = deploymentInfo.getObjectInterface(callingClass);
+        return new ProxyInfo(deploymentInfo, primaryKey, objectInterface, this);
+    }
+
+    private Object findEJBObject(Method callMethod, Object[] args, ThreadContext callContext) throws OpenEJBException {
+        CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
+
+        // Obtain the query for the called method
+        String queryString = deploymentInfo.getQuery(callMethod);
+
+        // Get the transaction policy assigned to this method
+        TransactionPolicy txPolicy = callContext.getDeploymentInfo().getTransactionPolicy(callMethod);
+        TransactionContext txContext = new TransactionContext(callContext, transactionManager);
+
+        txPolicy.beforeInvoke(null, txContext);
+        try {
+            List<Object> results = cmpEngine.queryBeans(callContext, queryString, callMethod, args);
+
+            KeyGenerator kg = deploymentInfo.getKeyGenerator();
+
+            Class<?> callingClass = callMethod.getDeclaringClass();
+            Class objectInterface = deploymentInfo.getObjectInterface(callingClass);
+
+            /*
+            The following block of code is responsible for returning ProxyInfo object(s) for each
+            matching entity bean found by the query.  If its a multi-value find operation a Vector
+            of ProxyInfo objects will be returned. If its a single-value find operation then a
+            single ProxyInfo object is returned.
+            */
+            if (callMethod.getReturnType() == Collection.class || callMethod.getReturnType() == Enumeration.class) {
+                Vector<ProxyInfo> proxies = new Vector<ProxyInfo>();
+                for (Object value : results) {
+                    EntityBean bean = (EntityBean) value;
+
+                    /*
+                    The KeyGenerator creates a new primary key and populates its fields with the
+                    primary key fields of the bean instance.  Each deployment has its own KeyGenerator.
+                    */
+                    Object primaryKey = kg.getPrimaryKey(bean);
+                    /*   create a new ProxyInfo based on the deployment info and primary key and add it to the vector */
+                    proxies.addElement(new ProxyInfo(deploymentInfo, primaryKey, objectInterface, this));
+                }
+                if (callMethod.getReturnType() == Enumeration.class) {
+                    return new Enumerator(proxies);
+                } else {
+                    return proxies;
+                }
+            } else {
+                if (results.size() != 1) throw new ObjectNotFoundException("A Enteprise bean with deployment_id = " + deploymentInfo.getDeploymentID() + " and primarykey = " + args[0] + " Does not exist");
+
+                // create a new ProxyInfo based on the deployment info and primary key
+                EntityBean bean = (EntityBean) results.get(0);
+                Object primaryKey = kg.getPrimaryKey(bean);
+                return new ProxyInfo(deploymentInfo, primaryKey, objectInterface, this);
+            }
+        } catch (javax.ejb.FinderException fe) {
+            txPolicy.handleApplicationException(fe, txContext);
+        } catch (Throwable e) {// handle reflection exception
+            txPolicy.handleSystemException(e, null, txContext);
+        } finally {
+            txPolicy.afterInvoke(null, txContext);
+        }
+        throw new AssertionError("Should not get here");
+    }
+
+    private void removeEJBObject(Method callMethod, ThreadContext callContext) throws OpenEJBException {
+        EntityBean bean = null;
+        TransactionContext txContext = new TransactionContext(callContext, transactionManager);
+        TransactionPolicy txPolicy = callContext.getDeploymentInfo().getTransactionPolicy(callMethod);
+
+        txPolicy.beforeInvoke(bean, txContext);
+        try {
+            cmpEngine.removeBean(callContext);
+        } catch (Throwable e) {// handle reflection exception
+            txPolicy.handleSystemException(e, bean, txContext);
+        } finally {
+            txPolicy.afterInvoke(bean, txContext);
+        }
+    }
+
+    private class ContainerCmpCallback implements CmpCallback {
+        public void setEntityContext(EntityBean entity) {
+            CmpContainer.this.setEntityContext(entity);
+        }
+
+        public void unsetEntityContext(EntityBean entity) {
+            CmpContainer.this.unsetEntityContext(entity);
+        }
+
+        public void ejbActivate(EntityBean entity) {
+            CmpContainer.this.ejbActivate(entity);
+        }
+
+        public void ejbPassivate(EntityBean entity) {
+            CmpContainer.this.ejbPassivate(entity);
+        }
+
+        public void ejbLoad(EntityBean entity) {
+            CmpContainer.this.ejbLoad(entity);
+        }
+
+        public void ejbStore(EntityBean entity) {
+            CmpContainer.this.ejbStore(entity);
+        }
+
+        public void ejbRemove(EntityBean entity) throws RemoveException {
+            CmpContainer.this.ejbRemove(entity);
+        }
+    }
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngine.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngine.java?view=auto&rev=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngine.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngine.java Sun Dec  3 09:32:06 2006
@@ -0,0 +1,39 @@
+/**
+ *
+ * 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.openejb.core.cmp;
+
+import org.apache.openejb.core.ThreadContext;
+
+import javax.persistence.EntityTransaction;
+import javax.ejb.EntityBean;
+import javax.ejb.CreateException;
+import javax.ejb.FinderException;
+import java.util.List;
+import java.lang.reflect.Method;
+
+public interface CmpEngine {
+    EntityTransaction getTransaction();
+
+    Object createBean(EntityBean entity, ThreadContext callContext) throws CreateException;
+
+    Object loadBean(ThreadContext callContext);
+
+    void removeBean(ThreadContext callContext);
+
+    List<Object> queryBeans(ThreadContext callContext, String queryString, Method callMethod, Object[] args) throws FinderException;
+}

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngineFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngineFactory.java?view=auto&rev=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngineFactory.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpEngineFactory.java Sun Dec  3 09:32:06 2006
@@ -0,0 +1,47 @@
+/**
+ *
+ * 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.openejb.core.cmp;
+
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.OpenEJBException;
+
+import javax.transaction.TransactionManager;
+
+public interface CmpEngineFactory {
+    TransactionManager getTransactionManager();
+
+    void setTransactionManager(TransactionManager transactionManager);
+
+    DeploymentInfo[] getDeploys();
+
+    void setDeploymentInfos(DeploymentInfo[] deploys);
+
+    String getEngine();
+
+    void setEngine(String engine);
+
+    String getConnectorName();
+
+    void setConnectorName(String connectorName);
+
+    CmpCallback getCmpCallback();
+
+    void setCmpCallback(CmpCallback cmpCallback);
+
+    CmpEngine create() throws OpenEJBException;
+}

Copied: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpTxPolicy.java (from r481685, incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEntityTxPolicy.java)
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpTxPolicy.java?view=diff&rev=481832&p1=incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEntityTxPolicy.java&r1=481685&p2=incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpTxPolicy.java&r2=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/containers/castor_cmp11/CastorCmpEntityTxPolicy.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpTxPolicy.java Sun Dec  3 09:32:06 2006
@@ -14,40 +14,40 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.openejb.alt.containers.castor_cmp11;
+package org.apache.openejb.core.cmp;
 
 import java.rmi.RemoteException;
 
-import org.exolab.castor.jdo.Database;
-import org.exolab.castor.jdo.JDOManager;
 import org.apache.openejb.ApplicationException;
 import org.apache.openejb.core.transaction.TransactionContext;
 import org.apache.openejb.core.transaction.TransactionPolicy;
 import org.apache.openejb.core.transaction.TransactionContainer;
 import org.apache.openejb.core.RpcContainerWrapper;
 
-public class CastorCmpEntityTxPolicy extends org.apache.openejb.core.transaction.TransactionPolicy {
+import javax.persistence.EntityTransaction;
+
+public class CmpTxPolicy extends org.apache.openejb.core.transaction.TransactionPolicy {
 
     protected TransactionPolicy policy;
 
-    protected final JDOManager jdo_ForLocalTransaction;
+    protected final CmpEngine cmpEngine;
 
-    public CastorCmpEntityTxPolicy(TransactionPolicy policy) {
+    public CmpTxPolicy(TransactionPolicy policy) {
         this.policy = policy;
         this.container = policy.getContainer();
         this.policyType = policy.policyType;
 
-        LocalCastorContainer cmpContainer = getCastorContainer(container);
+        CmpContainer cmpContainer = getCmpContainer(container);
 
-        this.jdo_ForLocalTransaction = cmpContainer.getLocalTxJDO();
+        cmpEngine = cmpContainer.getCmpEngine();
     }
 
-    private LocalCastorContainer getCastorContainer(TransactionContainer container) {
+    private CmpContainer getCmpContainer(TransactionContainer container) {
         if (container instanceof RpcContainerWrapper) {
             RpcContainerWrapper wrapper = (RpcContainerWrapper) container;
-            return getCastorContainer((TransactionContainer) wrapper.getContainer());
+            return getCmpContainer((TransactionContainer) wrapper.getContainer());
         } else {
-            return (LocalCastorContainer) container;
+            return (CmpContainer) container;
         }
     }
 
@@ -57,35 +57,11 @@
 //        DeploymentInfo deploymentInfo = context.callContext.getDeploymentInfo();
 //        ClassLoader classLoader = deploymentInfo.getBeanClass().getClassLoader();
 
-        Database db = null;
         try {
             if (context.currentTx == null) {
-                /*
-                * No current transaciton means that a local transaciton is required which 
-                * must be executed on Database object aquired from a JDO object that was not
-                * initated with a transaction manager name.
-                */
-                db = jdo_ForLocalTransaction.getDatabase();
-
-                /*
-                * The fact that there is no transaction following the processing of the wrapped
-                * TransactionPolicy's beforeInvoke( ) method indicates that the request must 
-                * execute in a Castor local transaction.  To get that local transacion started 
-                * the begin() method is invoked. The local transaction will be committed by the
-                * afterInoke() method of this class or rolled back by the handleSystemException() 
-                * or handleApplicationException() methods.
-                */
-                db.begin();
-
-                /* 
-                * Places a non-transaction managed database object into the unspecified field 
-                * of the current transaction context. This will be used later by the 
-                * getDatabase( ) method of this class to provide the correct database object. 
-                * Its also used by the afterInovoke() method to commit the local transaction 
-                * and the handleSystemException() and handleApplicationException method to 
-                * rollback the Castor's local transaction.
-                */
-                context.callContext.setUnspecified(db);
+                EntityTransaction entityTransaction = cmpEngine.getTransaction();
+                entityTransaction.begin();
+                context.callContext.setUnspecified(entityTransaction);
             } else {
                 /*
                 * If there is a transaction, that means that context is transaction-managed so
@@ -95,16 +71,8 @@
                 */
                 context.callContext.setUnspecified(null);
             }
-        } catch (org.exolab.castor.jdo.DatabaseNotFoundException e) {
-            RemoteException re = new RemoteException("Castor JDO DatabaseNotFoundException thrown when attempting to begin a local transaciton", e);
-            handleSystemException(re, instance, context);
-
-        } catch (org.exolab.castor.jdo.PersistenceException e) {
-            RemoteException re = new RemoteException("Castor JDO PersistenceException thrown when attempting to begin local transaciton", e);
-            handleSystemException(re, instance, context);
-
         } catch (Throwable e) {
-            RemoteException re = new RemoteException("Encountered and unkown error in Castor JDO when attempting to begin local transaciton", e);
+            RemoteException re = new RemoteException("Encountered and unkown error when attempting to begin local transaciton", e);
             handleSystemException(re, instance, context);
         }
     }
@@ -112,19 +80,16 @@
     public void afterInvoke(Object instance, TransactionContext context) throws org.apache.openejb.ApplicationException, org.apache.openejb.SystemException {
         try {
             if (context.currentTx == null) {
-                Database db = (Database) context.callContext.getUnspecified();
-                if (db != null && db.isActive()) {
-                    db.commit();
+                EntityTransaction entityTransaction = (EntityTransaction) context.callContext.getUnspecified();
+                if (entityTransaction != null && entityTransaction.isActive()) {
+                    entityTransaction.commit();
                 }
             }
-        } catch (org.exolab.castor.jdo.TransactionAbortedException e) {
-            RemoteException ex = new RemoteException("Castor JDO threw a JDO TransactionAbortedException while attempting to commit a local transaciton", e);
+        } catch (javax.persistence.RollbackException e) {
+            RemoteException ex = new RemoteException("Local transaction was rolled back", e);
             policy.handleApplicationException(ex, context);
-        } catch (org.exolab.castor.jdo.TransactionNotInProgressException e) {
-            RemoteException ex = new RemoteException("Transaction managment problem with Castor JDO, a transaction should be in progress, but this is not the case.", e);
-            policy.handleSystemException(ex, instance, context);
         } catch (Throwable e) {
-            RemoteException ex = new RemoteException("Encountered and unknown exception while attempting to commit the local castor database transaction", e);
+            RemoteException ex = new RemoteException("Encountered and unknown exception while attempting to commit the local transaction", e);
             policy.handleSystemException(ex, instance, context);
         } finally {
             policy.afterInvoke(instance, context);
@@ -134,11 +99,14 @@
     public void handleApplicationException(Throwable appException, TransactionContext context) throws ApplicationException {
         try {
             if (context.currentTx == null) {
-                Database db = (Database) context.callContext.getUnspecified();
-                db.rollback();
+                EntityTransaction entityTransaction = (EntityTransaction) context.callContext.getUnspecified();
+                if (entityTransaction != null && entityTransaction.isActive()) {
+                    entityTransaction.rollback();
+                }
             }
-        } catch (org.exolab.castor.jdo.TransactionNotInProgressException tnipe) {
-
+        } catch (IllegalStateException ignored) {
+        } catch (javax.persistence.PersistenceException e) {
+            logger.debug("Exception while rolling back local transaction", e);
         } finally {
             policy.handleApplicationException(appException, context);
         }
@@ -147,11 +115,14 @@
     public void handleSystemException(Throwable sysException, Object instance, TransactionContext context) throws org.apache.openejb.ApplicationException, org.apache.openejb.SystemException {
         try {
             if (context.currentTx == null) {
-                Database db = (Database) context.callContext.getUnspecified();
-                db.rollback();
+                EntityTransaction entityTransaction = (EntityTransaction) context.callContext.getUnspecified();
+                if (entityTransaction != null && entityTransaction.isActive()) {
+                    entityTransaction.rollback();
+                }
             }
-        } catch (org.exolab.castor.jdo.TransactionNotInProgressException tnipe) {
-
+        } catch (IllegalStateException ignored) {
+        } catch (javax.persistence.PersistenceException e) {
+            logger.debug("Exception while rolling back local transaction", e);
         } finally {
             policy.handleSystemException(sysException, instance, context);
         }

Propchange: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpTxPolicy.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpTxPolicy.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author Id Revision HeadURL

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml?view=diff&rev=481832&r1=481831&r2=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml Sun Dec  3 09:32:06 2006
@@ -50,8 +50,10 @@
   -->
   <ServiceProvider id="Default CMP Container"
                    provider-type="Container"
-                   constructor="id, transactionManager, securityService, deployments, Engine, ConnectorName"
-                   class-name="org.apache.openejb.alt.containers.castor_cmp11.CastorCMP11_EntityContainer">
+                   constructor="id, transactionManager, securityService, deployments, CmpEngineFactory, Engine, ConnectorName"
+                   class-name="org.apache.openejb.core.cmp.CmpContainer">
+
+    CmpEngineFactory org.apache.openejb.alt.containers.castor_cmp11.CastorCmpEngineFactory
 
     #Engine  derby
     Engine  instantdb

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring.xml?view=diff&rev=481832&r1=481831&r2=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring.xml Sun Dec  3 09:32:06 2006
@@ -75,9 +75,11 @@
     </o:urls>
   </o:urlClassLoader>
 
-  <o:castorCmp11Container id="Default CMP Container" depends-on="jndiBinding">
+  <o:cmpContainer id="Default CMP Container" depends-on="jndiBinding">
     id=Default CMP Container
 
+    cmpEngineFactory org.apache.openejb.alt.containers.castor_cmp11.CastorCmpEngineFactory
+
     #engine derby
     engine instantdb
 
@@ -86,7 +88,7 @@
     transactionManager #transactionManager
     securityService #securityService
     registry #cmpDeployments
-  </o:castorCmp11Container>
+  </o:cmpContainer>
 
   <!--
   # ==========================================================

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring2.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring2.xml?view=diff&rev=481832&r1=481831&r2=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring2.xml (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/spring2.xml Sun Dec  3 09:32:06 2006
@@ -72,9 +72,11 @@
     </o:urls>
   </o:urlClassLoader>
 
-  <o:castorCmp11Container id="Default CMP Container" depends-on="jndiBinding">
+  <o:cmpContainer id="Default CMP Container" depends-on="jndiBinding">
     id=Default CMP Container
 
+    cmpEngineFactory org.apache.openejb.alt.containers.castor_cmp11.CastorCmpEngineFactory
+
     #engine derby
     engine instantdb
 
@@ -85,7 +87,7 @@
     <o:registry>
       <o:addDeployments from="#deployments1" to="Default CMP Container"/>
     </o:registry>
-  </o:castorCmp11Container>
+  </o:cmpContainer>
 
   <!--
   # ==========================================================

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf?view=diff&rev=481832&r1=481831&r2=481832
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/resources/default.openejb.conf Sun Dec  3 09:32:06 2006
@@ -23,6 +23,8 @@
 <openejb>
 
 <Container id="Default CMP Container" ctype="CMP_ENTITY">
+    CmpEngineFactory org.apache.openejb.alt.containers.castor_cmp11.CastorCmpEngineFactory
+
     #Engine  instantdb
     Engine  derby