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 [6/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/o...
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelationSetDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelationSetDaoImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelationSetDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelationSetDaoImpl.java Sun May 2 17:02:51 2010
@@ -0,0 +1,104 @@
+/*
+ * 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.CorrelationSetDAO;
+import org.apache.ode.dao.bpel.ScopeDAO;
+import org.apache.ode.bpel.common.CorrelationKey;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelationSet;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelationProperty;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Hibernate-based {@link CorrelationSetDAO} implementation.
+ */
+class CorrelationSetDaoImpl extends HibernateDao
+ implements CorrelationSetDAO {
+
+ private HCorrelationSet _correlationSet;
+
+ public CorrelationSetDaoImpl(SessionManager sessionManager, HCorrelationSet correlationSet) {
+ super(sessionManager, correlationSet);
+ entering("CorrelationSetDaoImpl.CorrelationSetDaoImpl");
+ _correlationSet = correlationSet;
+ }
+
+ public Long getCorrelationSetId() {
+ return _correlationSet.getId();
+ }
+
+ public String getName() {
+ return _correlationSet.getName();
+ }
+
+ public ScopeDAO getScope() {
+ entering("CorrelationSetDaoImpl.getScope");
+ return new ScopeDaoImpl(_sm, _correlationSet.getScope());
+ }
+
+ public void setValue(QName[] names, CorrelationKey values) {
+ entering("CorrelationSetDaoImpl.setValue");
+ _correlationSet.setValue(values.toCanonicalString());
+ if (_correlationSet.getProperties() == null || _correlationSet.getProperties().size() == 0) {
+ for (int m = 0; m < names.length; m++) {
+ HCorrelationProperty prop =
+ new HCorrelationProperty(names[m], values.getValues()[m], _correlationSet);
+ getSession().save(prop);
+ }
+ } else {
+ for (int m = 0; m < names.length; m++) {
+ HCorrelationProperty prop = getProperty(names[m]);
+ if (prop == null) prop = new HCorrelationProperty(names[m], values.getValues()[m], _correlationSet);
+ else prop.setValue(values.getValues()[m]);
+ getSession().save(prop);
+ }
+ }
+ getSession().update(_correlationSet);
+ }
+
+ public CorrelationKey getValue() {
+ entering("CorrelationSetDaoImpl.getValue");
+ if (_correlationSet.getValue() != null) return new CorrelationKey(_correlationSet.getValue());
+ else return null;
+ }
+
+ public Map<QName, String> getProperties() {
+ entering("CorrelationSetDaoImpl.getProperties");
+ HashMap<QName, String> result = new HashMap<QName, String>();
+ for (HCorrelationProperty property : _correlationSet.getProperties()) {
+ result.put(property.getQName(), property.getValue());
+ }
+ return result;
+ }
+
+ private HCorrelationProperty getProperty(QName qName) {
+ entering("CorrelationSetDaoImpl.getProperty");
+ for (HCorrelationProperty property : _correlationSet.getProperties()) {
+ if (qName.getLocalPart().equals(property.getName())
+ && qName.getNamespaceURI().equals(property.getNamespace()))
+ return property;
+ }
+ return null;
+ }
+
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelatorDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelatorDaoImpl.java?rev=940263&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelatorDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/CorrelatorDaoImpl.java Sun May 2 17:02:51 2010
@@ -0,0 +1,244 @@
+/*
+ * 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.Date;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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 org.apache.ode.dao.hib.SessionManager;
+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.HMessageExchange;
+import org.apache.ode.dao.hib.bpel.hobj.HProcessInstance;
+import org.apache.ode.utils.CollectionUtils;
+import org.hibernate.Hibernate;
+import org.hibernate.LockMode;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Hibernate-based {@link CorrelatorDAO} implementation.
+ */
+class CorrelatorDaoImpl extends HibernateDao implements CorrelatorDAO {
+
+ /**
+ * Note: the hk.messageExchange=null is a hack to get around a Hibernate bug where the query
+ * does not properly discriminate for the proper subclass.
+ */
+ private static final String QRY_MESSAGE = " where this.correlationKey = ?".intern();
+
+ /** filter for finding a matching selector. */
+ private static final String FLTR_SELECTORS = ("from " + HCorrelatorSelector.class.getName()
+ + " hs where hs.correlationKey = ? and hs.processType = ? and hs.correlator.correlatorId = ?").intern();
+ private static final String FLTR_SELECTORS_SUBQUERY = ("from " + HCorrelatorSelector.class.getName()
+ + " hs where hs.correlationKey = ? and hs.processType = ? and hs.correlatorId = " +
+ "(select hc.id from " + HCorrelator.class.getName() + " hc where hc.correlatorId = ? )").intern();
+
+
+ private static final String LOCK_SELECTORS = "update from " + HCorrelatorSelector.class.getName() +
+ " set lock = lock+1 where correlationKey = ? and processType = ?".intern();
+
+ /** Query for removing routes. */
+ private static final String QRY_DELSELECTORS = "delete from " + HCorrelatorSelector.class.getName()
+ + " where groupId = ? and instance = ?".intern();
+
+ private static final String QRY_DELMESSAGES = "delete from " + HCorrelatorMessage.class.getName()
+ + " where messageExchange = ?".intern();
+
+ static Log __log = LogFactory.getLog(CorrelatorDaoImpl.class);
+
+ private HCorrelator _hobj;
+
+ public CorrelatorDaoImpl(SessionManager sm, HCorrelator hobj) {
+ super(sm, hobj);
+ entering("CorrelatorDaoImpl.CorrelatorDaoImpl");
+ _hobj = hobj;
+ }
+
+ public MessageExchangeDAO dequeueMessage(CorrelationKey key) {
+ entering("CorrelatorDaoImpl.dequeueMessage");
+ String hdr = "dequeueMessage(" + key + "): ";
+ __log.debug(hdr);
+
+ Query qry = getSession().createFilter(_hobj.getMessageCorrelations(), QRY_MESSAGE);
+ qry.setString(0, key.toCanonicalString());
+
+ // We really should consider the possibility of multiple messages matching a criteria.
+ // When the message is handled, its not too convenient to attempt to determine if the
+ // received message conflicts with one already received.
+ Iterator mcors = qry.iterate();
+ try {
+ if (!mcors.hasNext()) {
+ __log.debug(hdr + "did not find a MESSAGE entry.");
+ return null;
+ }
+
+ HCorrelatorMessage mcor = (HCorrelatorMessage) mcors.next();
+ __log.debug(hdr + "found MESSAGE entry " + mcor.getMessageExchange());
+ removeEntries(mcor.getMessageExchange());
+ return new MessageExchangeDaoImpl(_sm, mcor.getMessageExchange());
+ } finally {
+ Hibernate.close(mcors);
+ }
+ }
+
+ public MessageRouteDAO findRoute(CorrelationKey key) {
+ entering("CorrelatorDaoImpl.findRoute");
+ String hdr = "findRoute(key=" + key + "): ";
+ if (__log.isDebugEnabled())
+ __log.debug(hdr);
+
+ // Make sure we obtain a lock for the selector we want to find. Note that a SELECT FOR UPDATE
+ // will not necessarily work, as different DB vendors attach a different meaning to this syntax.
+ // In particular it is not clear how long the lock should be held, for the lifetime of the
+ // resulting cursor, or for the lifetime of the transaction. So really, an UPDATE of the row
+ // is a much safer alternative.
+ String processType = new QName(_hobj.getProcess().getTypeNamespace(), _hobj.getProcess().getTypeName()).toString();
+ Query lockQry = getSession().createQuery(LOCK_SELECTORS);
+ lockQry.setString(0, key == null ? null : key.toCanonicalString());
+ lockQry.setString(1, processType);
+ if (lockQry.executeUpdate() > 0) {
+
+ Query q = getSession().createQuery(_sm.canJoinForUpdate() ? FLTR_SELECTORS : FLTR_SELECTORS_SUBQUERY);
+ q.setString(0, key == null ? null : key.toCanonicalString());
+ q.setString(1, processType);
+ q.setString(2, _hobj.getCorrelatorId());
+ q.setLockMode("hs", LockMode.UPGRADE);
+
+ HCorrelatorSelector selector;
+ try {
+ selector = (HCorrelatorSelector) q.uniqueResult();
+ } catch (Exception ex) {
+ __log.debug("Strange, could not get a unique result for findRoute, trying to iterate instead.");
+
+ Iterator i = q.iterate();
+ if (i.hasNext()) selector = (HCorrelatorSelector) i.next();
+ else selector = null;
+ Hibernate.close(i);
+ }
+
+ __log.debug(hdr + "found " + selector);
+ return selector == null ? null : new MessageRouteDaoImpl(_sm, selector);
+ }
+
+ return null;
+ }
+
+ public void enqueueMessage(MessageExchangeDAO mex, CorrelationKey[] correlationKeys) {
+ entering("CorrelatorDaoImpl.enqueueMessage");
+ String[] keys = canonifyKeys(correlationKeys);
+ String hdr = "enqueueMessage(mex=" + ((MessageExchangeDaoImpl) mex)._hobj.getId() + " keys="
+ + CollectionUtils.makeCollection(ArrayList.class, keys) + "): ";
+
+ if (__log.isDebugEnabled())
+ __log.debug(hdr);
+
+ for (String key : keys) {
+ HCorrelatorMessage mcor = new HCorrelatorMessage();
+ mcor.setCorrelator(_hobj);
+ mcor.setCreated(new Date());
+ mcor.setCorrelationKey(key);
+ mcor.setMessageExchange((HMessageExchange) ((MessageExchangeDaoImpl) mex)._hobj);
+ getSession().save(mcor);
+
+ if (__log.isDebugEnabled())
+ __log.debug(hdr + "saved " + mcor);
+ }
+
+ }
+
+ private String[] canonifyKeys(CorrelationKey[] keys) {
+ String[] ret = new String[keys.length];
+ for (int i = 0; i < ret.length; ++i) {
+ ret[i] = keys[i].toCanonicalString();
+ }
+ return ret;
+ }
+
+ public void addRoute(String routeGroupId, ProcessInstanceDAO target, int idx, CorrelationKey correlationKey) {
+ entering("CorrelatorDaoImpl.addRoute");
+ String hdr = "addRoute(" + routeGroupId + ", iid=" + target.getInstanceId() + ", idx=" + idx + ", ckey="
+ + correlationKey + "): ";
+
+ __log.debug(hdr);
+ HCorrelatorSelector hsel = new HCorrelatorSelector();
+ hsel.setGroupId(routeGroupId);
+ hsel.setIndex(idx);
+ hsel.setLock(0);
+ hsel.setCorrelationKey(correlationKey.toCanonicalString());
+ hsel.setInstance((HProcessInstance) ((ProcessInstanceDaoImpl) target).getHibernateObj());
+ hsel.setProcessType(target.getProcess().getType().toString());
+ hsel.setCorrelator(_hobj);
+ hsel.setCreated(new Date());
+// _hobj.addSelector(hsel);
+ getSession().save(hsel);
+
+ __log.debug(hdr + "saved " + hsel);
+ }
+
+ public boolean checkRoute(CorrelationKey ckey) {
+ entering("CorrelatorDaoImpl.checkRoute");
+ Query lockQry = getSession().createQuery(LOCK_SELECTORS);
+ lockQry.setString("ckey", ckey == null ? null : ckey.toCanonicalString());
+ lockQry.setEntity("corr",_hobj);
+ lockQry.setReadOnly(true);
+ return lockQry.list().isEmpty();
+
+ }
+ public String getCorrelatorId() {
+ return _hobj.getCorrelatorId();
+ }
+
+ public void removeRoutes(String routeGroupId, ProcessInstanceDAO target) {
+ entering("CorrelatorDaoImpl.removeRoutes");
+ String hdr = "removeRoutes(" + routeGroupId + ", iid=" + target.getInstanceId() + "): ";
+ __log.debug(hdr);
+ Session session = getSession();
+ Query q = session.createQuery(QRY_DELSELECTORS);
+ q.setString(0, routeGroupId); // groupId
+ q.setEntity(1, ((ProcessInstanceDaoImpl) target).getHibernateObj()); // instance
+ int updates = q.executeUpdate();
+ session.flush(); // explicit flush to ensure route removed
+ __log.debug(hdr + "deleted " + updates + " rows");
+
+ }
+
+ public void removeEntries(HMessageExchange mex) {
+ entering("CorrelatorDaoImpl.removeEntries");
+ String hdr = "removeEntries(" + mex + "): ";
+ __log.debug(hdr);
+
+ Query q = getSession().createQuery(QRY_DELMESSAGES);
+ q.setEntity(0, mex); // messageExchange
+ int numMods = q.executeUpdate();
+ __log.debug(hdr + " deleted " + numMods + " rows");
+ }
+
+}
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=940263&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 Sun May 2 17:02:51 2010
@@ -0,0 +1,409 @@
+/*
+ * 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.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, 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();
+ for (int m = 0; m < pids.size(); m++) {
+ filters.append(" pi.process.processId =").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(" ", " ");
+ 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) {
+ disj.add(Restrictions.eq("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 = ISO8601DateParser.parse(getDateWithoutOp(prefixedDate));
+ } catch (ParseException e) {
+ // Never occurs, the deploy date format is pre-validated by the filter
+ }
+ addFilterOnPrefixedDate(crit,prefixedDate,realDate,dateAttribute);
+ }
+
+ 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=940263&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 Sun May 2 17:02:51 2010
@@ -0,0 +1,74 @@
+/*
+ * 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.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;
+
+import javax.xml.namespace.QName;
+import java.io.IOException;
+
+/**
+ * Hibernate based {@link FaultDAO} implementation
+ */
+public class FaultDAOImpl extends HibernateDao implements FaultDAO {
+
+
+ HFaultData _self;
+
+ public FaultDAOImpl(SessionManager sm, HFaultData fault) {
+ super(sm, fault);
+ if (logDao.isDebugEnabled()) logDao.debug("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().getText());
+ } 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=940263&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 Sun May 2 17:02:51 2010
@@ -0,0 +1,133 @@
+/*
+ * 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.Collection;
+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.dao.bpel' 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.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);
+ }
+
+ public static Object[] toIdArray(Collection<? extends HibernateDao> daos) {
+ Object[] ids = new Object[daos.size()];
+
+ int index = 0;
+ for( HibernateDao dao : daos ) {
+ ids[index++] = dao.getId();
+ }
+
+ return ids;
+ }
+
+ @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=940263&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 Sun May 2 17:02:51 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=940263&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 Sun May 2 17:02:51 2010
@@ -0,0 +1,100 @@
+/*
+ * 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.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HLargeData;
+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;
+ if (_hself.getMessageData() != null)
+ _session.delete(_hself.getMessageData());
+ HLargeData newdata = new HLargeData(DOMUtils.domToString(value));
+ _session.save(newdata);
+ _hself.setMessageData(newdata);
+ update();
+ leaving("MessageDaoImpl.setData");
+ }
+
+ public Element getData() {
+ entering("MessageDaoImpl.getData");
+ if (_hself.getMessageData() == null)
+ return null;
+ try {
+ return DOMUtils.stringToDOM(_hself.getMessageData().getText());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setHeader(Element value) {
+ entering("MessageDaoImpl.setHeader");
+ if (value == null) return;
+ if (_hself.getHeader() != null)
+ _session.delete(_hself.getHeader());
+ HLargeData newdata = new HLargeData(DOMUtils.domToString(value));
+ _session.save(newdata);
+ _hself.setHeader(newdata);
+ update();
+ leaving("MessageDaoImpl.setHeader");
+ }
+
+ public Element getHeader() {
+ entering("MessageDaoImpl.getHeader");
+ if (_hself.getHeader() == null) return null;
+ try {
+ return DOMUtils.stringToDOM(_hself.getHeader().getText());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
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=940263&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 Sun May 2 17:02:51 2010
@@ -0,0 +1,444 @@
+/*
+ * 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.Collections;
+import java.util.Date;
+import java.util.Set;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+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.bpel.iapi.InvocationStyle;
+import org.apache.ode.bpel.iapi.MessageExchange.AckType;
+import org.apache.ode.bpel.iapi.MessageExchange.FailureType;
+import org.apache.ode.bpel.iapi.MessageExchange.MessageExchangePattern;
+import org.apache.ode.bpel.iapi.MessageExchange.Status;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelatorMessage;
+import org.apache.ode.dao.hib.bpel.hobj.HLargeData;
+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.w3c.dom.Element;
+
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Set;
+
+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.getMexId();
+ }
+
+ public MessageDAO getResponse() {
+ entering("MessageExchangeDaoImpl.getResponse");
+ return _hself.getResponse() == null ? null : new MessageDaoImpl(_sm, _hself.getResponse());
+ }
+
+ public Date getCreateTime() {
+ return _hself.getInsertTime();
+ }
+
+ 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(Status status) {
+ entering("MessageExchangeDaoImpl.setStatus");
+ _hself.setState(status == null ? null : status.toString());
+ update();
+ }
+
+ public Status getStatus() {
+ return _hself.getState() == null ? null : Status.valueOf(_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());
+ 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 getPartnersKey() {
+ return _hself.getClientKey();
+ }
+
+ public void setPartnersKey(String clientKey) {
+ _hself.setClientKey(clientKey);
+ update();
+ }
+
+ public void setPattern(MessageExchangePattern pattern) {
+ entering("MessageExchangeDaoImpl.setPattern");
+ _hself.setPattern(pattern == null ? null : pattern.toString());
+ 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 {
+ HLargeData ld = new HLargeData(DOMUtils.domToString(source));
+ getSession().save(ld);
+ _hself.setEndpoint(ld);
+ }
+
+ getSession().saveOrUpdate(_hself);
+
+ }
+
+ public Element getEPR() {
+ entering("MessageExchangeDaoImpl.getEPR");
+ HLargeData ld = _hself.getEndpoint();
+ if (ld == null)
+ return null;
+ try {
+ return DOMUtils.stringToDOM(ld.getText());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setCallbackEPR(Element source) {
+ entering("MessageExchangeDaoImpl.setCallbackEPR");
+ if (source == null)
+ _hself.setCallbackEndpoint(null);
+ else {
+ HLargeData ld = new HLargeData(DOMUtils.domToString(source));
+ getSession().save(ld);
+ _hself.setCallbackEndpoint(ld);
+ }
+
+ getSession().saveOrUpdate(_hself);
+
+ }
+
+ public Element getCallbackEPR() {
+ entering("MessageExchangeDaoImpl.getCallbackEPR");
+ HLargeData ld = _hself.getCallbackEndpoint();
+ if (ld == null)
+ return null;
+ try {
+ return DOMUtils.stringToDOM(ld.getText());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public MessageExchangePattern getPattern() {
+ return _hself.getPattern() == null ? null : MessageExchangePattern.valueOf(_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 void release(boolean doClean) {
+ if( doClean ) {
+ deleteMessages();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void releasePremieMessages() {
+ deleteByIds(HLargeData.class, getSession().getNamedQuery(HLargeData.SELECT_MESSAGE_LDATA_IDS_BY_MEX_1).setParameter("mex", _hself).list());
+ deleteByIds(HLargeData.class, getSession().getNamedQuery(HLargeData.SELECT_MESSAGE_LDATA_IDS_BY_MEX_2).setParameter("mex", _hself).list());
+ deleteByIds(HLargeData.class, getSession().getNamedQuery(HLargeData.SELECT_MESSAGE_LDATA_IDS_BY_MEX_3).setParameter("mex", _hself).list());
+ deleteByIds(HLargeData.class, getSession().getNamedQuery(HLargeData.SELECT_MESSAGE_LDATA_IDS_BY_MEX_4).setParameter("mex", _hself).list());
+ deleteByIds(HCorrelatorMessage.class, getSession().getNamedQuery(HCorrelatorMessage.SELECT_CORMESSAGE_IDS_BY_MEX).setParameter("mex", _hself).list());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void deleteMessages() {
+ deleteByIds(HLargeData.class, getSession().getNamedQuery(HLargeData.SELECT_MESSAGE_LDATA_IDS_BY_MEX_1).setParameter("mex", _hself).list());
+ deleteByIds(HLargeData.class, getSession().getNamedQuery(HLargeData.SELECT_MESSAGE_LDATA_IDS_BY_MEX_2).setParameter("mex", _hself).list());
+ deleteByIds(HLargeData.class, getSession().getNamedQuery(HLargeData.SELECT_MESSAGE_LDATA_IDS_BY_MEX_3).setParameter("mex", _hself).list());
+ deleteByIds(HLargeData.class, getSession().getNamedQuery(HLargeData.SELECT_MESSAGE_LDATA_IDS_BY_MEX_4).setParameter("mex", _hself).list());
+ 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
+ }
+
+ public Map<String,String> getProperties() {
+ return _hself.getProperties();
+ }
+
+ public InvocationStyle getInvocationStyle() {
+ return _hself.getInvocationStyle() == null ? null : InvocationStyle.valueOf(_hself.getInvocationStyle());
+ }
+
+ public String getPipedMessageExchangeId() {
+ return _hself.getPipedMessageExchange();
+ }
+
+ public long getTimeout() {
+ return _hself.getTimeout();
+ }
+
+ public void setFailureType(FailureType failureType) {
+ _hself.setFailureType(failureType == null ? null : failureType.toString());
+ }
+
+ public FailureType getFailureType() {
+ return _hself.getFailureType() == null ? null : FailureType.valueOf(_hself.getFailureType());
+
+ }
+
+ public void setInvocationStyle(InvocationStyle invocationStyle) {
+ _hself.setInvocationStyle(invocationStyle == null ? null : invocationStyle.toString());
+ }
+
+ public void setPipedMessageExchangeId(String pipedMex) {
+ entering("MessageExchangeDaoImpl.setPipedMessageExchangeId");
+ _hself.setPipedMessageExchange(pipedMex);
+ }
+
+ public void setTimeout(long timeout) {
+ _hself.setTimeout(timeout);
+ }
+
+ public AckType getAckType() {
+ return _hself.getAckType() == null ? null : AckType.valueOf(_hself.getAckType());
+ }
+
+ public void setAckType(AckType ackType) {
+ _hself.setAckType(ackType == null ? null : ackType.toString());
+ }
+
+ public QName getPipedPID() {
+ return _hself.getPipedPID() == null ? null : QName.valueOf(_hself.getPipedPID());
+ }
+
+ public void setPipedPID(QName pipedPid) {
+ _hself.setPipedPID(pipedPid == null ? null : pipedPid.toString());
+
+ }
+
+ public void setResource(String resource) {
+ _hself.setResource(resource);
+ }
+
+ public String getResource() {
+ return _hself.getResource();
+ }
+
+ public boolean isInstantiatingResource() {
+ return _hself.isInstantiatingResource();
+ }
+
+ public void setInstantiatingResource(boolean inst) {
+ _hself.setInstantiatingResource(inst);
+ }
+}
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=940263&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 Sun May 2 17:02:51 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.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.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.dao.bpel.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();
+ }
+
+}
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=940263&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 Sun May 2 17:02:51 2010
@@ -0,0 +1,209 @@
+/*
+ * 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.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ode.dao.bpel.ContextValueDAO;
+import org.apache.ode.dao.bpel.PartnerLinkDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HContextValue;
+import org.apache.ode.dao.hib.bpel.hobj.HLargeData;
+import org.apache.ode.dao.hib.bpel.hobj.HPartnerLink;
+import org.apache.ode.utils.DOMUtils;
+import org.hibernate.Query;
+import org.hibernate.Session;
+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 {
+ private static final String QRY_DEL_CTX_VALUES = "delete from " + HContextValue.class.getName()
+ + " where namespace = ? and key = ?".intern();
+
+
+ /** 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().getText());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setMyEPR(Element val) {
+ entering("PartnerLinkDAOImpl.setMyEPR");
+ _myEPR = val;
+ if (_self.getMyEPR() != null)
+ _sm.getSession().delete(_self.getMyEPR());
+ if (val == null) {
+ _self.setMyEPR(null);
+ } else {
+ HLargeData ld = new HLargeData(DOMUtils.domToString(val));
+ getSession().save(ld);
+ _self.setMyEPR(ld);
+ }
+ 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().getText());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setPartnerEPR(Element val) {
+ entering("PartnerLinkDAOImpl.setPartnerEPR");
+ _partnerEPR = val;
+ if (_self.getPartnerEPR() != null)
+ _sm.getSession().delete(_self.getPartnerEPR());
+ if (val == null) {
+ _self.setPartnerEPR(null);
+ } else {
+ HLargeData ld = new HLargeData(DOMUtils.domToString(val));
+ getSession().save(ld);
+ _self.setPartnerEPR(ld);
+ }
+ 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);
+
+ }
+
+ public Collection<ContextValueDAO> getContextValues() {
+ entering("PartnerLinkDAOImpl.getContextValues");
+ Set<ContextValueDAO> results = new HashSet<ContextValueDAO>();
+ for (HContextValue hContextValue : _self.getContextValues()) {
+ results.add(new ContextValueDaoImpl(_sm, hContextValue));
+ }
+ return results;
+ }
+
+ public void removeContextValue(String namespace, String key) {
+ entering("PartnerLinkDAOImpl.removeContextValue");
+ Session session = getSession();
+ Query q = session.createQuery(QRY_DEL_CTX_VALUES);
+ q.setString(0, namespace); // namespace
+ q.setString(0, key); // key
+ q.executeUpdate();
+ session.flush(); // explicit flush to ensure value removed.
+ }
+
+ public void setContextValue(String namespace, String key, String value) {
+ entering("PartnerLinkDAOImpl.setContextValue");
+ HContextValue hvalue = null;
+ for (HContextValue c : _self.getContextValues()) {
+ if (c.getNamespace().equals(namespace) && c.getKey().equals(key)) {
+ hvalue = c;
+ }
+ }
+
+ if (hvalue == null) {
+ hvalue = new HContextValue();
+ hvalue.setNamespace(namespace);
+ hvalue.setKey(key);
+ hvalue.setPartnerLink(_self);
+ _self.getContextValues().add(hvalue);
+
+ hvalue.setLock(0);
+ hvalue.setCreated(new Date());
+ getSession().save(hvalue);
+ }
+
+ hvalue.setValue(value);
+ }
+
+}