You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by je...@apache.org on 2010/05/02 19:03:00 UTC

svn commit: r940263 [11/16] - in /ode/trunk: ./ axis2-war/ axis2-war/src/main/assembly/ axis2-war/src/main/webapp/WEB-INF/conf.hib-derby/ axis2-war/src/main/webapp/WEB-INF/conf.jpa-derby/ axis2-war/src/main/webapp/WEB-INF/conf/ axis2-war/src/test/java/...

Added: ode/trunk/dao-jpa-ojpa/src/main/java/org/apache/ode/dao/jpa/openjpa/JpaTxMgrProvider.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa-ojpa/src/main/java/org/apache/ode/dao/jpa/openjpa/JpaTxMgrProvider.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa-ojpa/src/main/java/org/apache/ode/dao/jpa/openjpa/JpaTxMgrProvider.java (added)
+++ ode/trunk/dao-jpa-ojpa/src/main/java/org/apache/ode/dao/jpa/openjpa/JpaTxMgrProvider.java Sun May  2 17:02:51 2010
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa.openjpa;
+
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.apache.openjpa.ee.ManagedRuntime;
+import org.apache.openjpa.util.GeneralException;
+
+public class JpaTxMgrProvider implements ManagedRuntime {
+	private TransactionManager _txMgr;
+	
+    public JpaTxMgrProvider(TransactionManager txMgr) {
+    	_txMgr = txMgr;
+    }
+    
+    public TransactionManager getTransactionManager() throws Exception {
+        return _txMgr;
+    }
+    
+    public void setRollbackOnly(Throwable cause) throws Exception {
+        // there is no generic support for setting the rollback cause
+        getTransactionManager().getTransaction().setRollbackOnly();
+    }
+    
+    public Throwable getRollbackCause() throws Exception {
+        // there is no generic support for setting the rollback cause
+        return null;
+    }
+    
+    public Object getTransactionKey() throws Exception, SystemException {
+        return _txMgr.getTransaction();
+    }
+    
+    public void doNonTransactionalWork(java.lang.Runnable runnable) throws NotSupportedException {
+        TransactionManager tm = null;
+        Transaction transaction = null;
+        
+        try { 
+            tm = getTransactionManager(); 
+            transaction = tm.suspend();
+        } catch (Exception e) {
+            NotSupportedException nse =
+                new NotSupportedException(e.getMessage());
+            nse.initCause(e);
+            throw nse;
+        }
+        
+        runnable.run();
+        
+        try {
+            tm.resume(transaction);
+        } catch (Exception e) {
+            try {
+                transaction.setRollbackOnly();
+            }
+            catch(SystemException se2) {
+                throw new GeneralException(se2);
+            }
+            NotSupportedException nse =
+                new NotSupportedException(e.getMessage());
+            nse.initCause(e);
+            throw nse;
+        } 
+    }
+}
\ No newline at end of file

Added: ode/trunk/dao-jpa-ojpa/src/main/java/org/apache/ode/dao/jpa/openjpa/SchedulerDAOConnectionFactoryImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa-ojpa/src/main/java/org/apache/ode/dao/jpa/openjpa/SchedulerDAOConnectionFactoryImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa-ojpa/src/main/java/org/apache/ode/dao/jpa/openjpa/SchedulerDAOConnectionFactoryImpl.java (added)
+++ ode/trunk/dao-jpa-ojpa/src/main/java/org/apache/ode/dao/jpa/openjpa/SchedulerDAOConnectionFactoryImpl.java Sun May  2 17:02:51 2010
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.jpa.openjpa;
+
+import java.util.Map;
+import java.util.Properties;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+import org.apache.ode.dao.jpa.scheduler.SchedulerDAOConnectionImpl;
+import org.apache.ode.dao.scheduler.SchedulerDAOConnection;
+import org.apache.ode.dao.scheduler.SchedulerDAOConnectionFactory;
+import org.apache.ode.il.config.OdeConfigProperties;
+import static org.apache.ode.dao.jpa.openjpa.BpelDAOConnectionFactoryImpl.buildConfig;
+import static org.apache.ode.dao.jpa.openjpa.BpelDAOConnectionFactoryImpl._operator;
+
+public class SchedulerDAOConnectionFactoryImpl implements SchedulerDAOConnectionFactory {
+
+    EntityManagerFactory _emf;
+    TransactionManager _txm;
+    DataSource _ds;
+
+    public void init(Properties odeConfig, TransactionManager txm, Object env) {
+        this._txm = txm;
+        this._ds = (DataSource) env;
+        Map emfProperties = buildConfig(OdeConfigProperties.PROP_DAOCF_STORE + ".", odeConfig, _txm, _ds);
+        _emf = Persistence.createEntityManagerFactory("ode-scheduler", emfProperties);
+
+    }
+
+    public SchedulerDAOConnection getConnection() {
+        final ThreadLocal<SchedulerDAOConnectionImpl> currentConnection = SchedulerDAOConnectionImpl.getThreadLocal();
+        SchedulerDAOConnectionImpl conn = (SchedulerDAOConnectionImpl) currentConnection.get();
+        if (conn != null && !conn.isClosed()) {
+            return conn;
+        } else {
+            EntityManager em = _emf.createEntityManager();
+            conn = new SchedulerDAOConnectionImpl(em, _txm, _operator);
+            currentConnection.set(conn);
+            return conn;
+        }
+    }
+
+    public void shutdown() {
+        _emf.close();
+    }
+}

Added: ode/trunk/dao-jpa-ojpa/src/main/scripts/license-header.sql
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa-ojpa/src/main/scripts/license-header.sql?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa-ojpa/src/main/scripts/license-header.sql (added)
+++ ode/trunk/dao-jpa-ojpa/src/main/scripts/license-header.sql Sun May  2 17:02:51 2010
@@ -0,0 +1,19 @@
+--
+-- 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.
+--
+ 

Added: ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-derby.sql
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-derby.sql?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-derby.sql (added)
+++ ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-derby.sql Sun May  2 17:02:51 2010
@@ -0,0 +1,30 @@
+-- Apache ODE - SimpleScheduler Database Schema
+-- 
+-- Apache Derby scripts by Maciej Szefler.
+-- 
+-- 
+
+CREATE TABLE ode_job (
+  jobid CHAR(64)  NOT NULL DEFAULT '',
+  ts BIGINT  NOT NULL DEFAULT 0,
+  nodeid char(64),
+  scheduled int  NOT NULL DEFAULT 0,
+  transacted int  NOT NULL DEFAULT 0,
+
+  instanceId BIGINT,
+  mexId varchar(255),
+  processId varchar(255),
+  type varchar(255),
+  channel varchar(255),
+  correlatorId varchar(255),
+  correlationKey varchar(255),
+  retryCount int,
+  inMem int,
+  detailsExt blob(4096),
+
+  PRIMARY KEY(jobid));
+
+CREATE INDEX IDX_ODE_JOB_TS ON ode_job(ts);
+CREATE INDEX IDX_ODE_JOB_NODEID ON ode_job(nodeid);
+
+

Added: ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-mysql.sql
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-mysql.sql?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-mysql.sql (added)
+++ ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-mysql.sql Sun May  2 17:02:51 2010
@@ -0,0 +1,33 @@
+-- Apache ODE - SimpleScheduler Database Schema
+-- 
+-- MySQL scripts by Maciej Szefler.
+-- 
+-- 
+DROP TABLE IF EXISTS ODE_JOB;
+
+CREATE TABLE ODE_JOB (
+  jobid CHAR(64)  NOT NULL DEFAULT '',
+  ts BIGINT  NOT NULL DEFAULT 0,
+  nodeid char(64)  NULL,
+  scheduled int  NOT NULL DEFAULT 0,
+  transacted int  NOT NULL DEFAULT 0,
+
+  instanceId BIGINT,
+  mexId varchar(255),
+  processId varchar(255),
+  type varchar(255),
+  channel varchar(255),
+  correlatorId varchar(255),
+  correlationKey varchar(255),
+  retryCount int,
+  inMem int,
+  detailsExt blob(4096),
+
+  PRIMARY KEY(jobid),
+  INDEX IDX_ODE_JOB_TS(ts),
+  INDEX IDX_ODE_JOB_NODEID(nodeid)
+)
+TYPE=InnoDB;
+
+COMMIT;
+

Added: ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-oracle.sql
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-oracle.sql?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-oracle.sql (added)
+++ ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-oracle.sql Sun May  2 17:02:51 2010
@@ -0,0 +1,32 @@
+-- Apache ODE - SimpleScheduler Database Schema
+-- 
+-- Apache Derby scripts by Maciej Szefler.
+-- 
+-- 
+
+DROP TABLE ode_job;
+
+CREATE TABLE ode_job (
+  jobid VARCHAR(64)  NOT NULL,
+  ts number(37)  NOT NULL,
+  nodeid varchar(64),
+  scheduled int  NOT NULL,
+  transacted int  NOT NULL,
+  
+  instanceId number(37),
+  mexId varchar(255),
+  processId varchar(255),
+  type varchar(255),
+  channel varchar(255),
+  correlatorId varchar(255),
+  correlationKey varchar(255),
+  retryCount int,
+  inMem int,
+  detailsExt blob,
+
+  PRIMARY KEY(jobid));
+
+CREATE INDEX IDX_ODE_JOB_TS ON ode_job(ts);
+CREATE INDEX IDX_ODE_JOB_NODEID ON ode_job(nodeid);
+
+

Added: ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-postgres.sql
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-postgres.sql?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-postgres.sql (added)
+++ ode/trunk/dao-jpa-ojpa/src/main/scripts/simplesched-postgres.sql Sun May  2 17:02:51 2010
@@ -0,0 +1,30 @@
+-- Apache ODE - SimpleScheduler Database Schema
+-- 
+-- Apache Derby scripts by Maciej Szefler.
+-- 
+-- 
+
+CREATE TABLE ode_job (
+  jobid CHAR(64)  NOT NULL DEFAULT '',
+  ts BIGINT  NOT NULL DEFAULT 0,
+  nodeid char(64),
+  scheduled int  NOT NULL DEFAULT 0,
+  transacted int  NOT NULL DEFAULT 0,
+
+  instanceId BIGINT,
+  mexId varchar(255),
+  processId varchar(255),
+  type varchar(255),
+  channel varchar(255),
+  correlatorId varchar(255),
+  correlationKey varchar(255),
+  retryCount int,
+  inMem int,
+  detailsExt bytea,
+
+  PRIMARY KEY(jobid));
+
+CREATE INDEX IDX_ODE_JOB_TS ON ode_job(ts);
+CREATE INDEX IDX_ODE_JOB_NODEID ON ode_job(nodeid);
+
+

Modified: ode/trunk/dao-jpa/pom.xml
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/pom.xml?rev=940263&r1=940262&r2=940263&view=diff
==============================================================================
--- ode/trunk/dao-jpa/pom.xml (original)
+++ ode/trunk/dao-jpa/pom.xml Sun May  2 17:02:51 2010
@@ -16,12 +16,12 @@
   ~ KIND, either express or implied.  See the License for the
   ~ specific language governing permissions and limitations
   ~ under the License.
-  -->
+-->
 <project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.ode</groupId>
   <artifactId>ode-dao-jpa</artifactId>
-  <name>ODE :: OpenJPA DAO Impl</name>
+  <name>ODE :: JPA DAO</name>
 
   <parent>
     <groupId>org.apache.ode</groupId>
@@ -37,10 +37,6 @@
     </dependency>
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
-      <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-jta_1.1_spec</artifactId>
     </dependency>
     <dependency>
@@ -52,10 +48,6 @@
       <artifactId>commons-logging</artifactId>
     </dependency>
     <dependency>
-      <groupId>commons-collections</groupId>
-      <artifactId>commons-collections</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.apache.ode</groupId>
       <artifactId>ode-bpel-api</artifactId>
     </dependency>
@@ -64,26 +56,19 @@
       <artifactId>ode-bpel-dao</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.ode</groupId>
-      <artifactId>ode-utils</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>xerces</groupId>
-      <artifactId>xercesImpl</artifactId>
-    </dependency>
-    <dependency>
-        <groupId>xerces</groupId>
-        <artifactId>xmlParserAPIs</artifactId>
+       <groupId>org.apache.ode</groupId>
+       <artifactId>ode-il-common</artifactId>
     </dependency>
+
+    <!-- we can't add this as a plugin dependency since OpenJPA needs to be loaded
+    in the same class loader as the persistence.xml. (see ant faq "ignores my classpath" -->
     <dependency>
       <groupId>org.apache.openjpa</groupId>
       <artifactId>openjpa</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>net.sourceforge.serp</groupId>
-      <artifactId>serp</artifactId>
+      <scope>provided</scope>
     </dependency>
   </dependencies>
+  
 
   <build>
     <plugins>
@@ -98,27 +83,46 @@
             </goals>
             <configuration>
               <tasks>
-                <property name="maven.runtime.classpath" refid="maven.compile.classpath"/>
+                <copy todir="${basedir}/target/classes-openjpa">
+                  <fileset dir="${basedir}/target/classes" includes="**/*"/>
+                </copy>
+                <property name="maven.compile.classpath" refid="maven.compile.classpath"/>
                 <path id="classpath">
-		   <pathelement path="${maven.runtime.classpath}"/>
-		</path>
-		<taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask" classpathref="classpath"/>
-                <openjpac>
-		    <fileset dir="${basedir}/src/main">
-		      <include name="**/*.java" />
-		    </fileset>
-		    <classpath>
-		     <pathelement location="${basedir}/target/classes"/>
-		     <pathelement path="${maven.runtime.classpath}"/>
-		    </classpath>
-		 </openjpac>
+                  <pathelement location="${basedir}/target/classes-openjpa"/>
+                  <pathelement path="${maven.compile.classpath}"/>
+                </path>
+                <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask" classpathref="classpath"/>
+                <openjpac directory="${basedir}/target/classes-openjpa">
+                  <fileset dir="${basedir}/src/main">
+                    <include name="**/*.java" />                    
+                  </fileset>
+                  <classpath refid="classpath"/>
+                </openjpac>
               </tasks>
             </configuration>
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>openjpa-enhancer-package</id>
+            <phase>package</phase>
+            <configuration>
+              <classifier>openjpa</classifier>
+              <classesDirectory>${project.build.directory}/classes-openjpa</classesDirectory>
+            </configuration>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
-   </build>
-  
+  </build>
 
 </project>
+

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/JpaConnection.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/JpaConnection.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/JpaConnection.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/JpaConnection.java Sun May  2 17:02:51 2010
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.jpa;
+
+import javax.persistence.EntityManager;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.dao.DAOConnection;
+
+public class JpaConnection implements DAOConnection {
+
+    private static final Log __log = LogFactory.getLog(JpaConnection.class);
+    final protected EntityManager _em;
+    final protected TransactionManager _mgr;
+    final protected JpaTxContext _txCtx;
+    final protected JpaOperator _operator;
+
+    public JpaConnection(EntityManager em, TransactionManager mgr, JpaOperator operator) {
+        _em = em;
+        _mgr = mgr;
+        if (mgr != null) {
+            _txCtx = new JpaJtaContext();
+        } else {
+            _txCtx = new JpaNonTxContext();
+        }
+        _operator = operator;
+    }
+
+    public EntityManager getEntityManager() {
+        return _em;
+    }
+
+    public JpaOperator getJPADaoOperator() {
+        return _operator;
+    }
+
+    public void close() {
+        /* Connections are stored in thread locals so only destroying the factory
+         * should close the connection
+        _em.close();
+        _em = null;
+        _mgr = null;
+         */
+    }
+
+    public boolean isClosed() {
+        return _em == null ? true : !_em.isOpen();
+    }
+
+    /** Clear out the entity manager after a commit so no stale entites are
+     *  preserved across transactions and all JPA operations pull data directly from
+     *  the DB.
+     *
+     */
+    public void clearOnComplete() {
+        try {
+            _mgr.getTransaction().registerSynchronization(new Synchronization() {
+
+                public void afterCompletion(int i) {
+                    _em.clear();
+                }
+
+                public void beforeCompletion() {
+                }
+            });
+        } catch (Exception e) {
+            __log.error("Error adding commit synchronizer", e);
+        }
+    }
+
+    protected interface JpaTxContext {
+
+        public void begin();
+
+        public void commit();
+
+        public void rollback();
+    }
+
+    class JpaJtaContext implements JpaTxContext {
+
+        /**
+         * Due to the way ODE re-uses connection on ThreadLocals it could be possible
+         * for the JPA EntityManager to not be created on the current JTA transaction
+         * and threfore it must by manually bound to the current transaction.
+         */
+        public void begin() {
+            try {
+                if (_mgr.getStatus() == Status.STATUS_ACTIVE) {
+                    _em.joinTransaction();
+                    clearOnComplete();
+                }
+            } catch (SystemException se) {
+                __log.error(se);
+            }
+        }
+
+        public void commit() {
+        }
+
+        public void rollback() {
+            try {
+                if (_mgr.getStatus() == Status.STATUS_ACTIVE) {
+                    _mgr.setRollbackOnly();
+                }
+            } catch (Exception ex) {
+                __log.error("Unable to set rollbackOnly", ex);
+            }
+        }
+    }
+
+    class JpaNonTxContext implements JpaTxContext {
+
+        public void begin() {
+            _em.getTransaction().begin();
+        }
+
+        public void commit() {
+            _em.getTransaction().commit();
+            _em.clear();
+        }
+
+        public void rollback() {
+            _em.getTransaction().rollback();
+            _em.clear();
+        }
+    }
+}

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/JpaOperator.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/JpaOperator.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/JpaOperator.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/JpaOperator.java Sun May  2 17:02:51 2010
@@ -0,0 +1,20 @@
+package org.apache.ode.dao.jpa;
+
+import java.util.Iterator;
+
+import javax.persistence.Query;
+
+/**
+ * this is interface that will include the methods that will be used in JPA DAO,
+ * But the implementation should be different from various JPA vendor, like OpenJPA, Hibernate etc.
+ * 
+ * @author Jeff Yu
+ *
+ */
+public interface JpaOperator {
+	
+	public <T> void batchUpdateByIds(Iterator<T> ids, Query query, String parameterName);
+	
+	public void setBatchSize(Query query, int limit);
+
+}
\ No newline at end of file

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/ActivityRecoveryDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/ActivityRecoveryDAOImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/ActivityRecoveryDAOImpl.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/ActivityRecoveryDAOImpl.java Sun May  2 17:02:51 2010
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa.bpel;
+
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.ode.dao.bpel.ActivityRecoveryDAO;
+import org.apache.ode.utils.DOMUtils;
+import org.w3c.dom.Element;
+
+
+@Entity
+@Table(name="ODE_ACTIVITY_RECOVERY")
+@NamedQueries({
+ 	@NamedQuery(name=ActivityRecoveryDAOImpl.DELETE_ACTIVITY_RECOVERIES_BY_IDS, query="delete from ActivityRecoveryDAOImpl as a where a._instanceId in(:ids)"),
+	@NamedQuery(name=ActivityRecoveryDAOImpl.COUNT_ACTIVITY_RECOVERIES_BY_INSTANCES,
+			query="select r._instanceId, count(r._id) from ActivityRecoveryDAOImpl r where r._instance in(:instances) group by r._instanceId")
+})
+public class ActivityRecoveryDAOImpl implements ActivityRecoveryDAO, Serializable {
+ 	public final static String DELETE_ACTIVITY_RECOVERIES_BY_IDS = "DELETE_ACTIVITY_RECOVERIES_BY_IDS";
+
+	public final static String COUNT_ACTIVITY_RECOVERIES_BY_INSTANCES = "COUNT_ACTIVITY_RECOVERIES_BY_INSTANCES";
+
+    @Id @Column(name="ID")
+    @GeneratedValue(strategy= GenerationType.AUTO)
+    private Long _id;
+
+	@Basic @Column(name="ACTIVITY_ID")
+    private long _activityId;
+	@Basic @Column(name="CHANNEL")
+    private String _channel;
+	@Basic @Column(name="REASON")
+    private String _reason;
+	@Basic @Column(name="DATE_TIME")
+    @Temporal(TemporalType.DATE)
+    private Date _dateTime;
+	@Lob @Column(name="DETAILS")
+    private String _details;
+	@Basic @Column(name="ACTIONS")
+    private String _actions;
+	@Basic @Column(name="RETRIES")
+    private int _retries;
+
+ 	@SuppressWarnings("unused")
+ 	@Basic @Column(name="INSTANCE_ID", insertable=false, updatable=false, nullable=true)
+     private Long _instanceId;
+
+ 	// _instances is unused because this is a one-way relationship at the database level
+    @SuppressWarnings("unused")
+    @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST}) @JoinColumn(name="INSTANCE_ID")
+    private ProcessInstanceDAOImpl _instance;
+
+	
+    public ActivityRecoveryDAOImpl() {}
+	public ActivityRecoveryDAOImpl(String channel, long activityId,
+			String reason, Date dateTime, Element data, String[] actions,
+			int retries) {
+		_channel = channel;
+		_activityId = activityId;
+		_reason = reason;
+		_dateTime = dateTime;
+
+        if (data != null) _details = DOMUtils.domToString(data);
+		
+        String alist = actions[0];
+        for (int i = 1; i < actions.length; ++i)
+            alist += " " + actions[i];
+		_actions = alist;
+		
+		_retries = retries;		
+	}
+	
+	public String getActions() {
+		return _actions;
+	}
+
+	public String[] getActionsList() {
+		return getActions().split(" ");
+	}
+
+	public long getActivityId() {
+		return _activityId;
+	}
+
+	public String getChannel() {
+		return _channel;
+	}
+
+	public Date getDateTime() {
+		return _dateTime;
+	}
+
+	public Element getDetails() {
+		Element ret = null;
+		if ( _details != null ) {
+			try {
+				ret = DOMUtils.stringToDOM(_details);
+			} catch (Exception e) {
+				throw new RuntimeException(e);
+			}
+		}
+		return ret;
+	}
+
+	public String getReason() {
+		return _reason;
+	}
+
+	public int getRetries() {
+		return _retries;
+	}
+
+    public ProcessInstanceDAOImpl getInstance() {
+        return _instance;
+    }
+
+    public void setInstance(ProcessInstanceDAOImpl instance) {
+        _instance = instance;
+    }
+}

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/BpelDAO.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/BpelDAO.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/BpelDAO.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/BpelDAO.java Sun May  2 17:02:51 2010
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.jpa.bpel;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.ode.dao.bpel.BpelDAOConnection;
+
+/**
+ * @author Matthieu Riou <mriou at apache dot org>
+ * @author Jeff Yu
+ */
+public class BpelDAO {
+	
+	public BpelDAO() {
+	
+	}
+
+    protected BpelDAOConnection getConn() {
+    	return BpelDAOConnectionImpl.getThreadLocal().get();
+    }
+
+    protected EntityManager getEM() {    	
+    	return BpelDAOConnectionImpl.getThreadLocal().get().getEntityManager();
+    }
+
+    /**
+     * javax.persistence.Query either let you query for a collection or a single
+     * value throwing an exception if nothing is found. Just a convenient shortcut
+     * for single results allowing null values
+     * @param qry query to execute
+     * @return whatever you assign it to
+     */
+    @SuppressWarnings("unchecked")
+    protected <T> T getSingleResult(Query qry) {
+        List res = qry.getResultList();
+        if (res.size() == 0) {
+        	return null;
+        }
+        return (T) res.get(0);
+    }
+    
+    
+    protected <T> void batchUpdateByIds(Iterator<T> ids, Query query, String parameterName) {
+    	BpelDAOConnectionImpl.getThreadLocal().get().getJPADaoOperator().batchUpdateByIds(ids, query, parameterName);
+    }
+}
\ No newline at end of file

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/BpelDAOConnectionImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/BpelDAOConnectionImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/BpelDAOConnectionImpl.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/BpelDAOConnectionImpl.java Sun May  2 17:02:51 2010
@@ -0,0 +1,429 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.jpa.bpel;
+
+import org.apache.ode.bpel.iapi.ProcessConf.CLEANUP_CATEGORY;
+import org.apache.ode.dao.jpa.JpaConnection;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.BpelEventFilter;
+import org.apache.ode.bpel.common.Filter;
+import org.apache.ode.bpel.common.InstanceFilter;
+import org.apache.ode.dao.bpel.*;
+import org.apache.ode.bpel.evt.BpelEvent;
+import org.apache.ode.bpel.evt.ScopeEvent;
+import org.apache.ode.utils.ISO8601DateParser;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.xml.namespace.QName;
+
+import java.io.Serializable;
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.util.*;
+import javax.transaction.TransactionManager;
+import org.apache.ode.dao.jpa.JpaOperator;
+
+/**
+ * @author Matthieu Riou <mriou at apache dot org>
+ */
+public class BpelDAOConnectionImpl extends JpaConnection implements BpelDAOConnection/*, FilteredInstanceDeletable*/ {
+
+    static final Log __log = LogFactory.getLog(BpelDAOConnectionImpl.class);
+    static final ThreadLocal<BpelDAOConnectionImpl> _connections = new ThreadLocal<BpelDAOConnectionImpl>();
+
+    public BpelDAOConnectionImpl(EntityManager mgr, TransactionManager txMgr, JpaOperator operator) {
+        super(mgr, txMgr, operator);
+    }
+
+    public static ThreadLocal<BpelDAOConnectionImpl> getThreadLocal() {
+        return _connections;
+    }
+
+    public List<BpelEvent> bpelEventQuery(InstanceFilter ifilter,
+            BpelEventFilter efilter) {
+        // TODO
+        throw new UnsupportedOperationException();
+    }
+
+    public List<Date> bpelEventTimelineQuery(InstanceFilter ifilter,
+            BpelEventFilter efilter) {
+        // TODO
+        throw new UnsupportedOperationException();
+    }
+
+    public ProcessInstanceDAO getInstance(Long iid) {
+        _txCtx.begin();
+        ProcessInstanceDAO dao = _em.find(ProcessInstanceDAOImpl.class, iid);
+        _txCtx.commit();
+        return dao;
+
+
+    }
+
+    public MessageExchangeDAO createMessageExchange(String mexId, char dir) {
+        _txCtx.begin();
+        MessageExchangeDAOImpl ret = new MessageExchangeDAOImpl(mexId, dir);
+        _em.persist(ret);
+        _txCtx.commit();
+        return ret;
+    }
+
+    public void releaseMessageExchange(String mexid) {
+        _txCtx.begin();
+        MessageExchangeDAO dao = getMessageExchange(mexid);
+        dao.release(true);
+        _txCtx.commit();
+    }
+
+    public ProcessDAO createProcess(QName pid, QName type, String guid, long version) {
+        _txCtx.begin();
+        ProcessDAOImpl ret = new ProcessDAOImpl(pid, type, guid, version);
+        _em.persist(ret);
+        _txCtx.commit();
+        return ret;
+    }
+
+    public ProcessDAO createTransientProcess(Serializable id) {
+        _txCtx.begin();
+        ProcessDAOImpl ret = new ProcessDAOImpl(null, null, null, 0);
+        ret.setId((Long) id);
+        _txCtx.commit();
+        return ret;
+    }
+
+    public ProcessDAO getProcess(QName processId) {
+        _txCtx.begin();
+        List l = _em.createQuery("select x from ProcessDAOImpl x where x._processId = ?1").setParameter(1, processId.toString()).getResultList();
+        _txCtx.commit();
+        if (l.size() == 0) {
+            return null;
+        }
+        return (ProcessDAOImpl) l.get(0);
+    }
+
+    public ScopeDAO getScope(Long siidl) {
+        _txCtx.begin();
+        ScopeDAO dao = _em.find(ScopeDAOImpl.class, siidl);
+        _txCtx.commit();
+        return dao;
+    }
+
+    public void insertBpelEvent(BpelEvent event, ProcessDAO process, ProcessInstanceDAO instance) {
+        _txCtx.begin();
+        EventDAOImpl eventDao = new EventDAOImpl();
+        eventDao.setTstamp(new Timestamp(System.currentTimeMillis()));
+        eventDao.setType(BpelEvent.eventName(event));
+        String evtStr = event.toString();
+        eventDao.setDetail(evtStr.substring(0, Math.min(254, evtStr.length())));
+        if (process != null) {
+            eventDao.setProcess((ProcessDAOImpl) process);
+        }
+        if (instance != null) {
+            eventDao.setInstance((ProcessInstanceDAOImpl) instance);
+        }
+        if (event instanceof ScopeEvent) {
+            eventDao.setScopeId(((ScopeEvent) event).getScopeId());
+        }
+        eventDao.setEvent(event);
+        _em.persist(eventDao);
+        _txCtx.commit();
+    }
+
+    private static String dateFilter(String filter) {
+        String date = Filter.getDateWithoutOp(filter);
+        String op = filter.substring(0, filter.indexOf(date));
+        Date dt;
+        try {
+            dt = ISO8601DateParser.parse(date);
+        } catch (ParseException e) {
+            __log.error("Error parsing date.", e);
+            return "";
+        }
+        Timestamp ts = new Timestamp(dt.getTime());
+        return op + " '" + ts.toString() + "'";
+    }
+
+    @SuppressWarnings("unchecked")
+    public Collection<ProcessInstanceDAO> instanceQuery(InstanceFilter criteria) {
+        _txCtx.begin();
+        StringBuffer query = new StringBuffer();
+        query.append("select pi from ProcessInstanceDAOImpl as pi");
+
+        if (criteria != null) {
+            // Building each clause
+            ArrayList<String> clauses = new ArrayList<String>();
+
+            // iid filter
+            if (criteria.getIidFilter() != null) {
+                StringBuffer filters = new StringBuffer();
+                List<String> iids = criteria.getIidFilter();
+                for (int m = 0; m < iids.size(); m++) {
+                    filters.append(" pi._instanceId = ").append(iids.get(m)).append("");
+                    if (m < iids.size() - 1) {
+                        filters.append(" or");
+                    }
+                }
+                clauses.add(" (" + filters + ")");
+            }
+
+            // pid filter
+            if (criteria.getPidFilter() != null) {
+                StringBuffer filters = new StringBuffer();
+                List<String> pids = criteria.getPidFilter();
+                for (int m = 0; m < pids.size(); m++) {
+                    filters.append(" pi._process._processId = '").append(pids.get(m)).append("'");
+                    if (m < pids.size() - 1) {
+                        filters.append(" or");
+                    }
+                }
+                clauses.add(" (" + filters + ")");
+            }
+
+            // name filter
+            if (criteria.getNameFilter() != null) {
+                String val = criteria.getNameFilter();
+                if (val.endsWith("*")) {
+                    val = (val.substring(0, val.length() - 1).equals("*") ? "" : val.substring(0, val.length() - 1)) + "%";
+                }
+                //process type string begins with name space
+                //this could possibly match more than you want
+                //because the name space and name are stored together 
+                clauses.add(" pi._process._processType like '%" + val + "'");
+            }
+
+            // name space filter
+            if (criteria.getNamespaceFilter() != null) {
+                //process type string begins with name space
+                //this could possibly match more than you want
+                //because the name space and name are stored together
+                clauses.add(" pi._process._processType like '{"
+                        + (criteria.getNamespaceFilter().equals("*") ? "" : criteria.getNamespaceFilter()) + "%'");
+            }
+
+            // started filter
+            if (criteria.getStartedDateFilter() != null) {
+                for (String ds : criteria.getStartedDateFilter()) {
+                    clauses.add(" pi._dateCreated " + dateFilter(ds));
+                }
+            }
+
+            // last-active filter
+            if (criteria.getLastActiveDateFilter() != null) {
+                for (String ds : criteria.getLastActiveDateFilter()) {
+                    clauses.add(" pi._lastActive " + dateFilter(ds));
+                }
+            }
+
+            // status filter
+            if (criteria.getStatusFilter() != null) {
+                StringBuffer filters = new StringBuffer();
+                List<Short> states = criteria.convertFilterState();
+                for (int m = 0; m < states.size(); m++) {
+                    filters.append(" pi._state = ").append(states.get(m));
+                    if (m < states.size() - 1) {
+                        filters.append(" or");
+                    }
+                }
+                clauses.add(" (" + filters.toString() + ")");
+            }
+
+            // $property filter
+            if (criteria.getPropertyValuesFilter() != null) {
+                Map<String, String> props = criteria.getPropertyValuesFilter();
+                // join to correlation sets
+                query.append(" inner join pi._rootScope._correlationSets as cs");
+                int i = 0;
+                for (String propKey : props.keySet()) {
+                    i++;
+                    // join to props for each prop
+                    query.append(" inner join cs._props as csp" + i);
+                    // add clause for prop key and value
+                    clauses.add(" csp" + i + ".propertyKey = '" + propKey
+                            + "' and csp" + i + ".propertyValue = '"
+                            + // spaces have to be escaped, might be better handled in InstanceFilter
+                            props.get(propKey).replaceAll("&#32;", " ") + "'");
+                }
+            }
+
+            // order by
+            StringBuffer orderby = new StringBuffer("");
+            if (criteria.getOrders() != null) {
+                orderby.append(" order by");
+                List<String> orders = criteria.getOrders();
+                for (int m = 0; m < orders.size(); m++) {
+                    String field = orders.get(m);
+                    String ord = " asc";
+                    if (field.startsWith("-")) {
+                        ord = " desc";
+                    }
+                    String fieldName = " pi._instanceId";
+                    if (field.endsWith("name") || field.endsWith("namespace")) {
+                        fieldName = " pi._process._processType";
+                    }
+                    if (field.endsWith("version")) {
+                        fieldName = " pi._process._version";
+                    }
+                    if (field.endsWith("status")) {
+                        fieldName = " pi._state";
+                    }
+                    if (field.endsWith("started")) {
+                        fieldName = " pi._dateCreated";
+                    }
+                    if (field.endsWith("last-active")) {
+                        fieldName = " pi._lastActive";
+                    }
+                    orderby.append(fieldName + ord);
+                    if (m < orders.size() - 1) {
+                        orderby.append(", ");
+                    }
+                }
+
+            }
+
+            // Preparing the statement
+            if (clauses.size() > 0) {
+                query.append(" where");
+                for (int m = 0; m < clauses.size(); m++) {
+                    query.append(clauses.get(m));
+                    if (m < clauses.size() - 1) {
+                        query.append(" and");
+                    }
+                }
+            }
+
+            query.append(orderby);
+        }
+
+        if (__log.isDebugEnabled()) {
+            __log.debug(query.toString());
+        }
+
+        // criteria limit
+        Query pq = _em.createQuery(query.toString());
+        pq.setMaxResults(criteria.getLimit());
+        getJPADaoOperator().setBatchSize(pq, criteria.getLimit());
+        List<ProcessInstanceDAO> ql = pq.getResultList();
+
+        Collection<ProcessInstanceDAO> list = new ArrayList<ProcessInstanceDAO>();
+        int num = 0;
+        for (Object piDAO : ql) {
+            if (num++ > criteria.getLimit()) {
+                break;
+            }
+            ProcessInstanceDAO processInstanceDAO = (ProcessInstanceDAO) piDAO;
+            list.add(processInstanceDAO);
+        }
+        _txCtx.commit();
+        return list;
+    }
+
+    public Collection<ProcessInstanceDAO> instanceQuery(String expression) {
+        _txCtx.begin();
+        return instanceQuery(new InstanceFilter(expression));
+    }
+
+    public MessageExchangeDAO getMessageExchange(String mexid) {
+        _txCtx.begin();
+        List l = _em.createQuery("select x from MessageExchangeDAOImpl x where x._id = ?1").setParameter(1, mexid).getResultList();
+        _txCtx.commit();
+        if (l.size() == 0) {
+            return null;
+        }
+
+        return (MessageExchangeDAOImpl) l.get(0);
+    }
+
+    public ResourceRouteDAO getResourceRoute(String url, String method) {
+        _txCtx.begin();
+        List l = _em.createQuery("select r from ResourceRouteDAOImpl r where r._url = ?1 and r._method = ?2").setParameter(1, url).setParameter(2, method).getResultList();
+        _txCtx.commit();
+        if (l.size() == 0) {
+            return null;
+        }
+        ResourceRouteDAOImpl m = (ResourceRouteDAOImpl) l.get(0);
+        return m;
+    }
+
+    public List<ResourceRouteDAO> getAllResourceRoutes() {
+        _txCtx.begin();
+        List<ResourceRouteDAO> ret = _em.createQuery("select r from ResourceRouteDAOImpl r").getResultList();
+        _txCtx.commit();
+        return ret;
+    }
+
+    public void deleteResourceRoute(String url, String method) {
+        _txCtx.begin();
+        _em.createQuery("delete from ResourceRouteDAOImpl r where r._url = ?1 and r._method = ?2").setParameter(1, url).setParameter(2, method).executeUpdate();
+        _txCtx.commit();
+    }
+
+    public EntityManager getEntityManager() {
+        return _em;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Map<Long, Collection<CorrelationSetDAO>> getCorrelationSets(Collection<ProcessInstanceDAO> instances) {
+        if (instances.size() == 0) {
+            return new HashMap<Long, Collection<CorrelationSetDAO>>();
+        }
+        _txCtx.begin();
+        ArrayList<Long> iids = new ArrayList<Long>(instances.size());
+        for (ProcessInstanceDAO dao : instances) {
+            iids.add(dao.getInstanceId());
+        }
+        Collection<CorrelationSetDAOImpl> csets = _em.createNamedQuery(CorrelationSetDAOImpl.SELECT_CORRELATION_SETS_BY_INSTANCES).setParameter("instances", iids).getResultList();
+        Map<Long, Collection<CorrelationSetDAO>> map = new HashMap<Long, Collection<CorrelationSetDAO>>();
+        for (CorrelationSetDAOImpl cset : csets) {
+            Long id = cset.getScope().getProcessInstance().getInstanceId();
+            Collection<CorrelationSetDAO> existing = map.get(id);
+            if (existing == null) {
+                existing = new ArrayList<CorrelationSetDAO>();
+                map.put(id, existing);
+            }
+            existing.add(cset);
+        }
+        _txCtx.commit();
+        return map;
+    }
+
+    public ProcessManagementDAO getProcessManagement() {
+        return new ProcessManagementDAOImpl(_em);
+    }
+    /** TODO support deleting of instances
+    public int deleteInstances(InstanceFilter criteria, Set<CLEANUP_CATEGORY> categories) {
+    if (criteria.getLimit() == 0) {
+    return 0;
+    }
+
+    List<ProcessInstanceDAO> instances = _instanceQueryForList(getSession(), false, criteria);
+    if (__log.isDebugEnabled()) {
+    __log.debug("Collected " + instances.size() + " instances to delete.");
+    }
+
+    if (!instances.isEmpty()) {
+    ProcessDAOImpl process = (ProcessDAOImpl) createTransientProcess(instances.get(0).getProcess().getProcessId());
+    return process.deleteInstances(instances, categories);
+    }
+
+    return 0;
+    }
+     */
+}

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/ContextValueDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/ContextValueDAOImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/ContextValueDAOImpl.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/ContextValueDAOImpl.java Sun May  2 17:02:51 2010
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.jpa.bpel;
+
+import java.io.Serializable;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+
+import org.apache.ode.dao.bpel.ContextValueDAO;
+
+@Entity
+@Table(name="ODE_CONTEXT_VALUE")
+@NamedQueries({
+    @NamedQuery(name=ContextValueDAOImpl.DELETE_CONTEXT_VALUES_BY_KEYS, query="delete from ContextValueDAOImpl as l where l._key = :key and l._namespace = :namespace")
+})
+
+public class ContextValueDAOImpl extends BpelDAO implements ContextValueDAO, Serializable {
+	public static final String DELETE_CONTEXT_VALUES_BY_KEYS = "DELETE_CONTEXT_VALUES_BY_KEYS";
+	
+    @Id @Column(name="CONTEXT_VALUE_ID") 
+    @GeneratedValue(strategy=GenerationType.AUTO)
+    @SuppressWarnings("unused")
+    private Long _id;
+
+    @Basic @Column(name="NAMESPACE")
+    //TODO: can we move this specific annotation into XML property??
+    //@Index(name="IDX_CTX_NS", enabled=true, unique=false)
+    private String _namespace;
+
+    @Basic @Column(name="KEY_NAME")
+    //TODO: can we move this specific annotation into XML property??
+    //@Index(name="IDX_CTX_KEY", enabled=true, unique=false)
+    private String _key;
+
+    @Lob @Column(name="DATA")
+    private String _data;
+    
+    @Basic @Column(name="VALUE")
+    //TODO: can we move this specific annotation into XML property??
+    //@Index(name="IDX_CTX_VAL", enabled=true, unique=false)
+    private String _value;
+    
+//    @Basic @Column(name="PARTNER_LINK_ID", nullable=true, insertable=false, updatable=false)
+//    @SuppressWarnings("unused")
+//    private Long _partnerLinkId;
+
+    @SuppressWarnings("unused")
+    @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST}) 
+    @JoinColumn(name="PLINK")
+    private PartnerLinkDAOImpl _partnerLink;
+
+
+    public ContextValueDAOImpl() {}
+    public ContextValueDAOImpl(PartnerLinkDAOImpl partnerLink, String namespace, String key){
+        _partnerLink = partnerLink;
+        _namespace = namespace;
+        _key = key;
+    }
+
+    public String getKey() {
+        return _key;
+    }
+
+    public String getValue() {
+        if (_value != null) {
+            return _value;
+        }
+        
+        if (_data != null) {
+            return _data;
+        }
+        
+        return null;
+    }
+
+    public void setValue(String value) {
+        // store large data in the clob, small data indexable in a varchar
+        if (value.length() <= 250) {
+            _value = value;
+            _data = null;
+        } else {
+            _value = null;
+            _data = value;
+        }
+    }
+
+	public String getNamespace() {
+		return _namespace;
+	}
+
+	public void setKey(String key) {
+		_key = key;
+	}
+
+	public void setNamespace(String namespace) {
+		_namespace = namespace;
+	}
+}

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrSetProperty.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrSetProperty.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrSetProperty.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrSetProperty.java Sun May  2 17:02:51 2010
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ode.dao.jpa.bpel;
+
+import java.io.Serializable;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+
+/**
+ * @author Matthieu Riou <mriou at apache dot org>
+ */
+@Entity
+@Table(name="ODE_CORSET_PROP")
+@NamedQueries({
+    @NamedQuery(name=CorrSetProperty.DELETE_CORSET_PROPERTIES_BY_PROPERTY_IDS, query="delete from CorrSetProperty as p where p.corrSetId in(:corrSetIds)")
+})
+public class CorrSetProperty implements Serializable {
+    public final static String DELETE_CORSET_PROPERTIES_BY_PROPERTY_IDS = "DELETE_CORSET_PROPERTIES_BY_PROPERTY_IDS";
+
+    @Id @Column(name="ID")
+    @GeneratedValue(strategy=GenerationType.AUTO)
+    @SuppressWarnings("unused")
+    private Long _id;
+    @Basic @Column(name="PROP_KEY")
+    private String propertyKey;
+    @Basic @Column(name="PROP_VALUE")
+    private String propertyValue;
+
+    @SuppressWarnings("unused")
+    @Basic @Column(name="CORRSET_ID", insertable=false, updatable=false, nullable=true)
+    private Long corrSetId;
+
+    @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST}) @JoinColumn(name="CORRSET_ID")
+    private CorrelationSetDAOImpl _corrSet;
+
+    public CorrSetProperty() {
+    }
+    public CorrSetProperty(String propertyKey, String propertyValue) {
+        this.propertyKey = propertyKey;
+        this.propertyValue = propertyValue;
+    }
+
+    public String getPropertyKey() {
+        return propertyKey;
+    }
+
+    public void setPropertyKey(String propertyKey) {
+        this.propertyKey = propertyKey;
+    }
+
+    public String getPropertyValue() {
+        return propertyValue;
+    }
+
+    public void setPropertyValue(String propertyValue) {
+        this.propertyValue = propertyValue;
+    }
+
+    public CorrelationSetDAOImpl getCorrSet() {
+        return _corrSet;
+    }
+
+    public void setCorrSet(CorrelationSetDAOImpl corrSet) {
+        _corrSet = corrSet;
+    }
+}

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrelationSetDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrelationSetDAOImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrelationSetDAOImpl.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrelationSetDAOImpl.java Sun May  2 17:02:51 2010
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa.bpel;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.xml.namespace.QName;
+
+import org.apache.ode.bpel.common.CorrelationKey;
+import org.apache.ode.dao.bpel.CorrelationSetDAO;
+import org.apache.ode.dao.bpel.ScopeDAO;
+
+@Entity
+@Table(name="ODE_CORRELATION_SET")
+@NamedQueries({
+    @NamedQuery(name=CorrelationSetDAOImpl.DELETE_CORRELATION_SETS_BY_IDS, query="delete from CorrelationSetDAOImpl as c where c._correlationSetId in (:ids)"),
+    @NamedQuery(name=CorrelationSetDAOImpl.SELECT_CORRELATION_SETS_BY_INSTANCES, query="select c from CorrelationSetDAOImpl as c left join fetch c._scope left join fetch c._props where c._scope._processInstance._instanceId in (:instances)"),    
+    @NamedQuery(name=CorrelationSetDAOImpl.SELECT_CORRELATION_SET_IDS_BY_PROCESS, query="select c._correlationSetId from CorrelationSetDAOImpl as c where c._scope._processInstance._process = :process"),
+    @NamedQuery(name=CorrelationSetDAOImpl.SELECT_CORRELATION_SET_IDS_BY_INSTANCE, query="select c._correlationSetId from CorrelationSetDAOImpl as c where c._scope._processInstance = :instance"),
+    @NamedQuery(name=CorrelationSetDAOImpl.SELECT_ACTIVE_SETS, query="select c from CorrelationSetDAOImpl as c left join fetch c._scope where c._scope._processInstance._state = (:state)")
+})
+public class CorrelationSetDAOImpl implements CorrelationSetDAO, Serializable {
+    public final static String DELETE_CORRELATION_SETS_BY_IDS = "DELETE_CORRELATION_SETS_BY_IDS";
+    public final static String SELECT_CORRELATION_SETS_BY_INSTANCES = "SELECT_CORRELATION_SETS_BY_INSTANCES";
+    public final static String SELECT_CORRELATION_SET_IDS_BY_PROCESS = "SELECT_CORRELATION_SET_IDS_BY_PROCESS";
+    public final static String SELECT_CORRELATION_SET_IDS_BY_INSTANCE = "SELECT_CORRELATION_SET_IDS_BY_INSTANCE";
+    public final static String SELECT_ACTIVE_SETS = "SELECT_ACTIVE_SETS";
+
+	@Id @Column(name="CORRELATION_SET_ID") 
+	@GeneratedValue(strategy=GenerationType.AUTO)
+	private Long _correlationSetId;
+	@Basic @Column(name="NAME")
+    private String _name;
+	@Basic @Column(name="CORRELATION_KEY")
+    private String _correlationKey;
+
+    @OneToMany(targetEntity=CorrSetProperty.class,mappedBy="_corrSet",fetch=FetchType.LAZY,cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
+    private Collection<CorrSetProperty> _props = new ArrayList<CorrSetProperty>();
+    @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST}) @JoinColumn(name="SCOPE_ID")
+    private ScopeDAOImpl _scope;
+
+    public CorrelationSetDAOImpl() {}
+	public CorrelationSetDAOImpl(ScopeDAOImpl scope, String name) {
+		_name = name;
+		_scope = scope;
+	}
+	
+	public Long getCorrelationSetId() {
+		return _correlationSetId;
+	}
+
+	public String getName() {
+		return _name;
+	}
+
+	public Map<QName, String> getProperties() {
+        HashMap<QName, String> map = new HashMap<QName, String>();
+        for (CorrSetProperty prop : _props) {
+            map.put(QName.valueOf(prop.getPropertyKey()), prop.getPropertyValue());
+        }
+        return map;
+	}
+
+	public ScopeDAO getScope() {
+		return _scope;
+	}
+
+	public CorrelationKey getValue() {
+        if (_correlationKey == null) return null;
+        return new CorrelationKey(_correlationKey);
+	}
+
+	public void setValue(QName[] names, CorrelationKey values) {
+		_correlationKey = values.toCanonicalString();
+	    for (int m = 0; m < names.length; m++) {
+            CorrSetProperty prop = new CorrSetProperty(names[m].toString(), values.getValues()[m]);
+            _props.add(prop);
+            prop.setCorrSet(this);
+        }
+	}
+}

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrelatorDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrelatorDAOImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrelatorDAOImpl.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/CorrelatorDAOImpl.java Sun May  2 17:02:51 2010
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa.bpel;
+
+import java.io.Serializable;
+import org.apache.ode.bpel.common.CorrelationKey;
+import org.apache.ode.dao.bpel.CorrelatorDAO;
+import org.apache.ode.dao.bpel.MessageExchangeDAO;
+import org.apache.ode.dao.bpel.MessageRouteDAO;
+import org.apache.ode.dao.bpel.ProcessInstanceDAO;
+
+import javax.persistence.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+@Entity
+@Table(name="ODE_CORRELATOR")
+@NamedQueries({
+    @NamedQuery(name="RouteByCKey", query="SELECT route " +
+            "FROM MessageRouteDAOImpl as route " +
+            "WHERE route._correlationKey = :ckey " +
+                   "and route._correlator._process._processType = :ptype " +
+                   "and route._correlator._correlatorKey = :corrkey"),
+    @NamedQuery(name=CorrelatorDAOImpl.DELETE_CORRELATORS_BY_PROCESS, query="delete from CorrelatorDAOImpl as c where c._process = :process")
+})
+public class CorrelatorDAOImpl extends BpelDAO implements CorrelatorDAO, Serializable {
+    public final static String DELETE_CORRELATORS_BY_PROCESS = "DELETE_CORRELATORS_BY_PROCESS";
+
+    @Id @Column(name="CORRELATOR_ID")
+    @GeneratedValue(strategy=GenerationType.AUTO)
+    private Long _correlatorId;
+    @Basic @Column(name="CORRELATOR_KEY")
+    private String _correlatorKey;
+    @OneToMany(targetEntity=MessageRouteDAOImpl.class,mappedBy="_correlator",fetch=FetchType.EAGER,cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
+    private Collection<MessageRouteDAOImpl> _routes = new ArrayList<MessageRouteDAOImpl>();
+    @OneToMany(targetEntity=MessageExchangeDAOImpl.class,mappedBy="_correlator",fetch=FetchType.LAZY,cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
+    private Collection<MessageExchangeDAOImpl> _exchanges = new ArrayList<MessageExchangeDAOImpl>();
+    @ManyToOne(fetch= FetchType.LAZY,cascade={CascadeType.PERSIST}) @JoinColumn(name="PROC_ID")
+    private ProcessDAOImpl _process;
+
+    public CorrelatorDAOImpl(){}
+    public CorrelatorDAOImpl(String correlatorKey, ProcessDAOImpl process) {
+        _correlatorKey = correlatorKey;
+        _process = process;
+    }
+
+    public void addRoute(String routeGroupId, ProcessInstanceDAO target, int index, CorrelationKey correlationKey) {
+        MessageRouteDAOImpl mr = new MessageRouteDAOImpl(correlationKey,
+                routeGroupId, index, (ProcessInstanceDAOImpl) target, this);
+        _routes.add(mr);
+    }
+
+    public MessageExchangeDAO dequeueMessage(CorrelationKey correlationKey) {
+        MessageExchangeDAOImpl toRemove = null;
+        for (Iterator<MessageExchangeDAOImpl> itr=_exchanges.iterator(); itr.hasNext();){
+            MessageExchangeDAOImpl mex = itr.next();
+            if (mex.getCorrelationKeys().contains(correlationKey)) {
+                toRemove = mex;
+            }
+        }
+        _exchanges.remove(toRemove);
+        return toRemove;
+    }
+
+    public void enqueueMessage(MessageExchangeDAO mex,
+                               CorrelationKey[] correlationKeys) {
+        MessageExchangeDAOImpl mexImpl = (MessageExchangeDAOImpl) mex;
+        for (CorrelationKey key : correlationKeys ) {
+            mexImpl.addCorrelationKey(key);
+        }
+        _exchanges.add(mexImpl);
+        mexImpl.setCorrelator(this);
+
+    }
+
+    public MessageRouteDAO findRoute(CorrelationKey correlationKey) {
+        Query qry = getEM().createNamedQuery("RouteByCKey");
+        qry.setParameter("ckey", correlationKey.toCanonicalString());
+        qry.setParameter("ptype", _process.getType().toString());
+        qry.setParameter("corrkey", _correlatorKey);
+        List<MessageRouteDAO> routes = (List<MessageRouteDAO>) qry.getResultList();
+        if (routes.size() > 0) return routes.get(0);
+        else return null;
+    }
+
+    public String getCorrelatorId() {
+        return _correlatorKey;
+    }
+
+    public void removeRoutes(String routeGroupId, ProcessInstanceDAO target) {
+        // remove route across all correlators of the process
+        ((ProcessInstanceDAOImpl)target).removeRoutes(routeGroupId);
+    }
+
+    void removeLocalRoutes(String routeGroupId, ProcessInstanceDAO target) {
+        boolean flush = false;
+        for (Iterator<MessageRouteDAOImpl> itr=_routes.iterator(); itr.hasNext(); ) {
+            MessageRouteDAOImpl mr = itr.next();
+            if ( mr.getGroupId().equals(routeGroupId) && mr.getTargetInstance().equals(target)) {
+                itr.remove();
+                getEM().remove(mr);
+                flush = true;
+            }
+        }
+        if (flush) {
+            getEM().flush();
+        }
+    }
+}

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/EventDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/EventDAOImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/EventDAOImpl.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/EventDAOImpl.java Sun May  2 17:02:51 2010
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa.bpel;
+
+import java.io.Serializable;
+import org.apache.ode.bpel.evt.BpelEvent;
+
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import java.sql.Timestamp;
+
+/**
+ * @author Matthieu Riou <mriou at apache dot org>
+ */
+@Entity
+@Table(name="ODE_EVENT")
+@NamedQueries({
+    @NamedQuery(name=EventDAOImpl.SELECT_EVENT_IDS_BY_PROCESS, query="select e._id from EventDAOImpl as e where e._instance._process = :process"),
+    @NamedQuery(name=EventDAOImpl.DELETE_EVENTS_BY_IDS, query="delete from EventDAOImpl as e where e._id in (:ids)"),
+    @NamedQuery(name=EventDAOImpl.DELETE_EVENTS_BY_INSTANCE, query="delete from EventDAOImpl as e where e._instance = :instance")
+})
+public class EventDAOImpl implements Serializable {
+    public final static String SELECT_EVENT_IDS_BY_PROCESS = "SELECT_EVENT_IDS_BY_PROCESS";
+    public final static String DELETE_EVENTS_BY_IDS = "DELETE_EVENTS_BY_IDS";
+    public final static String DELETE_EVENTS_BY_INSTANCE = "DELETE_EVENTS_BY_INSTANCE";
+
+    @Id @Column(name="EVENT_ID")
+	@GeneratedValue(strategy= GenerationType.AUTO)
+	private Long _id;
+    @Basic @Column(name="TSTAMP")
+    private Timestamp _tstamp;
+    @Basic @Column(name="TYPE")
+    private String _type;
+    @Basic @Column(name="DETAIL")
+    private String _detail;
+
+    /** Scope identifier, possibly null. */
+    @Basic @Column(name="SCOPE_ID")
+    private Long _scopeId;
+
+    @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST}) @JoinColumn(name="PROCESS_ID")
+    private ProcessDAOImpl _process;
+    @ManyToOne(fetch= FetchType.LAZY,cascade={CascadeType.PERSIST})	@JoinColumn(name="INSTANCE_ID")
+    private ProcessInstanceDAOImpl _instance;
+    @Lob  @Column(name="DATA")
+    private BpelEvent _event;
+
+    public BpelEvent getEvent() {
+        return _event;
+    }
+
+    public void setEvent(BpelEvent event) {
+        _event = event;
+    }
+
+    public String getDetail() {
+        return _detail;
+    }
+
+    public void setDetail(String detail) {
+        _detail = detail;
+    }
+
+    public Long getId() {
+        return _id;
+    }
+
+    public void setId(Long id) {
+        _id = id;
+    }
+
+    public ProcessInstanceDAOImpl getInstance() {
+        return _instance;
+    }
+
+    public void setInstance(ProcessInstanceDAOImpl instance) {
+        _instance = instance;
+    }
+
+    public ProcessDAOImpl getProcess() {
+        return _process;
+    }
+
+    public void setProcess(ProcessDAOImpl process) {
+        _process = process;
+    }
+
+    public Timestamp getTstamp() {
+        return _tstamp;
+    }
+
+    public void setTstamp(Timestamp tstamp) {
+        _tstamp = tstamp;
+    }
+
+    public String getType() {
+        return _type;
+    }
+
+    public void setType(String type) {
+        _type = type;
+    }
+
+    public Long getScopeId() {
+        return _scopeId;
+    }
+
+    public void setScopeId(Long scopeId) {
+        _scopeId = scopeId;
+    }
+}

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/FaultDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/FaultDAOImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/FaultDAOImpl.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/FaultDAOImpl.java Sun May  2 17:02:51 2010
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa.bpel;
+
+import java.io.Serializable;
+import org.apache.ode.dao.bpel.FaultDAO;
+import org.apache.ode.utils.DOMUtils;
+import org.w3c.dom.Element;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.xml.namespace.QName;
+
+@Entity
+@Table(name="ODE_FAULT")
+@NamedQueries({
+    @NamedQuery(name=FaultDAOImpl.DELETE_FAULTS_BY_IDS, query="delete from FaultDAOImpl as f where f._id in(:ids)")
+})
+public class FaultDAOImpl implements FaultDAO, Serializable {
+    public final static String DELETE_FAULTS_BY_IDS = "DELETE_FAULTS_BY_IDS";
+
+	@Id @Column(name="FAULT_ID") 
+	@GeneratedValue(strategy=GenerationType.AUTO)
+	private Long _id;
+	@Basic @Column(name="NAME")
+    private String _name;
+	@Basic @Column(name="MESSAGE", length=4000)
+    private String _explanation;
+	@Lob @Column(name="DATA")
+    private String _data;
+	@Basic @Column(name="LINE_NUMBER")
+    private int _lineNo;
+	@Basic @Column(name="ACTIVITY_ID")
+    private int _activityId;
+
+	public FaultDAOImpl() {}
+	public FaultDAOImpl(QName faultName, String explanation, int faultLineNo,
+			int activityId, Element faultMessage) {
+		_name = faultName.toString();
+		_explanation = explanation;
+		_lineNo = faultLineNo;
+		_activityId = activityId;
+		_data = (faultMessage == null)?null:DOMUtils.domToString(faultMessage);
+	}
+	
+	public int getActivityId() {
+		return _activityId;
+	}
+
+	public Element getData() {
+		Element ret = null;
+		
+		try {
+			ret = (_data == null)?null:DOMUtils.stringToDOM(_data);
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+		
+		return ret;
+	}
+
+	public String getExplanation() {
+		return _explanation;
+	}
+
+	public int getLineNo() {
+		return _lineNo;
+	}
+
+	public QName getName() {
+		return _name == null ? null : QName.valueOf(_name);
+	}
+
+}

Added: ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/MessageDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/MessageDAOImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/MessageDAOImpl.java (added)
+++ ode/trunk/dao-jpa/src/main/java/org/apache/ode/dao/jpa/bpel/MessageDAOImpl.java Sun May  2 17:02:51 2010
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa.bpel;
+
+import java.io.Serializable;
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.xml.namespace.QName;
+
+import org.apache.ode.dao.bpel.MessageDAO;
+import org.apache.ode.utils.DOMUtils;
+import org.w3c.dom.Element;
+
+@Entity
+@Table(name="ODE_MESSAGE")
+@NamedQueries({
+    @NamedQuery(name=MessageDAOImpl.SELECT_REQUEST_MESSAGE_IDS_BY_PROCESS, query="select x._request._id from MessageExchangeDAOImpl as x where x._process = :process"),
+    @NamedQuery(name=MessageDAOImpl.SELECT_RESPONSE_MESSAGE_IDS_BY_PROCESS, query="select x._response._id from MessageExchangeDAOImpl as x where x._process = :process"),
+    @NamedQuery(name=MessageDAOImpl.DELETE_MESSAGES_BY_IDS, query="delete from MessageDAOImpl as m where m._id in (:ids)")
+})
+public class MessageDAOImpl implements MessageDAO, Serializable {
+    public final static String SELECT_REQUEST_MESSAGE_IDS_BY_PROCESS = "SELECT_REQUEST_MESSAGE_IDS_BY_PROCESS";
+    public final static String SELECT_RESPONSE_MESSAGE_IDS_BY_PROCESS = "SELECT_RESPONSE_MESSAGE_IDS_BY_PROCESS";
+    public final static String DELETE_MESSAGES_BY_IDS = "DELETE_MESSAGES_BY_IDS";
+
+    @Id @Column(name="MESSAGE_ID")
+    @GeneratedValue(strategy=GenerationType.AUTO)
+    @SuppressWarnings("unused")
+    Long _id;
+    @Basic @Column(name="TYPE")
+    private String _type;
+    @Lob @Column(name="DATA")
+    private String _data;
+    @Lob @Column(name="HEADER")
+    private String _header;
+    @Transient
+    private Element _element;
+    @Transient
+    private Element _headerElement;
+
+    public MessageDAOImpl() {
+    }
+
+    public MessageDAOImpl(QName type, MessageExchangeDAOImpl me) {
+        if (type != null) _type = type.toString();
+    }
+
+    public Element getData() {
+        if ( _element == null && _data != null && !"".equals(_data) ) {
+            try {
+                _element = DOMUtils.stringToDOM(_data);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        return _element;
+    }
+
+    public QName getType() {
+        return _type == null ? null : QName.valueOf(_type);
+    }
+
+    public void setData(Element value) {
+        if (value == null) return;
+        _data = DOMUtils.domToString(value);
+        _element = value;
+    }
+
+    public void setType(QName type) {
+        _type = type.toString();
+    }
+
+    public Element getHeader() {
+        if ( _headerElement == null && _header != null && !"".equals(_header)) {
+            try {
+                _headerElement = DOMUtils.stringToDOM(_header);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return _headerElement;
+    }
+
+    public void setHeader(Element value) {
+        if (value == null) return;
+        _header = DOMUtils.domToString(value);
+        _headerElement = value;
+    }
+
+}