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/21 17:41:07 UTC

svn commit: r947046 [6/12] - in /ode/trunk: ./ axis2/src/main/java/org/apache/ode/axis2/ bpel-dao/ bpel-dao/src/main/java/org/apache/ode/dao/ bpel-dao/src/main/java/org/apache/ode/dao/bpel/ bpel-dao/src/main/java/org/apache/ode/dao/store/ bpel-epr/ bpe...

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelatorMessageDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelatorMessageDaoImpl.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelatorMessageDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelatorMessageDaoImpl.java Fri May 21 15:40:59 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.hib.bpel;
+
+import org.apache.ode.dao.bpel.CorrelatorMessageDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelatorMessage;
+import org.apache.ode.bpel.common.CorrelationKey;
+
+public class CorrelatorMessageDaoImpl extends HibernateDao implements CorrelatorMessageDAO {
+
+    private HCorrelatorMessage _hobj;
+
+    public CorrelatorMessageDaoImpl(SessionManager sm, HCorrelatorMessage hobj) {
+        super(sm, hobj);
+        entering("CorrelatorDaoImpl.CorrelatorDaoImpl");
+        _hobj = hobj;
+    }
+
+    public CorrelationKey getCorrelationKey() {
+        return new CorrelationKey(_hobj.getCorrelationKey());
+    }
+
+    public void setCorrelationKey(CorrelationKey ckey) {
+        _hobj.setCorrelationKey(ckey.toCanonicalString());
+    }
+}

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CriteriaBuilder.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CriteriaBuilder.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CriteriaBuilder.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CriteriaBuilder.java Fri May 21 15:40:59 2010
@@ -0,0 +1,428 @@
+/*
+ * 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.hib.bpel;
+
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.utils.ISO8601DateParser;
+import org.apache.ode.utils.RelativeDateParser;
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.criterion.Disjunction;
+import org.hibernate.criterion.Property;
+import org.hibernate.criterion.Restrictions;
+
+/**
+ * Class used for converting "filter" objects into Hibernate
+ * {@link org.hibernate.Criteria} objects.
+ */
+class CriteriaBuilder {
+    static final Log __log = LogFactory.getLog(CriteriaBuilder.class);
+    
+    /**
+     * Build a HQL query from an instance filter.
+     * @param filter filter
+     */
+    Query buildHQLQuery(Session session, InstanceFilter filter) {
+        Map<String, Object> parameters = new HashMap<String, Object>();
+        
+        StringBuffer query = new StringBuffer();
+                
+        query.append("select pi from HProcessInstance as pi left join fetch pi.fault ");
+
+        if (filter != null) {
+            // Building each clause
+            ArrayList<String> clauses = new ArrayList<String>();
+
+            // iid filter
+            if ( filter.getIidFilter() != null ) {
+                StringBuffer filters = new StringBuffer();
+                List<String> iids = filter.getIidFilter();
+                for (int m = 0; m < iids.size(); m++) {
+                    filters.append(" pi.id = :iid").append(m);
+                    parameters.put("iid" + m, Long.parseLong(iids.get(m)));
+                    if (m < iids.size() - 1) filters.append(" or");
+                }
+                clauses.add(" (" + filters + ")");
+            }
+
+            // pid filter
+            if (filter.getPidFilter() != null) {
+                StringBuffer filters = new StringBuffer();
+                List<String> pids = filter.getPidFilter();
+                String cmp;
+                if (filter.arePidsNegative()) {
+                    cmp = " != ";
+                } else {
+                    cmp = " = ";
+                }
+                for (int m = 0; m < pids.size(); m++) {
+                    filters.append(" pi.process.processId ").append(cmp).append(" :pid").append(m);
+                    parameters.put("pid" + m, pids.get(m));
+                    if (m < pids.size() - 1) filters.append(" or");
+                }
+                clauses.add(" (" + filters + ")");
+            }
+
+            // name filter
+            if (filter.getNameFilter() != null) {
+                clauses.add(" pi.process.typeName like :pname");
+                parameters.put("pname", filter.getNameFilter().replaceAll("\\*", "%"));
+            }
+
+            // name space filter
+            if (filter.getNamespaceFilter() != null) {
+                clauses.add(" pi.process.typeNamespace like :pnamespace");
+                parameters.put("pnamespace", filter.getNamespaceFilter().replaceAll("\\*", "%"));
+            }
+
+            // started filter
+            if (filter.getStartedDateFilter() != null) {
+                for ( String ds : filter.getStartedDateFilter() ) {
+                    // named parameters not needed as date is parsed and is hence not
+                    // prone to HQL injections
+                    clauses.add(" pi.created " + dateFilter(ds));
+                }
+            }
+
+            // last-active filter
+            if (filter.getLastActiveDateFilter() != null) {
+                for ( String ds : filter.getLastActiveDateFilter() ) {
+                    // named parameters not needed as date is parsed and is hence not
+                    // prone to HQL injections
+                    clauses.add(" pi.lastActiveTime " + dateFilter(ds));
+                }
+            }
+
+            // status filter
+            if (filter.getStatusFilter() != null) {
+                StringBuffer filters = new StringBuffer();
+                List<Short> states = filter.convertFilterState();
+                for (int m = 0; m < states.size(); m++) {
+                    filters.append(" pi.state = :pstate").append(m);
+                    parameters.put("pstate" + m, states.get(m));
+                    if (m < states.size() - 1) filters.append(" or");
+                }
+                clauses.add(" (" + filters.toString() + ")");
+            }
+
+            // $property filter
+            if (filter.getPropertyValuesFilter() != null) {
+                Map<String,String> props = filter.getPropertyValuesFilter();
+                // join to correlation sets
+                query.append(" inner join pi.correlationSets as cs");
+                int i = 0;
+                for (String propKey : props.keySet()) {
+                    i++;
+                    // join to props for each prop
+                    query.append(" inner join cs.properties as csp"+i);
+                    // add clause for prop key and value
+                    
+                    // spaces have to be escaped, might be better handled in InstanceFilter
+                    String value = props.get(propKey).replaceAll("&#32;", " ");
+                    if (propKey.startsWith("{")) {
+                        String namespace = propKey.substring(1, propKey.lastIndexOf("}"));
+                        clauses.add(" csp" + i + ".name = :cspname" + i +
+                                " and csp" + i + ".namespace = :cspnamespace" + i + 
+                                " and csp" + i + ".value = :cspvalue" + i);
+
+                        parameters.put("cspname" + i, propKey.substring(propKey.lastIndexOf("}") + 1, propKey.length()));
+                        parameters.put("cspnamespace" + i, namespace);
+                        parameters.put("cspvalue" + i, value);
+                    } else {
+                        clauses.add(" csp" + i + ".name = :cspname" + i +
+                                " and csp" + i + ".value = :cspvalue" + i);
+
+                        parameters.put("cspname" + i, propKey);
+                        parameters.put("cspvalue" + i, value);
+                    }
+                }
+            }
+
+            // order by
+            StringBuffer orderby = new StringBuffer("");
+            if (filter.getOrders() != null) {
+                orderby.append(" order by");
+                List<String> orders = filter.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.id";
+                    if (field.endsWith("name")) {
+                        fieldName = " pi.process.typeName";
+                    }
+                    if (field.endsWith("namespace")) {
+                        fieldName = " pi.process.typeNamespace";
+                    }
+                    if ( field.endsWith("version")) {
+                        fieldName = " pi.process.version";
+                    }
+                    if ( field.endsWith("status")) {
+                        fieldName = " pi.state";
+                    }
+                    if ( field.endsWith("started")) {
+                        fieldName = " pi.created";
+                    }
+                    if ( field.endsWith("last-active")) {
+                        fieldName = " pi.lastActiveTime";
+                    }
+                    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());
+        }
+        
+        Query q = session.createQuery(query.toString());
+        
+        for (String p : parameters.keySet()) {
+            q.setParameter(p, parameters.get(p));
+        }
+
+        if (filter.getLimit() != 0) {
+            q.setMaxResults(filter.getLimit());
+        }
+
+        return q;
+    }
+    
+    private static String dateFilter(String filter) {
+        String date = Filter.getDateWithoutOp(filter);
+        String op = filter.substring(0,filter.indexOf(date));
+        Date dt = null;
+        try {
+            dt = ISO8601DateParser.parse(date);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        Timestamp ts = new Timestamp(dt.getTime());
+        return op + " '" + ts.toString() + "'";
+    }
+
+    
+    
+  /**
+   * Build a Hibernate {@link Criteria} from an instance filter.
+   * @param crit target (destination) criteria
+   * @param filter filter
+   */
+  void buildCriteria(Criteria crit, InstanceFilter filter) {
+    Criteria processCrit = crit.createCriteria("process");
+
+    // Filtering on PID
+    List<String> pids = filter.getPidFilter();
+    if (pids != null && pids.size() > 0) {
+        Disjunction disj = Restrictions.disjunction();
+        for (String pid: pids) {
+            if( !filter.arePidsNegative() ) {
+                disj.add(Restrictions.eq("processId", pid));
+            } else {
+                disj.add(Restrictions.ne("processId", pid));
+            }
+        }
+        processCrit.add(disj);
+    }
+    
+    List<String> iids = filter.getIidFilter();
+    if (iids != null && iids.size() > 0) {
+        Disjunction disj = Restrictions.disjunction();
+        for (String iid: iids) {
+            disj.add(Restrictions.eq("id", new Long(iid)));
+        }
+        crit.add(disj);
+    }
+    
+    // Filtering on name and namespace
+    if (filter.getNameFilter() != null) {
+      processCrit.add(Restrictions.like("typeName", filter.getNameFilter().replaceAll("\\*", "%")));
+    }
+    if (filter.getNamespaceFilter() != null) {
+      processCrit.add(Restrictions.like("typeNamespace", filter.getNamespaceFilter().replaceAll("\\*", "%")));
+    }
+
+    // Specific filter for status (using a disjunction between possible statuses)
+    if (filter.getStatusFilter() != null) {
+      List<Short> statuses = filter.convertFilterState();
+      Disjunction disj = Restrictions.disjunction();
+      for (short status : statuses) {
+        disj.add(Restrictions.eq("state", status));
+      }
+      crit.add(disj);
+    }
+
+    // Specific filter for started and last active dates.
+    if (filter.getStartedDateFilter() != null) {
+      for (String sdf : filter.getStartedDateFilter()) {
+        addFilterOnPrefixedDate(crit, sdf, "created");
+      }
+    }
+    if (filter.getLastActiveDateFilter() != null) {
+      for (String ladf : filter.getLastActiveDateFilter()) {
+        addFilterOnPrefixedDate(crit, ladf,  "lastActiveTime");
+      }
+    }
+
+    // Specific filter for correlation properties
+    if (filter.getPropertyValuesFilter() != null) {
+      Criteria propCrit = crit.createCriteria("correlationSets").createCriteria("properties");
+      for (Map.Entry<String, String> corValue : filter.getPropertyValuesFilter().entrySet()) {
+        String propName = (String)corValue.getKey();
+        if (propName.startsWith("{")) {
+          String namespace = propName.substring(1, propName.lastIndexOf("}"));
+          propName = propName.substring(propName.lastIndexOf("}") + 1, propName.length());
+          propCrit.add(Restrictions.eq("name", propName))
+                  .add(Restrictions.eq("namespace", namespace))
+                  .add(Restrictions.eq("value", corValue.getValue()));
+        } else {
+          propCrit.add(Restrictions.eq("name", corValue.getKey()))
+                  .add(Restrictions.eq("value", corValue.getValue()));
+        }
+      }
+    }
+
+    // Ordering
+    if (filter.orders != null) {
+      for (String key : filter.orders) {
+        boolean ascending = true;
+        String orderKey = key;
+        if (key.startsWith("+") || key.startsWith("-")) {
+          orderKey = key.substring(1, key.length());
+          if (key.startsWith("-")) ascending = false;
+        }
+
+        if ("name".equals(orderKey)) {
+          if (ascending) processCrit.addOrder(Property.forName("typeName").asc());
+          else processCrit.addOrder(Property.forName("typeName").desc());
+        } else if ("namespace".equals(orderKey)) {
+          if (ascending) processCrit.addOrder(Property.forName("typeNamespace").asc());
+          else processCrit.addOrder(Property.forName("typeNamespace").desc());
+        } else if ("pid".equals(orderKey)) {
+          if (ascending) processCrit.addOrder(Property.forName("processId").asc());
+          else processCrit.addOrder(Property.forName("processId").desc());
+        } else if ("version".equals(orderKey)) {
+          if (ascending) processCrit.addOrder(Property.forName("version").asc());
+          else processCrit.addOrder(Property.forName("version").desc());
+        } else if ("status".equals(orderKey)) {
+          if (ascending) crit.addOrder(Property.forName("state").asc());
+          else crit.addOrder(Property.forName("state").desc());
+        } else if ("started".equals(orderKey)) {
+          if (ascending) crit.addOrder(Property.forName("created").asc());
+          else crit.addOrder(Property.forName("created").desc());
+        } else if ("last-active".equals(orderKey)) {
+          if (ascending) crit.addOrder(Property.forName("lastActiveTime").asc());
+          else crit.addOrder(Property.forName("lastActiveTime").desc());
+        }
+      }
+    }
+
+    if (filter.getLimit() > 0) crit.setMaxResults(filter.getLimit());
+  }
+
+  /**
+   * Build criteria for an event filter.
+   * @param crit target criteria
+   * @param efilter event filter
+   */
+  void buildCriteria(Criteria crit, BpelEventFilter efilter) {
+    if (efilter.getTypeFilter() != null)
+      crit.add(Restrictions.like("type", efilter.getTypeFilter().replace('*','%')));
+      
+    // Specific filter for started and last active dates.
+    if (efilter.getTimestampFilter() != null) {
+      for (Filter.Restriction<Date> sdf : efilter.getTimestampFilter()) {
+        addFilterOnPrefixedDate(crit, sdf.op, sdf.value, "tstamp");
+      }
+    }
+
+    if (efilter.limit > 0) crit.setMaxResults(efilter.limit);
+  }
+  
+  void addScopeFilter(Criteria crit, String scopeId) {
+    crit.add(Restrictions.eq("",scopeId));
+  }
+  
+  static void addFilterOnPrefixedDate(Criteria crit, String prefixedDate, String dateAttribute) {
+    Date realDate = null;
+    try {
+      realDate = parseDateExpression(getDateWithoutOp(prefixedDate));
+    } catch (ParseException e) {
+      // Never occurs, the deploy date format is pre-validated by the filter
+    }
+    addFilterOnPrefixedDate(crit,prefixedDate,realDate,dateAttribute);
+  }
+  
+  private static Date parseDateExpression(String date) throws ParseException {
+      if( date.toLowerCase().startsWith("-") && date.length() > 1 ) {
+          return RelativeDateParser.parseRelativeDate(date.substring(1));
+      } else {
+          return ISO8601DateParser.parse(date);
+      }
+  }
+
+  static void addFilterOnPrefixedDate(Criteria crit, String op, Date date, String dateAttribute) {
+    if (op.startsWith("=")) {
+      crit.add(Restrictions.eq(dateAttribute, date));
+    } else if (op.startsWith("<=")) {
+      crit.add(Restrictions.le(dateAttribute, date));
+    } else if (op.startsWith(">=")) {
+      crit.add(Restrictions.ge(dateAttribute, date));
+    } else if (op.startsWith("<")) {
+      crit.add(Restrictions.lt(dateAttribute, date));
+    } else if (op.startsWith(">")) {
+      crit.add(Restrictions.gt(dateAttribute, date));
+    }
+  }
+
+  private static String getDateWithoutOp(String ddf) {
+    return Filter.getDateWithoutOp(ddf);
+  }
+
+
+}

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/FaultDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/FaultDAOImpl.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/FaultDAOImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/FaultDAOImpl.java Fri May 21 15:40:59 2010
@@ -0,0 +1,75 @@
+/*
+ * 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.hib.bpel;
+
+import java.io.IOException;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.dao.bpel.FaultDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HFaultData;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.QNameUtils;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+/**
+ * Hibernate based {@link FaultDAO} implementation
+ */
+public class FaultDAOImpl extends HibernateDao implements FaultDAO {
+
+
+    HFaultData _self;
+
+    public FaultDAOImpl(SessionManager sm, HFaultData fault) {
+        super(sm, fault);
+        entering("FaultDAOImpl.FaultDAOImpl");
+        _self = fault;
+    }
+
+    public QName getName() {
+        return QNameUtils.toQName(_self.getName());
+    }
+
+    public Element getData() {
+        entering("FaultDAOImpl.getData");
+        if (_self.getData() == null) return null;
+        try {
+            return DOMUtils.stringToDOM(_self.getData());
+        } catch (SAXException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public String getExplanation() {
+        return _self.getExplanation();
+    }
+
+    public int getLineNo() {
+        return _self.getLineNo();
+    }
+
+    public int getActivityId() {
+        return _self.getActivityId();
+    }
+}

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/HibernateDao.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/HibernateDao.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/HibernateDao.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/HibernateDao.java Fri May 21 15:40:59 2010
@@ -0,0 +1,121 @@
+/*
+ * 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.hib.bpel;
+
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Base class for our DAO objects.
+ * <p>
+ * All subclass methods that might trigger SQL queries should log a message in the log category 'org.apache.ode.bpel.DAO' when entered.
+ * A typical message could be "className.methodName". <br/>
+ * Typical candidates are setters, finders and getters of entities. Getters of simple properties won't provide relevant information. 
+ */
+public abstract class HibernateDao {
+
+    // logger used by subclasses to track entered methods that may trigger sql query
+    // we don't use the package name to avoid interferences with other logging info.
+    static final Log logDao = LogFactory.getLog("org.apache.ode.bpel.DAO");
+
+    protected final SessionManager _sm;
+    protected final HObject _hobj;
+
+    protected HibernateDao(SessionManager sessionManager, HObject hobj) {
+        _sm = sessionManager;
+        _hobj = hobj;
+    }
+
+    void entering(String msg){
+        // add a prefix to be parser friendly 
+        if(logDao.isDebugEnabled()) logDao.debug("entering "+msg);
+    }
+
+    void leaving(String msg){
+        if(logDao.isDebugEnabled()) logDao.debug("leaving "+msg);
+    }
+
+    /**
+     * @see org.apache.ode.utils.dao.DAO#getDHandle()
+     */
+    public Serializable getDHandle() {
+        return new HibernateHandle(getClass(), _hobj.getClass(), getSession().getIdentifier(_hobj));
+    }
+  
+    protected Session getSession() {
+        return _sm.getSession();
+    }
+
+    public HObject getHibernateObj() {
+        return _hobj;
+    }
+
+    public Serializable getId() {
+        if( _hobj != null ) {
+            return _hobj.getId();
+        }
+        return null;
+    }
+    
+    public boolean equals(Object obj) {
+        assert obj instanceof HibernateDao;
+        return _hobj.getId().equals(((HibernateDao) obj)._hobj.getId());
+    }
+
+    public int hashCode() {
+        return _hobj.getId().hashCode();
+    }
+
+    protected void update() {
+        _sm.getSession().update(_hobj);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected void deleteByIds(Class entity, List<Long> ids) {
+        deleteByColumn(entity, "id", ids);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected void deleteByColumn(Class entity, String column, List<Long> values) {
+        if( values != null && values.size() > 0 ) {
+            final String delete = "delete from "+entity.getName()+" as e where e."+column+" in (:values)";
+
+            // some databases don't like long lists of values with IN operator
+            // so we delete in batches.  Oracle 9i, for instance, doesn't support
+            // more than 1000 -- we opt to be conservative.
+            final int batchSize = 100;
+            
+            int index = 0;
+            while (index < values.size()) {
+                List<Long> subList = values.subList(index, Math.min(index+batchSize, values.size()));
+                Query query = getSession().createQuery(delete);
+                query.setParameterList("values", subList);
+                query.executeUpdate();
+                index += batchSize;
+            }
+        }
+    }    
+}

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/HibernateHandle.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/HibernateHandle.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/HibernateHandle.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/HibernateHandle.java Fri May 21 15:40:59 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.hib.bpel;
+
+import java.io.Serializable;
+
+/**
+ * Serializable class for obtain a reference to a hibernate POJO
+ */
+class HibernateHandle implements Serializable{
+
+  private static final long serialVersionUID = 1L;
+  private Class _daoCls;
+	private Class _hibCls;
+  private Serializable _id;
+  /**
+	 * 
+	 */
+	public HibernateHandle(Class daoCls, Class hibCls, Serializable id) {
+		_daoCls = daoCls;
+    _hibCls = hibCls;
+    _id = id;
+	}
+  
+  public Class getHibernateClass(){
+  	return _hibCls;
+  }
+  
+  public Class getDAOClass(){
+  	return _daoCls;
+  }
+  
+  public Serializable getId(){
+  	return _id;
+  }
+}

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageDaoImpl.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageDaoImpl.java Fri May 21 15:40:59 2010
@@ -0,0 +1,98 @@
+/*
+ * 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.hib.bpel;
+
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.dao.bpel.MessageDAO;
+import org.apache.ode.dao.bpel.MessageExchangeDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HMessage;
+import org.apache.ode.utils.DOMUtils;
+import org.hibernate.Session;
+import org.w3c.dom.Element;
+
+
+public class MessageDaoImpl extends HibernateDao implements MessageDAO {
+
+    private HMessage _hself;
+    private Session _session;
+
+    public MessageDaoImpl(SessionManager sessionManager, HMessage hobj) {
+        super(sessionManager, hobj);
+        entering("MessageDaoImpl.MessageDaoImpl");
+        _hself = hobj;
+        _session = sessionManager.getSession();
+    }
+
+    public void setType(QName type) {
+        entering("MessageDaoImpl.setType");
+        _hself.setType(type == null ? null : type.toString());
+    }
+
+    public QName getType() {
+        return _hself.getType() == null ? null : QName.valueOf(_hself.getType());
+    }
+
+    public void setData(Element value) {
+        entering("MessageDaoImpl.setData");
+        if (value == null) return;
+        _hself.setMessageData(DOMUtils.domToBytes(value));
+        update();
+        leaving("MessageDaoImpl.setData");
+    }
+
+    public Element getData() {
+        entering("MessageDaoImpl.getData");
+        if (_hself.getMessageData() == null)
+            return null;
+        try {
+            return DOMUtils.stringToDOM(_hself.getMessageData());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void setHeader(Element value) {
+        entering("MessageDaoImpl.setHeader");
+        if (value == null) return;
+        _hself.setHeader(DOMUtils.domToBytes(value));
+        update();
+        leaving("MessageDaoImpl.setHeader");
+    }
+
+    public Element getHeader() {
+        entering("MessageDaoImpl.getHeader");
+        if (_hself.getHeader() == null) return null;
+        try {
+            return DOMUtils.stringToDOM(_hself.getHeader());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public MessageExchangeDAO getMessageExchange() {
+        entering("MessageDaoImpl.getMessageExchange");
+        return new MessageExchangeDaoImpl(_sm,_hself.getMessageExchange());
+    }
+
+
+}

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageExchangeDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageExchangeDaoImpl.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageExchangeDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageExchangeDaoImpl.java Fri May 21 15:40:59 2010
@@ -0,0 +1,381 @@
+/*
+ * 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.hib.bpel;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.dao.bpel.MessageDAO;
+import org.apache.ode.dao.bpel.MessageExchangeDAO;
+import org.apache.ode.dao.bpel.PartnerLinkDAO;
+import org.apache.ode.dao.bpel.ProcessDAO;
+import org.apache.ode.dao.bpel.ProcessInstanceDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelatorMessage;
+import org.apache.ode.dao.hib.bpel.hobj.HMessage;
+import org.apache.ode.dao.hib.bpel.hobj.HMessageExchange;
+import org.apache.ode.dao.hib.bpel.hobj.HProcess;
+import org.apache.ode.dao.hib.bpel.hobj.HProcessInstance;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.stl.CollectionsX;
+import org.apache.ode.utils.stl.UnaryFunctionEx;
+import org.w3c.dom.Element;
+
+public class MessageExchangeDaoImpl extends HibernateDao implements
+        MessageExchangeDAO {
+    @SuppressWarnings("unused")
+    private static final Log __log = LogFactory.getLog(MessageExchangeDaoImpl.class);
+    
+    private HMessageExchange _hself;
+
+    // Used when provided process and instance aren't hibernate implementations. The relation
+    // therefore can't be persisted. Used for in-mem DAOs so that doesn't matter much. 
+    private ProcessDAO _externalProcess;
+    private ProcessInstanceDAO _externalInstance;
+
+    public MessageExchangeDaoImpl(SessionManager sm, HMessageExchange mex) {
+        super(sm, mex);
+        entering("MessageExchangeDaoImpl.MessageExchangeDaoImpl");
+        _hself = mex;
+    }
+
+    public String getMessageExchangeId() {
+        return _hself.getId().toString();
+    }
+
+    public MessageDAO getResponse() {
+        entering("MessageExchangeDaoImpl.getResponse");
+        return _hself.getResponse() == null ? null : new MessageDaoImpl(_sm, _hself.getResponse());
+    }
+
+    public Date getCreateTime() {
+        return _hself.getInsertTime();
+    }
+
+    public void setCreateTime(Date createTime) {
+        _hself.setInsertTime(createTime);
+    }
+
+    public MessageDAO getRequest() {
+        entering("MessageExchangeDaoImpl.getRequest");
+        return _hself.getRequest() == null ? null : new MessageDaoImpl(_sm, _hself.getRequest());
+    }
+
+    public String getOperation() {
+        return _hself.getOperationName();
+    }
+
+    public QName getPortType() {
+        return _hself.getPortType() == null ? null : QName.valueOf(_hself.getPortType());
+    }
+
+    public void setPortType(QName porttype) {
+        entering("MessageExchangeDaoImpl.setPortType");
+        _hself.setPortType(porttype == null ? null : porttype.toString());
+        update();
+    }
+
+    public void setStatus(String status) {
+        entering("MessageExchangeDaoImpl.setStatus");
+        _hself.setState(status);
+        update();
+    }
+
+    public String getStatus() {
+        return _hself.getState();
+    }
+
+    public MessageDAO createMessage(QName type) {
+        entering("MessageExchangeDaoImpl.createMessage");
+        HMessage message = new HMessage();
+        message.setType(type == null ? null : type.toString());
+        message.setCreated(new Date());
+        message.setMessageExchange(_hself);
+        getSession().save(message);
+        return new MessageDaoImpl(_sm, message);
+
+    }
+
+    public void setRequest(MessageDAO msg) {
+        entering("MessageExchangeDaoImpl.setRequest");
+        _hself.setRequest(msg == null ? null : (HMessage) ((MessageDaoImpl) msg).getHibernateObj());
+        update();
+    }
+
+    public void setResponse(MessageDAO msg) {
+        entering("MessageExchangeDaoImpl.setResponse");
+        _hself.setResponse(msg == null ? null : (HMessage) ((MessageDaoImpl) msg).getHibernateObj());
+        update();
+    }
+
+    public int getPartnerLinkModelId() {
+        return _hself.getPartnerLinkModelId();
+    }
+
+    public void setPartnerLinkModelId(int modelId) {
+        entering("MessageExchangeDaoImpl.setPartnerLinkModelId");
+        _hself.setPartnerLinkModelId(modelId);
+        update();
+    }
+
+    public String getCorrelationId() {
+        return _hself.getClientKey();
+    }
+
+    public void setCorrelationId(String clientKey) {
+        entering("MessageExchangeDaoImpl.setCorrelationId");
+        _hself.setClientKey(clientKey);
+        update();
+    }
+
+    public void setPattern(String pattern) {
+        entering("MessageExchangeDaoImpl.setPattern");
+        _hself.setPattern(pattern);
+        update();
+
+    }
+
+    public void setOperation(String opname) {
+        entering("MessageExchangeDaoImpl.setOperation");
+        _hself.setOperationName(opname);
+        update();
+    }
+
+    public void setEPR(Element source) {
+        entering("MessageExchangeDaoImpl.setEPR");
+        if (source == null)
+            _hself.setEndpoint(null);
+        else {
+            _hself.setEndpoint(DOMUtils.domToBytes(source));
+        }
+
+        getSession().saveOrUpdate(_hself);
+
+    }
+
+    public Element getEPR() {
+        entering("MessageExchangeDaoImpl.getEPR");
+        byte[] endpoint = _hself.getEndpoint();
+        if (endpoint == null)
+            return null;
+        try {
+            return DOMUtils.stringToDOM(endpoint);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void setCallbackEPR(Element source) {
+        entering("MessageExchangeDaoImpl.setCallbackEPR");
+        if (source == null)
+            _hself.setCallbackEndpoint(null);
+        else {
+        	_hself.setCallbackEndpoint(DOMUtils.domToBytes(source));
+        }
+
+        getSession().saveOrUpdate(_hself);
+
+    }
+
+    public Element getCallbackEPR() {
+        entering("MessageExchangeDaoImpl.getCallbackEPR");
+        byte[] endpoint = _hself.getCallbackEndpoint();
+        if (endpoint == null)
+            return null;
+        try {
+            return DOMUtils.stringToDOM(endpoint);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public String getPattern() {
+        return _hself.getPattern();
+    }
+
+    public String getChannel() {
+        return _hself.getChannelName();
+    }
+
+    public void setChannel(String channel) {
+        entering("MessageExchangeDaoImpl.setChannel");
+        _hself.setChannelName(channel);
+        update();
+    }
+
+    public boolean getPropagateTransactionFlag() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public QName getFault() {
+        return _hself.getFault() == null ? null : QName.valueOf(_hself.getFault());
+    }
+
+    public void setFault(QName faultType) {
+        entering("MessageExchangeDaoImpl.setFault");
+        _hself.setFault(faultType == null ? null : faultType.toString());
+        update();
+    }
+
+    public String getFaultExplanation() {
+        return _hself.getFaultExplanation();
+    }
+
+    public void setFaultExplanation(String explanation) {
+        entering("MessageExchangeDaoImpl.setFaultExplanation");
+        _hself.setFaultExplanation(explanation);
+        update();
+    }
+
+    public void setCorrelationStatus(String cstatus) {
+        entering("MessageExchangeDaoImpl.setCorrelationStatus");
+        _hself.setCorrelationStatus(cstatus);
+        update();
+    }
+
+    public String getCorrelationStatus() {
+        return _hself.getCorrelationStatus();
+    }
+
+    public ProcessDAO getProcess() {
+        entering("MessageExchangeDaoImpl.getProcess");
+        if (_externalProcess != null) return _externalProcess;
+        else return _hself.getProcess() == null ? null : new ProcessDaoImpl(_sm, _hself.getProcess());
+    }
+
+    public void setProcess(ProcessDAO process) {
+        entering("MessageExchangeDaoImpl.setProcess");
+        if (process == null || process instanceof ProcessDaoImpl) {
+        _hself.setProcess(process == null ? null : (HProcess) ((ProcessDaoImpl) process).getHibernateObj());
+        update();
+        } else {
+            _externalProcess = process;
+    }
+    }
+
+    public void setInstance(ProcessInstanceDAO instance) {
+        entering("MessageExchangeDaoImpl.setInstance");
+        if (instance == null || instance instanceof ProcessInstanceDaoImpl) {
+        _hself.setInstance(instance == null ? null : (HProcessInstance) ((ProcessInstanceDaoImpl) instance)
+                .getHibernateObj());
+        update();
+        } else {
+            _externalInstance = instance;
+    }
+
+    }
+
+    public ProcessInstanceDAO getInstance() {
+        entering("MessageExchangeDaoImpl.getInstance");
+        if (_externalInstance != null) return _externalInstance;
+        else return _hself.getInstance() == null ? null : new ProcessInstanceDaoImpl(_sm, _hself.getInstance());
+    }
+
+    public char getDirection() {
+        return _hself.getDirection();
+    }
+
+    public QName getCallee() {
+        String callee = _hself.getCallee();
+        return callee == null ? null : QName.valueOf(callee);
+    }
+
+    public void setCallee(QName callee) {
+        entering("MessageExchangeDaoImpl.setCallee");
+        _hself.setCallee(callee == null ? null : callee.toString());
+        update();
+    }
+
+    public String getProperty(String key) {
+        entering("MessageExchangeDaoImpl.getProperty");
+        return _hself.getProperties().get(key);
+    }
+
+    public void setProperty(String key, String value) {
+        entering("MessageExchangeDaoImpl.setProperty");
+        _hself.getProperties().put(key, value);
+        update();
+    }
+
+    public void setPartnerLink(PartnerLinkDAO plinkDAO) {
+        entering("MessageExchangeDaoImpl.setPartnerLink");
+        _hself.setPartnerLink(((PartnerLinkDAOImpl) plinkDAO)._self);
+        update();
+    }
+
+    public PartnerLinkDAO getPartnerLink() {
+        entering("MessageExchangeDaoImpl.getPartnerLink");
+        return new PartnerLinkDAOImpl(_sm, _hself.getPartnerLink());
+    }
+
+    public Set<String> getPropertyNames() {
+        entering("MessageExchangeDaoImpl.getPropertyNames");
+        return Collections.unmodifiableSet(_hself.getProperties().keySet());
+    }
+
+    public String getPipedMessageExchangeId() {
+        return _hself.getPipedMessageExchangeId();
+    }
+
+    public void setPipedMessageExchangeId(String mexId) {
+        entering("MessageExchangeDaoImpl.setPipedMessageExchangeId");
+        _hself.setPipedMessageExchangeId(mexId);
+    }
+
+    public int getSubscriberCount() {
+        return _hself.getSubscriberCount();
+    }
+    
+    public void setSubscriberCount(int subscriberCount) {
+        _hself.setSubscriberCount(subscriberCount);        
+    }
+    
+    public void release(boolean doClean) {
+        if( doClean ) {
+            deleteMessages();
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public void releasePremieMessages() {
+        deleteByIds(HCorrelatorMessage.class, getSession().getNamedQuery(HCorrelatorMessage.SELECT_CORMESSAGE_IDS_BY_MEX).setParameter("mex", _hself).list());
+    }
+
+    public void incrementSubscriberCount() {
+        _hself.incrementSubscriberCount();
+    }
+    
+    @SuppressWarnings("unchecked")
+    public void deleteMessages() {
+        deleteByIds(HCorrelatorMessage.class, getSession().getNamedQuery(HCorrelatorMessage.SELECT_CORMESSAGE_IDS_BY_MEX).setParameter("mex", _hself).list());
+          
+        getSession().delete(_hself);
+        // This deletes endpoint LData, callbackEndpoint LData, request HMessage, response HMessage, HMessageExchangeProperty 
+    }
+    
+}

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageRouteDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageRouteDaoImpl.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageRouteDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/MessageRouteDaoImpl.java Fri May 21 15:40:59 2010
@@ -0,0 +1,95 @@
+/*
+ * 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.hib.bpel;
+
+import org.apache.ode.bpel.common.CorrelationKeySet;
+import org.apache.ode.dao.bpel.MessageRouteDAO;
+import org.apache.ode.dao.bpel.ProcessInstanceDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelatorSelector;
+import org.apache.ode.dao.hib.bpel.hobj.HProcessInstance;
+import org.apache.ode.bpel.common.CorrelationKey;
+import org.hibernate.Query;
+
+/**
+ * Hibernate-based {@link MessageRouteDAO} implementation.
+ */
+class MessageRouteDaoImpl extends HibernateDao implements MessageRouteDAO {
+
+    private static final String LOCK_INSTANCE = "update " + HProcessInstance.class.getName()
+            + " set lock=lock+1 where id=?";
+
+    private HCorrelatorSelector _selector;
+
+    private boolean _locked = false;
+
+    public MessageRouteDaoImpl(SessionManager sm, HCorrelatorSelector hobj) {
+        super(sm, hobj);
+        entering("MessageRouteDaoImpl.MessageRouteDaoImpl");
+        _selector = hobj;
+    }
+
+    /**
+     * @see org.apache.ode.bpel.dao.MessageRouteDAO#getTargetInstance()
+     */
+    public ProcessInstanceDAO getTargetInstance() {
+        entering("MessageRouteDaoImpl.getTargetInstance");
+        // First we need to reliably lock the instance:
+        if (!_locked) {
+            Query q = getSession().createQuery(LOCK_INSTANCE);
+            q.setLong(0, _selector.getInstance().getId());
+            q.executeUpdate();
+            _locked = true;
+        }
+
+        // now it is safe to return
+        return new ProcessInstanceDaoImpl(_sm, _selector.getInstance());
+    }
+
+    public String getGroupId() {
+        entering("MessageRouteDaoImpl.getGroupId");
+        return _selector.getGroupId();
+    }
+
+    public int getIndex() {
+        entering("MessageRouteDaoImpl.getIndex");
+        return _selector.getIndex();
+    }
+    
+    public String getRoute() {
+    	return _selector.getRoute();
+    }
+
+	public CorrelationKeySet getCorrelationKeySet() {
+		return new CorrelationKeySet(_selector.getCorrelationKey());
+	}
+
+    public void setCorrelationKeySet(CorrelationKeySet keySet) {
+        _selector.setCorrelationKey(keySet.toCanonicalString());
+    }
+
+    public void setCorrelationKey(CorrelationKey key) {
+         _selector.setCorrelationKey(key.toCanonicalString());
+     }
+
+     public CorrelationKey getCorrelationKey() {
+         return new CorrelationKey(_selector.getCorrelationKey());
+     }
+
+}

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/PartnerLinkDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/PartnerLinkDAOImpl.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/PartnerLinkDAOImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/PartnerLinkDAOImpl.java Fri May 21 15:40:59 2010
@@ -0,0 +1,146 @@
+/*
+ * 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.hib.bpel;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.dao.bpel.PartnerLinkDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HPartnerLink;
+import org.apache.ode.utils.DOMUtils;
+import org.w3c.dom.Element;
+
+/**
+ * Hibernate based {EndpointReferenceDAO} implementation. can either be related
+ * to a scope (when it's specific to a scope instance, for example because it
+ * has been assigned during the instance execution) or to a process definition
+ * (general endpoint configuration).
+ */
+public class PartnerLinkDAOImpl extends HibernateDao implements PartnerLinkDAO {
+
+
+    /** Cached copy of my epr */
+    private Element _myEPR;
+
+    /** Cached copy of partner epr. */
+    private Element _partnerEPR;
+
+    HPartnerLink _self;
+
+    public PartnerLinkDAOImpl(SessionManager sessionManager, HPartnerLink hobj) {
+        super(sessionManager, hobj);
+        entering("PartnerLinkDAOImpl.PartnerLinkDAOImpl");
+        _self = hobj;
+    }
+
+    public String getPartnerLinkName() {
+        return _self.getLinkName();
+    }
+
+    public String getPartnerRoleName() {
+        return _self.getPartnerRole();
+    }
+
+    public String getMyRoleName() {
+        return _self.getMyRole();
+    }
+
+    public int getPartnerLinkModelId() {
+        return _self.getModelId();
+    }
+
+    public QName getMyRoleServiceName() {
+        return _self.getServiceName() == null ? null : QName.valueOf(_self.getServiceName());
+    }
+
+    public void setMyRoleServiceName(QName svcName) {
+        entering("PartnerLinkDAOImpl.setMyRoleServiceName");
+        _self.setServiceName(svcName == null ? null : svcName.toString());
+        update();
+    }
+
+    public Element getMyEPR() {
+        entering("PartnerLinkDAOImpl.getMyEPR");
+        if (_myEPR != null)
+            return _myEPR;
+        if (_self.getMyEPR() == null)
+            return null;
+        try {
+            return DOMUtils.stringToDOM(_self.getMyEPR());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void setMyEPR(Element val) {
+        entering("PartnerLinkDAOImpl.setMyEPR");
+        _myEPR = val;
+        if (val == null) {
+            _self.setMyEPR(null);
+        } else {
+            _self.setMyEPR(DOMUtils.domToBytes(val));
+        }
+        getSession().update(_self);
+    }
+
+    public Element getPartnerEPR() {
+        entering("PartnerLinkDAOImpl.getPartnerEPR");
+        if (_partnerEPR != null)
+            return _partnerEPR;
+        if (_self.getPartnerEPR() == null)
+            return null;
+        try {
+            return _partnerEPR = DOMUtils.stringToDOM(_self.getPartnerEPR());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void setPartnerEPR(Element val) {
+        entering("PartnerLinkDAOImpl.setPartnerEPR");
+        _partnerEPR = val;
+        if (val == null) {
+            _self.setPartnerEPR(null);
+        } else {
+            _self.setPartnerEPR(DOMUtils.domToBytes(val));
+        }
+        getSession().update(_self);
+    }
+
+    public String getMySessionId() {
+        return _self.getMySessionId();
+    }
+
+    public String getPartnerSessionId() {
+        return _self.getPartnerSessionId();
+    }
+
+    public void setPartnerSessionId(String session) {
+        entering("PartnerLinkDAOImpl.setPartnerSessionId");
+        _self.setPartnerSessionId(session);
+    }
+
+    public void setMySessionId(String sessionId) {
+        entering("PartnerLinkDAOImpl.setMySessionId");
+        _self.setMySessionId(sessionId);
+
+    }
+
+}

Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessDaoImpl.java?rev=947046&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessDaoImpl.java Fri May 21 15:40:59 2010
@@ -0,0 +1,299 @@
+/*
+ * 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.hib.bpel;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.CorrelationKey;
+import org.apache.ode.bpel.common.ProcessState;
+import org.apache.ode.dao.bpel.CorrelatorDAO;
+import org.apache.ode.dao.bpel.DeferredProcessInstanceCleanable;
+import org.apache.ode.dao.bpel.ProcessDAO;
+import org.apache.ode.dao.bpel.ProcessInstanceDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HActivityRecovery;
+import org.apache.ode.dao.hib.bpel.hobj.HBpelEvent;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelationProperty;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelationSet;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelator;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelatorMessage;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelatorSelector;
+import org.apache.ode.dao.hib.bpel.hobj.HFaultData;
+import org.apache.ode.dao.hib.bpel.hobj.HMessage;
+import org.apache.ode.dao.hib.bpel.hobj.HMessageExchange;
+import org.apache.ode.dao.hib.bpel.hobj.HMessageExchangeProperty;
+import org.apache.ode.dao.hib.bpel.hobj.HPartnerLink;
+import org.apache.ode.dao.hib.bpel.hobj.HProcess;
+import org.apache.ode.dao.hib.bpel.hobj.HProcessInstance;
+import org.apache.ode.dao.hib.bpel.hobj.HScope;
+import org.apache.ode.dao.hib.bpel.hobj.HVariableProperty;
+import org.apache.ode.dao.hib.bpel.hobj.HXmlData;
+import org.apache.ode.bpel.iapi.ProcessConf.CLEANUP_CATEGORY;
+import org.hibernate.Criteria;
+import org.hibernate.Hibernate;
+import org.hibernate.Query;
+import org.hibernate.StaleStateException;
+import org.hibernate.UnresolvableObjectException;
+import org.hibernate.criterion.Expression;
+import org.hibernate.criterion.Order;
+
+/**
+ * Hibernate-based {@link ProcessDAO} implementation.
+ */
+public class ProcessDaoImpl extends HibernateDao implements ProcessDAO, DeferredProcessInstanceCleanable {
+    private static final Log __log = LogFactory.getLog(ProcessDaoImpl.class);
+
+    private static final String QRY_CORRELATOR = "where this.correlatorId = ?";
+
+    private HProcess _process;
+
+    public ProcessDaoImpl(SessionManager sm, HProcess process) {
+        super(sm,process);
+        entering("ProcessDaoImpl.ProcessDaoImpl");
+        _process = process;
+    }
+
+    public QName getProcessId() {
+        return QName.valueOf(_process.getProcessId());
+    }
+
+    public ProcessInstanceDAO getInstance(Long iid) {
+        entering("ProcessDaoImpl.getInstance");
+        ProcessInstanceDAO instance = BpelDAOConnectionImpl._getInstance(_sm, getSession(), iid);
+        if (instance == null || !instance.getProcess().getProcessId().equals(getProcessId()))
+            return null;
+        return instance;
+    }
+
+    @SuppressWarnings("unchecked")
+    public CorrelatorDAO getCorrelator(String  corrId) {
+        entering("ProcessDaoImpl.getCorrelator");
+        Iterator results;
+        Query q = getSession().createFilter(_process.getCorrelators(),
+                QRY_CORRELATOR);
+        results = q.setString(0, corrId).iterate();
+
+        if(!results.hasNext()){
+            String msg = "no such correlator: corrId = " + corrId;
+            throw new IllegalArgumentException(msg);
+        }
+        try {
+            return new CorrelatorDaoImpl(_sm, (HCorrelator)results.next());
+        } finally {
+            Hibernate.close(results);
+        }
+    }
+
+    public void removeRoutes(String routeId, ProcessInstanceDAO target) {
+        entering("ProcessDaoImpl.removeRoutes");
+        for (HCorrelator hCorrelator : _process.getCorrelators()) {
+            new CorrelatorDaoImpl(_sm, hCorrelator).removeRoutes(routeId, target);
+        }
+    }
+
+    public ProcessInstanceDAO createInstance(CorrelatorDAO correlator) {
+        entering("ProcessDaoImpl.createInstance");
+        HProcessInstance instance = new HProcessInstance();
+        instance.setInstantiatingCorrelator((HCorrelator)((CorrelatorDaoImpl)correlator).getHibernateObj());
+        instance.setProcess(_process);
+        instance.setCreated(new Date());
+        getSession().save(instance);
+//        _process.addInstance(instance);
+
+        return new ProcessInstanceDaoImpl(_sm,instance);
+    }
+
+    /**
+     * @see org.apache.ode.bpel.dao.ProcessDAO#findInstance(CorrelationKey)
+     */
+    @SuppressWarnings("unchecked")
+    public Collection<ProcessInstanceDAO> findInstance(CorrelationKey ckeyValue) {
+        entering("ProcessDaoImpl.findInstance");
+        Criteria criteria = getSession().createCriteria(HCorrelationSet.class);
+        criteria.add(Expression.eq("scope.instance.process.id",_process.getId()));
+        criteria.add(Expression.eq("value", ckeyValue.toCanonicalString()));
+        criteria.addOrder(Order.desc("scope.instance.created"));
+        return criteria.list();
+    }
+
+    /**
+     * @see org.apache.ode.bpel.dao.ProcessDAO#instanceCompleted(ProcessInstanceDAO)
+     */
+    public void instanceCompleted(ProcessInstanceDAO instance) {
+        // nothing to do here (yet?)
+    }
+
+    @SuppressWarnings("unchecked")
+    public void deleteProcessAndRoutes() {
+        // delete routes
+        deleteByIds(HCorrelatorSelector.class, getSession().getNamedQuery(HCorrelatorSelector.SELECT_MESSAGE_ROUTE_IDS_BY_PROCESS).setParameter("process", _process).list());
+
+        // delete process dao
+        deleteByIds(HCorrelator.class, getSession().getNamedQuery(HCorrelator.SELECT_CORRELATOR_IDS_BY_PROCESS).setParameter("process", _process).list());
+        try {
+            getSession().refresh(_process);
+            getSession().delete(_process); // this deletes HCorrelator -> HCorrelatorSelector
+
+            // after this delete, we have a use case that creates the process with the same procid.
+            // for hibernate to work without the database deferred constraint check, let's just flush the session.
+            getSession().flush();
+        } catch( UnresolvableObjectException sse ) {
+            __log.debug("Process: " + getProcessId() + " has been already deleted.");
+            // don't sweat, they already deleted by another thread or process
+        } catch( StaleStateException sse ) {
+            __log.debug("Process: " + getProcessId() + " has been already deleted.");
+            // don't sweat, they already deleted by another thread or process
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    public int deleteInstances(int transactionSize) {
+        entering("ProcessDaoImpl.delete");
+
+        if( transactionSize < 1 ) {
+               if(__log.isWarnEnabled()) __log.warn("A zero or negative value was given for the transaction size of process dao deletion; overriding to '1'. Not using bulk deletion of rows may result in performance degradation.");
+               transactionSize = 1;
+        }
+
+        Collection<HProcessInstance> instances = getSession().getNamedQuery(HProcessInstance.SELECT_INSTANCES_BY_PROCESS).setParameter("process", _process).setMaxResults(transactionSize).list();
+        if( !instances.isEmpty() ) {
+            deleteEvents(instances);
+            deleteCorrelations(instances);
+            deleteMessages(instances);
+            deleteVariables(instances);
+            deleteProcessInstances(instances);
+        }
+
+        return instances.size();
+    }
+
+    public int deleteInstances(Collection<HProcessInstance> instances, Set<CLEANUP_CATEGORY> categories) {
+        entering("ProcessDaoImpl.deleteInstances");
+
+        if( !instances.isEmpty() ) {
+            if( categories.contains(CLEANUP_CATEGORY.EVENTS)) {
+                deleteEvents(instances);
+            }
+            if( categories.contains(CLEANUP_CATEGORY.CORRELATIONS)) {
+                deleteCorrelations(instances);
+            }
+            if( categories.contains(CLEANUP_CATEGORY.MESSAGES)) {
+                deleteMessages(instances);
+            }
+            if( categories.contains(CLEANUP_CATEGORY.VARIABLES)) {
+                deleteVariables(instances);
+            }
+            if( categories.contains(CLEANUP_CATEGORY.INSTANCE)) {
+                deleteProcessInstances(instances);
+            }
+        }
+
+        return instances.size();
+    }
+
+    @SuppressWarnings("unchecked")
+    private void deleteProcessInstances(Collection<HProcessInstance> instances) {
+        deleteByIds(HActivityRecovery.class, getSession().getNamedQuery(HActivityRecovery.SELECT_ACTIVITY_RECOVERY_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+        deleteByIds(HFaultData.class, getSession().getNamedQuery(HFaultData.SELECT_FAULT_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+
+        List<Long> instanceIds = new ArrayList<Long>();
+        for( HProcessInstance instance : instances ) {
+            instanceIds.add(instance.getId());
+        }
+        deleteByIds(HProcessInstance.class, instanceIds);
+    }
+
+    @SuppressWarnings("unchecked")
+    private void deleteVariables(Collection<HProcessInstance> instances) {
+        deleteByIds(HVariableProperty.class, getSession().getNamedQuery(HVariableProperty.SELECT_VARIABLE_PROPERTY_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+        deleteByIds(HXmlData.class, getSession().getNamedQuery(HXmlData.SELECT_XMLDATA_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+        deleteByIds(HPartnerLink.class, getSession().getNamedQuery(HPartnerLink.SELECT_PARTNER_LINK_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+        deleteByIds(HScope.class, getSession().getNamedQuery(HScope.SELECT_SCOPE_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+    }
+
+    @SuppressWarnings("unchecked")
+    private void deleteMessages(Collection<HProcessInstance> instances) {
+        deleteByIds(HActivityRecovery.class, getSession().getNamedQuery(HCorrelatorMessage.SELECT_CORMESSAGE_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+        deleteByIds(HMessage.class, getSession().getNamedQuery(HMessage.SELECT_MESSAGE_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+        List<Long> mex = getSession().getNamedQuery(HMessageExchange.SELECT_MEX_IDS_BY_INSTANCES).setParameterList("instances", instances).list();
+        deleteByColumn(HMessageExchangeProperty.class, "mex.id", mex);
+        deleteByIds(HMessageExchange.class, mex);
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void deleteCorrelations(Collection<HProcessInstance> instances) {
+        deleteByIds(HCorrelationProperty.class, getSession().getNamedQuery(HCorrelationProperty.SELECT_CORPROP_IDS_BY_INSTANCES).setParameterList ("instances", instances).list());
+        deleteByIds(HCorrelationSet.class, getSession().getNamedQuery(HCorrelationSet.SELECT_CORSET_IDS_BY_INSTANCES).setParameterList ("instances", instances).list());
+    }
+
+    @SuppressWarnings("unchecked")
+    private void deleteEvents(Collection<HProcessInstance> instances) {
+        deleteByIds(HBpelEvent.class, getSession().getNamedQuery(HBpelEvent.SELECT_EVENT_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+    }
+
+    public QName getType() {
+        return new QName(_process.getTypeNamespace(), _process.getTypeName());
+    }
+
+    public long getVersion() {
+        return _process.getVersion();
+    }
+
+    public CorrelatorDAO addCorrelator(String corrid) {
+        entering("ProcessDaoImpl.addCorrelator");
+        HCorrelator correlator = new HCorrelator();
+        correlator.setCorrelatorId(corrid);
+        correlator.setProcess(_process);
+        correlator.setCreated(new Date());
+//        _process.addCorrelator(correlator);
+        getSession().save(correlator);
+        getSession().saveOrUpdate(_process);
+        return new CorrelatorDaoImpl(_sm, correlator);
+    }
+
+    @SuppressWarnings("unchecked")
+    public Collection<ProcessInstanceDAO> getActiveInstances() {
+        ArrayList<ProcessInstanceDAO> instDaos = new ArrayList<ProcessInstanceDAO>();
+        Collection<HProcessInstance> insts = getSession().getNamedQuery(HProcessInstance.SELECT_INSTANCES_BY_PROCESS_AND_STATES)
+                .setParameter("process", _process).setParameterList("states", new Object[] {ProcessState.STATE_ACTIVE}).list();
+        for (HProcessInstance inst : insts)
+            instDaos.add(new ProcessInstanceDaoImpl(_sm, inst));
+        return instDaos;
+    }
+
+    public int getNumInstances() {
+        entering("ProcessDaoImpl.getNumInstances");
+        // this should be efficient if the relation is tagged as extra-lazy.
+        // If the collection is not initialized yet, Hibernate will do a count(*) and the whole collection will not be fetched.
+        return _process.getInstances().size();
+    }
+
+    public String getGuid() {
+        return _process.getGuid();
+    }
+}