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/08/18 06:12:59 UTC
svn commit: r986561 [7/13] - in /ode/trunk: ./ axis2-war/
axis2-war/src/main/assembly/ axis2-war/src/test/java/org/apache/ode/axis2/
axis2-war/src/test/java/org/apache/ode/axis2/instancecleanup/
axis2-war/src/test/java/org/apache/ode/bpel/dao/ axis2-wa...
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=986561&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 Wed Aug 18 04:12:49 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=986561&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 Wed Aug 18 04:12:49 2010
@@ -0,0 +1,392 @@
+/*
+ * 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.bpel.iapi.Scheduler;
+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.hibernate.LockMode;
+import org.hibernate.exception.LockAcquisitionException;
+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 boolean lockPremieMessages() {
+ try {
+ return getSession().getNamedQuery(HCorrelatorMessage.SELECT_CORMESSAGE_BY_MEX).setLockMode("m", LockMode.UPGRADE).setParameter("mex", _hself).list().size() > 0;
+ } catch (LockAcquisitionException e) {
+ throw new Scheduler.JobProcessorException(e, true);
+ }
+ }
+
+ 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=986561&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 Wed Aug 18 04:12:49 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.bpel.common.CorrelationKey;
+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();
+ }
+
+ 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=986561&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 Wed Aug 18 04:12:49 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=986561&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 Wed Aug 18 04:12:49 2010
@@ -0,0 +1,304 @@
+/*
+ * 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.bpel.iapi.ProcessConf.CLEANUP_CATEGORY;
+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.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 Long getPidId() {
+ return (Long) getId();
+ }
+
+ 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.dao.bpel.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.dao.bpel.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();
+ }
+
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessInstanceDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessInstanceDaoImpl.java?rev=986561&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessInstanceDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessInstanceDaoImpl.java Wed Aug 18 04:12:49 2010
@@ -0,0 +1,573 @@
+/*
+ * 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.HashSet;
+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.ProcessState;
+import org.apache.ode.bpel.evt.ProcessInstanceEvent;
+import org.apache.ode.bpel.iapi.ProcessConf.CLEANUP_CATEGORY;
+import org.apache.ode.dao.bpel.ActivityRecoveryDAO;
+import org.apache.ode.dao.bpel.BpelDAOConnection;
+import org.apache.ode.dao.bpel.CorrelationSetDAO;
+import org.apache.ode.dao.bpel.CorrelatorDAO;
+import org.apache.ode.dao.bpel.FaultDAO;
+import org.apache.ode.dao.bpel.MessageExchangeDAO;
+import org.apache.ode.dao.bpel.ProcessDAO;
+import org.apache.ode.dao.bpel.ProcessInstanceDAO;
+import org.apache.ode.dao.bpel.ScopeDAO;
+import org.apache.ode.dao.bpel.ScopeStateEnum;
+import org.apache.ode.dao.bpel.XmlDataDAO;
+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.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.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.utils.DOMUtils;
+import org.apache.ode.utils.QNameUtils;
+import org.apache.ode.utils.stl.CollectionsX;
+import org.apache.ode.utils.stl.UnaryFunction;
+import org.hibernate.Criteria;
+import org.hibernate.Hibernate;
+import org.hibernate.Query;
+import org.hibernate.criterion.Projections;
+import org.hibernate.criterion.Restrictions;
+import org.w3c.dom.Element;
+
+/**
+ * Hibernate-based {@link ProcessInstanceDAO} implementation.
+ */
+public class ProcessInstanceDaoImpl extends HibernateDao implements ProcessInstanceDAO {
+ private static final Log __log = LogFactory.getLog(ProcessInstanceDaoImpl.class);
+
+ /** Query for removing selectors. */
+ private static final String QRY_DELSELECTORS = "delete from " +
+ HCorrelatorSelector.class.getName() + " where instance = ?";
+
+ private static final String QRY_VARIABLES = "from " + HXmlData.class.getName()
+ + " as x where x.name = ? and x.scope.scopeModelId = ? and x.scope.instance.id = ?";
+
+ private static final String QRY_RECOVERIES = "from " + HActivityRecovery.class.getName() +
+ " AS x WHERE x.instance.id = ?";
+
+ private HProcessInstance _instance;
+
+ private ScopeDAO _root;
+
+ public ProcessInstanceDaoImpl(SessionManager sm, HProcessInstance instance) {
+ super(sm, instance);
+ entering("ProcessInstanceDaoImpl.ProcessInstanceDaoImpl");
+ _instance = instance;
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getCreateTime()
+ */
+ public Date getCreateTime() {
+ return _instance.getCreated();
+ }
+
+ public void setFault(FaultDAO fault) {
+ entering("ProcessInstanceDaoImpl.setFault");
+ _instance.setFault(((FaultDAOImpl)fault)._self);
+ getSession().update(_instance);
+
+ }
+
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#setFault(javax.xml.namespace.QName, String, int, int, org.w3c.dom.Element)
+ */
+ public void setFault(QName name, String explanation, int lineNo, int activityId, Element faultData) {
+ entering("ProcessInstanceDaoImpl.setFault");
+ if (_instance.getFault() != null)
+ getSession().delete(_instance.getFault());
+
+ HFaultData fault = new HFaultData();
+ fault.setName(QNameUtils.fromQName(name));
+ fault.setExplanation(explanation);
+ fault.setLineNo(lineNo);
+ fault.setActivityId(activityId);
+ if (faultData != null) {
+ fault.setData(DOMUtils.domToBytes(faultData));
+ }
+
+ _instance.setFault(fault);
+ getSession().save(fault);
+ getSession().update(_instance);
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getFault()
+ */
+ public FaultDAO getFault() {
+ entering("ProcessInstanceDaoImpl.getFault");
+ if (_instance.getFault() == null) return null;
+ else return new FaultDAOImpl(_sm, _instance.getFault());
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getExecutionState()
+ */
+ public byte[] getExecutionState() {
+ entering("ProcessInstanceDaoImpl.getExecutionState");
+ if (_instance.getJacobState() == null) return null;
+ return _instance.getJacobState();
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#setExecutionState(byte[])
+ */
+ public void setExecutionState(byte[] bytes) {
+ entering("ProcessInstanceDaoImpl.setExecutionState");
+ if (bytes.length > 0) {
+ _instance.setJacobState(bytes);
+ }
+ getSession().update(_instance);
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getProcess()
+ */
+ public ProcessDAO getProcess() {
+ entering("ProcessInstanceDaoImpl.getProcess");
+ return new ProcessDaoImpl(_sm, _instance.getProcess());
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getRootScope()
+ */
+ public ScopeDAO getRootScope() {
+ entering("ProcessInstanceDaoImpl.getRootScope");
+ if (_root != null)
+ return _root;
+ Query rootQry = getSession().createFilter(_instance.getScopes(),
+ "where this.parentScope is null");
+ HScope hroot = (HScope)rootQry.uniqueResult();
+ if (hroot == null)
+ return null;
+ return _root = new ScopeDaoImpl(_sm, hroot);
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#setState(short)
+ */
+ public void setState(short state) {
+ entering("ProcessInstanceDaoImpl.setState");
+ _instance.setPreviousState(_instance.getState());
+ _instance.setState(state);
+ if(state==ProcessState.STATE_TERMINATED) {
+ clearSelectors();
+ }
+ getSession().update(_instance);
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getState()
+ */
+ public short getState() {
+ return _instance.getState();
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getPreviousState()
+ */
+ public short getPreviousState() {
+ return _instance.getPreviousState();
+ }
+
+
+ public ScopeDAO createScope(ScopeDAO parentScope, String name, int scopeModelId) {
+ entering("ProcessInstanceDaoImpl.createScope");
+ HScope scope = new HScope();
+ scope.setParentScope(parentScope != null
+ ? (HScope)((ScopeDaoImpl)parentScope).getHibernateObj()
+ : null);
+ scope.setName(name);
+ scope.setScopeModelId(scopeModelId);
+ scope.setState(ScopeStateEnum.NEW.toString());
+ scope.setInstance(_instance);
+ scope.setCreated(new Date());
+// _instance.addScope(scope);
+ getSession().save(scope);
+
+ return new ScopeDaoImpl(_sm, scope);
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getInstanceId()
+ */
+ public Long getInstanceId() {
+ return _instance.getId();
+ }
+
+ public ScopeDAO getScope(Long scopeInstanceId) {
+ entering("ProcessInstanceDaoImpl.getScope");
+ Long id = Long.valueOf(scopeInstanceId);
+ HScope scope = (HScope)getSession().get(HScope.class, id);
+ return scope != null
+ ? new ScopeDaoImpl(_sm, scope)
+ : null;
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getScopes(java.lang.String)
+ */
+ @SuppressWarnings("unchecked")
+ public Collection<ScopeDAO> getScopes(String scopeName) {
+ entering("ProcessInstanceDaoImpl.getScopes");
+ Collection<HScope> hscopes;
+ if (scopeName != null) {
+ Query filter = _sm.getSession().createFilter(_instance.getScopes(),
+ "where this.name=?");
+ filter.setString(0,scopeName);
+ hscopes = filter.list();
+ } else
+ hscopes = _instance.getScopes();
+ ArrayList<ScopeDAO> ret = new ArrayList<ScopeDAO>();
+ CollectionsX.transform(ret, hscopes, new UnaryFunction<HScope,ScopeDAO> () {
+ public ScopeDAO apply(HScope x) {
+ return new ScopeDaoImpl(_sm, x);
+ }
+ });
+ return ret;
+ }
+
+ public Collection<ScopeDAO> getScopes() {
+ return getScopes(null);
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getInstantiatingCorrelator()
+ */
+ public CorrelatorDAO getInstantiatingCorrelator() {
+ entering("ProcessInstanceDaoImpl.getInstantiatingCorrelator");
+ return new CorrelatorDaoImpl(_sm, _instance.getInstantiatingCorrelator());
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getLastActiveTime()
+ */
+ public Date getLastActiveTime() {
+ return _instance.getLastActiveTime();
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#setLastActiveTime(java.util.Date)
+ */
+ public void setLastActiveTime(Date dt) {
+ entering("ProcessInstanceDaoImpl.setLastActiveTime");
+ _instance.setLastActiveTime(dt);
+ }
+
+ public Set<CorrelationSetDAO> getCorrelationSets() {
+ entering("ProcessInstanceDaoImpl.getCorrelationSets");
+ Set<CorrelationSetDAO> results = new HashSet<CorrelationSetDAO>();
+
+ for (HCorrelationSet hCorrelationSet : _instance.getCorrelationSets()) {
+ results.add(new CorrelationSetDaoImpl(_sm, hCorrelationSet));
+ }
+
+ return results;
+ }
+
+ public CorrelationSetDAO getCorrelationSet(String name) {
+ entering("ProcessInstanceDaoImpl.getCorrelationSet");
+ for (HCorrelationSet hCorrelationSet : _instance.getCorrelationSets()) {
+ if (hCorrelationSet.getName().equals(name))
+ return new CorrelationSetDaoImpl(_sm, hCorrelationSet);
+ }
+ return null;
+ }
+
+ /**
+ * TODO this is never used, except by test cases - should be removed
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#getVariables(java.lang.String, int)
+ */
+ @SuppressWarnings("unchecked")
+ public XmlDataDAO[] getVariables(String variableName, int scopeModelId) {
+ entering("ProcessInstanceDaoImpl.getVariables");
+ List<XmlDataDAO> results = new ArrayList<XmlDataDAO>();
+
+ Iterator iter;
+ Query qry = getSession().createQuery(QRY_VARIABLES);
+ qry.setString(0, variableName);
+ qry.setInteger(1, scopeModelId);
+ qry.setLong(2, _instance.getId());
+ iter = qry.iterate();
+
+ while(iter.hasNext()) {
+ results.add(new XmlDataDaoImpl(_sm, (HXmlData)iter.next()));
+ }
+ Hibernate.close(iter);
+
+ return results.toArray(new XmlDataDAO[results.size()]);
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ProcessInstanceDAO#finishCompletion()
+ */
+ public void finishCompletion() {
+ entering("ProcessInstanceDaoImpl.finishCompletion");
+ // make sure we have completed.
+ assert (ProcessState.isFinished(this.getState()));
+ // let our process know that we've done our work.
+ this.getProcess().instanceCompleted(this);
+ }
+
+ public void delete(Set<CLEANUP_CATEGORY> cleanupCategories) {
+ delete(cleanupCategories, true);
+ }
+
+ public void delete(Set<CLEANUP_CATEGORY> cleanupCategories, boolean deleteMyRoleMex) {
+ entering("ProcessInstanceDaoImpl.delete");
+ if(__log.isDebugEnabled()) __log.debug("Cleaning up instance data with categories = " + cleanupCategories);
+
+ if( _instance.getJacobState() != null ) {
+ _instance.setJacobState(null);
+ }
+
+ HProcessInstance[] instances = new HProcessInstance[] {_instance};
+
+ if( cleanupCategories.contains(CLEANUP_CATEGORY.EVENTS) ) {
+ deleteEvents(instances);
+ }
+
+ if( cleanupCategories.contains(CLEANUP_CATEGORY.CORRELATIONS) ) {
+ deleteCorrelations(instances);
+ }
+
+ if( cleanupCategories.contains(CLEANUP_CATEGORY.MESSAGES) ) {
+ deleteMessages(instances, deleteMyRoleMex);
+ }
+
+ if( cleanupCategories.contains(CLEANUP_CATEGORY.VARIABLES) ) {
+ deleteVariables(instances);
+ }
+
+ if( cleanupCategories.contains(CLEANUP_CATEGORY.INSTANCE) ) {
+ deleteInstances(instances);
+ }
+
+ getSession().flush();
+
+ if(__log.isDebugEnabled()) __log.debug("Instance data cleaned up and flushed.");
+ }
+
+ @SuppressWarnings("unchecked")
+ private void deleteInstances(HProcessInstance[] instances) {
+ deleteByIds(HFaultData.class, getSession().getNamedQuery(HFaultData.SELECT_FAULT_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+
+ getSession().delete(_instance); // this deletes JcobState, HActivityRecovery -> ActivityRecovery-LData
+ }
+
+ @SuppressWarnings("unchecked")
+ private void deleteVariables(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());
+
+ 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(HProcessInstance[] instances, boolean deleteMyRoleMex) {
+ // Let's delete ALL mex properties here
+ List<Long> allMexes = getSession().getNamedQuery(HMessageExchange.SELECT_MEX_IDS_BY_INSTANCES).setParameterList("instances", instances).list();
+ deleteByColumn(HMessageExchangeProperty.class, "mex.id", allMexes);
+
+ if( deleteMyRoleMex ) { // Delete my role mex and partner role mexes
+ // delete messages
+ deleteByIds(HMessage.class, getSession().getNamedQuery(HMessage.SELECT_MESSAGE_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+
+ // delete all mexes
+ deleteByIds(HMessageExchange.class, allMexes);
+ } else { // Delete only the unmatched mexes, there are chances that some unmatched messages are still there
+ Collection<HMessageExchange> unmatchedMex = getSession().getNamedQuery(HMessageExchange.SELECT_UNMATCHED_MEX_BY_INSTANCES).setParameterList("instances", instances).list();
+ if( !unmatchedMex.isEmpty() ) {
+ List<Long> mexIdList = new ArrayList<Long>();
+ for( HMessageExchange mex : unmatchedMex ) {
+ mexIdList.add(mex.getId());
+ }
+
+ // delete unmatched mexes
+ getSession().delete(unmatchedMex);
+ }
+ }
+
+ // Delete routes and unmatched messages
+ deleteByIds(HCorrelatorMessage.class, getSession().getNamedQuery(HCorrelatorMessage.SELECT_CORMESSAGE_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+ deleteByIds(HCorrelatorSelector.class, getSession().getNamedQuery(HCorrelatorSelector.SELECT_MESSAGE_ROUTE_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+ }
+
+ @SuppressWarnings("unchecked")
+ private void deleteCorrelations(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(HProcessInstance[] instances) {
+ deleteByIds(HBpelEvent.class, getSession().getNamedQuery(HBpelEvent.SELECT_EVENT_IDS_BY_INSTANCES).setParameterList("instances", instances).list());
+ }
+
+ public void insertBpelEvent(ProcessInstanceEvent event) {
+ entering("ProcessInstanceDaoImpl.insertBpelEvent");
+ // Defer to the BpelDAOConnectionImpl
+ BpelDAOConnectionImpl._insertBpelEvent(getSession(), event, this.getProcess(), this);
+ }
+
+ public EventsFirstLastCountTuple getEventsFirstLastCount() {
+ entering("ProcessInstanceDaoImpl.getEventsFirstLastCount");
+ // Using a criteria, find the min,max, and count of event tstamps.
+ Criteria c = getSession().createCriteria(HBpelEvent.class);
+ c.add(Restrictions.eq("instance",_instance));
+ c.setProjection(Projections.projectionList().add(Projections.min("tstamp"))
+ .add(Projections.max("tstamp"))
+ .add(Projections.count("tstamp")));
+
+ Object[] ret = (Object[]) c.uniqueResult();
+ EventsFirstLastCountTuple flc = new EventsFirstLastCountTuple();
+ flc.first = (Date) ret[0];
+ flc.last = (Date) ret[1];
+ flc.count = (Integer)ret[2];
+ return flc;
+ }
+
+ public Collection<MessageExchangeDAO> getMessageExchanges() {
+ Collection<MessageExchangeDAO> exchanges = new ArrayList<MessageExchangeDAO>();
+
+ for( HMessageExchange exchange : _instance.getMessageExchanges() ) {
+ exchanges.add(new MessageExchangeDaoImpl(_sm, exchange));
+ }
+
+ return exchanges;
+ }
+
+ public long genMonotonic() {
+ entering("ProcessInstanceDaoImpl.genMonotonic");
+ long seq = _instance.getSequence()+1;
+ _instance.setSequence(seq);
+ return seq;
+ }
+
+ protected void clearSelectors() {
+ entering("ProcessInstanceDaoImpl.clearSelectors");
+ Query q = getSession().createQuery(QRY_DELSELECTORS);
+ q.setEntity(0, _instance);
+ q.executeUpdate();
+ }
+
+ public int getActivityFailureCount() {
+ return _instance.getActivityFailureCount();
+ }
+
+ public Date getActivityFailureDateTime() {
+ return _instance.getActivityFailureDateTime();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Collection<ActivityRecoveryDAO> getActivityRecoveries() {
+ entering("ProcessInstanceDaoImpl.getActivityRecoveries");
+ List<ActivityRecoveryDAO> results = new ArrayList<ActivityRecoveryDAO>();
+ Query qry = getSession().createQuery(QRY_RECOVERIES);
+ qry.setLong(0, _instance.getId());
+ Iterator iter = qry.iterate();
+ while (iter.hasNext())
+ results.add(new ActivityRecoveryDaoImpl(_sm, (HActivityRecovery) iter.next()));
+ Hibernate.close(iter);
+ return results;
+ }
+
+ public void createActivityRecovery(String channel, long activityId, String reason,
+ Date dateTime, Element data, String[] actions, int retries) {
+ entering("ProcessInstanceDaoImpl.createActivityRecovery");
+ HActivityRecovery recovery = new HActivityRecovery();
+ recovery.setInstance(_instance);
+ recovery.setChannel(channel);
+ recovery.setActivityId(activityId);
+ recovery.setReason(reason);
+ recovery.setDateTime(dateTime);
+ recovery.setRetries(retries);
+ if (data != null) {
+ recovery.setDetails(DOMUtils.domToBytes(data));
+ }
+ String list = actions[0];
+ for (int i = 1; i < actions.length; ++i)
+ list += " " + actions[i];
+ recovery.setActions(list);
+// _instance.addRecovery(recovery);
+ getSession().save(recovery);
+ _instance.setActivityFailureDateTime(dateTime);
+ _instance.setActivityFailureCount(_instance.getActivityFailureCount() + 1);
+ getSession().update(_instance);
+ }
+
+ /**
+ * Delete previously registered activity recovery.
+ */
+ public void deleteActivityRecovery(String channel) {
+ entering("ProcessInstanceDaoImpl.deleteActivityRecovery");
+ for (HActivityRecovery recovery : _instance.getActivityRecoveries()) {
+ if (recovery.getChannel().equals(channel)) {
+ getSession().delete(recovery);
+ _instance.setActivityFailureCount(_instance.getActivityFailureCount() - 1);
+ getSession().update(_instance);
+ return;
+ }
+ }
+ }
+
+ public BpelDAOConnection getConnection() {
+ entering("ProcessInstanceDaoImpl.getConnection");
+ return new BpelDAOConnectionImpl(_sm);
+ }
+
+ public Collection<String> getMessageExchangeIds() {
+ Collection<String> c = new HashSet<String>();
+ for (HMessageExchange m : _instance.getMessageExchanges()) {
+ c.add(m.getId().toString());
+ }
+ return c;
+ }
+
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessManagementDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessManagementDaoImpl.java?rev=986561&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessManagementDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ProcessManagementDaoImpl.java Wed Aug 18 04:12:49 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ode.bpel.common.InstanceFilter;
+import org.apache.ode.bpel.common.InstanceFilter.StatusKeys;
+import org.apache.ode.dao.bpel.ProcessManagementDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HProcessInstance;
+import org.hibernate.Query;
+
+public class ProcessManagementDaoImpl extends HibernateDao implements ProcessManagementDAO {
+ protected ProcessManagementDaoImpl(SessionManager sessionManager) {
+ super(sessionManager, null);
+ }
+
+ public Map<InstanceSummaryKey, Long> countInstancesSummary(Set<String> pids) {
+ Map<InstanceSummaryKey, Long> result = new HashMap<InstanceSummaryKey, Long>();
+ if (!pids.isEmpty()) {
+ for (StatusKeys status : InstanceFilter.StatusKeys.values()) {
+ Query query = getSession().getNamedQuery(HProcessInstance.COUNT_INSTANCES_BY_PROCESSES_IDS_AND_STATES);
+ query.setParameterList("states", new InstanceFilter("status=" + status.toString()).convertFilterState());
+ query.setParameterList("processIds", pids);
+ for (Object o : query.list()) {
+ Object[] row = (Object[]) o;
+ InstanceSummaryKey key = new InstanceSummaryKey(row[0].toString(), status.toString());
+ result.put(key, (Long) row[1]);
+ }
+ }
+ }
+ return result;
+ }
+
+ public Map<String, FailedSummaryValue> findFailedCountAndLastFailedDateForProcessIds(Set<String> pids) {
+ Map<String, FailedSummaryValue> result = new HashMap<String, FailedSummaryValue>();
+ if (!pids.isEmpty()) {
+ Query query = getSession().getNamedQuery(HProcessInstance.COUNT_FAILED_INSTANCES_BY_PROCESSES_IDS_AND_STATES);
+ query.setParameterList("processIds", pids);
+ for (Object o : query.list()) {
+ Object[] row = (Object[]) o;
+ result.put(row[0].toString(), new FailedSummaryValue((Long) row[1], (Date) row[2]));
+ }
+ }
+ return result;
+ }
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ScopeDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ScopeDaoImpl.java?rev=986561&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ScopeDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/ScopeDaoImpl.java Wed Aug 18 04:12:49 2010
@@ -0,0 +1,266 @@
+/*
+ * 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.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.ode.bpel.evt.BpelEvent;
+import org.apache.ode.dao.bpel.CorrelationSetDAO;
+import org.apache.ode.dao.bpel.PartnerLinkDAO;
+import org.apache.ode.dao.bpel.ProcessInstanceDAO;
+import org.apache.ode.dao.bpel.ScopeDAO;
+import org.apache.ode.dao.bpel.ScopeStateEnum;
+import org.apache.ode.dao.bpel.XmlDataDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HBpelEvent;
+import org.apache.ode.dao.hib.bpel.hobj.HCorrelationSet;
+import org.apache.ode.dao.hib.bpel.hobj.HPartnerLink;
+import org.apache.ode.dao.hib.bpel.hobj.HScope;
+import org.apache.ode.dao.hib.bpel.hobj.HXmlData;
+import org.apache.ode.utils.SerializableUtils;
+import org.apache.ode.utils.stl.CollectionsX;
+import org.apache.ode.utils.stl.UnaryFunction;
+import org.apache.ode.utils.stl.UnaryFunctionEx;
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.criterion.Restrictions;
+
+/**
+ * Hibernate-based {@link ScopeDAO} implementation.
+ */
+public class ScopeDaoImpl extends HibernateDao implements ScopeDAO {
+
+
+ private static final String QRY_VARIABLE = "from " + HXmlData.class.getName() +
+ " as x where x.name = ? and x.scope.id = ?";
+
+ private static final String QRY_CSET = "from " + HCorrelationSet.class.getName() +
+ " as c where c.name = ? and c.scope.id = ?";
+
+ private static final String QRY_SCOPE_EPR = "from " + HPartnerLink.class.getName() +
+ " as e where e.modelId = ? and e.scope = ?";
+
+ private HScope _scope;
+
+ private HashMap<String,XmlDataDAO> _variables = new HashMap<String,XmlDataDAO>();
+
+ public ScopeDaoImpl(SessionManager sm, HScope scope) {
+ super(sm, scope);
+ entering("ScopeDaoImpl.ScopeDaoImpl");
+ _scope = scope;
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ScopeDAO#getCorrelationSet(java.lang.String)
+ */
+ public CorrelationSetDAO getCorrelationSet(String corrSetName) {
+ entering("ScopeDaoImpl.getCorrelationSet");
+ Query qry = getSession().createQuery(QRY_CSET);
+ qry.setString(0,corrSetName);
+ qry.setLong(1,_scope.getId());
+ HCorrelationSet cs;
+ List res = qry.list();
+
+ if(res.size() == 0){
+ // if it doesn't exist, we make it
+ cs = new HCorrelationSet(_scope, corrSetName);
+// _scope.addCorrelationSet(cs);
+ getSession().save(cs);
+ } else {
+ cs = (HCorrelationSet)res.get(0);
+ }
+ return new CorrelationSetDaoImpl(_sm, cs);
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.ScopeDAO#getParentScope()
+ */
+ public ScopeDAO getParentScope() {
+ entering("ScopeDaoImpl.getParentScope");
+ return _scope.getParentScope() != null
+ ? new ScopeDaoImpl(_sm, _scope.getParentScope())
+ : null;
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.ScopeDAO#getProcessInstance()
+ */
+ public ProcessInstanceDAO getProcessInstance() {
+ entering("ScopeDaoImpl.getProcessInstance");
+ return new ProcessInstanceDaoImpl(_sm, _scope.getInstance());
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.ScopeDAO#setState(org.apache.ode.dao.bpel.ScopeStateEnum)
+ */
+ public void setState(ScopeStateEnum state) {
+ entering("ScopeDaoImpl.setState");
+ _scope.setState(state.toString());
+ getSession().update(_scope);
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.ScopeDAO#getState()
+ */
+ public ScopeStateEnum getState() {
+ return ScopeStateEnum.valueOf(_scope.getState());
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.ScopeDAO#getName()
+ */
+ public String getName() {
+ return _scope.getName();
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.ScopeDAO#getVariable(java.lang.String)
+ */
+ public XmlDataDAO getVariable(String varName) {
+ entering("ScopeDaoImpl.getVariable");
+ XmlDataDAO cached = _variables.get(varName);
+ if (cached != null) return _variables.get(varName);
+
+ HXmlData data = null;
+ for (HXmlData e : _scope.getVariables()) {
+ if (e.getName().equals(varName) && e.getScope().getId().equals(_scope.getId())) {
+ data = e;
+ }
+ }
+ if (data == null) {
+ data = new HXmlData();
+ data.setName(varName);
+ data.setScope(_scope);
+ _scope.getVariables().add(data);
+ }
+
+ XmlDataDaoImpl varDao = new XmlDataDaoImpl(_sm, data);
+ _variables.put(varName, varDao);
+ return varDao;
+ }
+
+ public PartnerLinkDAO createPartnerLink(int modelId, String pLinkName, String myRole, String partnerRole) {
+ entering("ScopeDaoImpl.createPartnerLink");
+ HPartnerLink epr = new HPartnerLink();
+ epr.setModelId(modelId);
+ epr.setLinkName(pLinkName);
+ epr.setMyRole(myRole);
+ epr.setPartnerRole(partnerRole);
+ epr.setScope(_scope);
+// _scope.addPartnerLink(epr);
+ getSession().save(epr);
+ PartnerLinkDAOImpl eprDao = new PartnerLinkDAOImpl(_sm, epr);
+ return eprDao;
+ }
+
+ public PartnerLinkDAO getPartnerLink(int plinkId) {
+ entering("ScopeDaoImpl.getPartnerLink");
+ Query qry = getSession().createQuery(QRY_SCOPE_EPR);
+ qry.setInteger(0,plinkId);
+ qry.setEntity(1,_scope);
+ HPartnerLink hpl = (HPartnerLink) qry.uniqueResult();
+ if (hpl == null)
+ return null;
+ return new PartnerLinkDAOImpl(_sm, hpl);
+ }
+
+ public Collection<PartnerLinkDAO> getPartnerLinks() {
+ entering("ScopeDaoImpl.getPartnerLinks");
+ ArrayList<PartnerLinkDAO> plinks = new ArrayList<PartnerLinkDAO>();
+ for (HPartnerLink hPartnerLink : _scope.getPartnerLinks()) {
+ plinks.add(new PartnerLinkDAOImpl(_sm, hPartnerLink));
+ }
+ return plinks;
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ScopeDAO#getScopeInstanceId()
+ */
+ public Long getScopeInstanceId() {
+ return _scope.getId();
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.ScopeDAO#getModelId()
+ */
+ public int getModelId() {
+ return _scope.getScopeModelId();
+ }
+
+ public Set<CorrelationSetDAO> getCorrelationSets() {
+ entering("ScopeDaoImpl.getCorrelationSets");
+ Set<CorrelationSetDAO> results = new HashSet<CorrelationSetDAO>();
+ for (HCorrelationSet hCorrelationSet : _scope.getCorrelationSets()) {
+ results.add(new CorrelationSetDaoImpl(_sm, hCorrelationSet));
+ }
+ return results;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public Collection<ScopeDAO> getChildScopes() {
+ entering("ScopeDaoImpl.getChildScopes");
+ Query q = getSession().createQuery("from " + HScope.class.getName() + " as x where x.parentScope=?");
+ q.setEntity(0, _scope);
+ Collection<HScope> hscopes = q.list();
+ return CollectionsX.transform(new LinkedList<ScopeDAO>(), hscopes, new UnaryFunction<HScope,ScopeDAO>() {
+ public ScopeDAO apply(HScope x) {
+ return new ScopeDaoImpl(_sm,x);
+ }
+
+ });
+ }
+
+ @SuppressWarnings("unchecked")
+ public Collection<XmlDataDAO> getVariables() {
+ entering("ScopeDaoImpl.getVariables");
+ Query q = getSession().createFilter(_scope.getVariables(), "where this.scope=?");
+ q.setEntity(0, _scope);
+ return CollectionsX.transform(new LinkedList<XmlDataDAO>(), (Collection<HXmlData>)q.list(), new UnaryFunction<HXmlData,XmlDataDAO>() {
+ public XmlDataDAO apply(HXmlData x) {
+ return new XmlDataDaoImpl(_sm,x);
+ }
+
+ });
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<BpelEvent> listEvents() {
+ entering("ScopeDaoImpl.listEvents");
+// CriteriaBuilder cb = new CriteriaBuilder();
+ Criteria crit = _sm.getSession().createCriteria(HBpelEvent.class);
+// if (efilter != null)
+// cb.buildCriteria(crit, efilter);
+ crit.add(Restrictions.eq("scopeId",_scope.getId()));
+
+ List<HBpelEvent> hevents = crit.list();
+ List<BpelEvent> ret = new ArrayList<BpelEvent>(hevents.size());
+ try {
+ CollectionsX.transformEx(ret,hevents,new UnaryFunctionEx<HBpelEvent,BpelEvent>() {
+ public BpelEvent apply(HBpelEvent x) throws Exception{
+ return (BpelEvent) SerializableUtils.toObject(x.getData(),BpelEvent.class.getClassLoader());
+ }
+
+ });
+ }catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ return ret;
+ }
+}
Added: ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/XmlDataDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/XmlDataDaoImpl.java?rev=986561&view=auto
==============================================================================
--- ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/XmlDataDaoImpl.java (added)
+++ ode/trunk/dao-hibernate/src/main/java/org/apache/ode/dao/hib/bpel/XmlDataDaoImpl.java Wed Aug 18 04:12:49 2010
@@ -0,0 +1,192 @@
+/*
+ * 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.Iterator;
+
+import org.apache.ode.dao.bpel.ScopeDAO;
+import org.apache.ode.dao.bpel.XmlDataDAO;
+import org.apache.ode.dao.hib.SessionManager;
+import org.apache.ode.dao.hib.bpel.hobj.HVariableProperty;
+import org.apache.ode.dao.hib.bpel.hobj.HXmlData;
+import org.apache.ode.utils.DOMUtils;
+import org.hibernate.Query;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * Hibernate-based {@link XmlDataDAO} implementation.
+ */
+public class XmlDataDaoImpl extends HibernateDao implements XmlDataDAO {
+
+
+ private static final String QUERY_PROPERTY =
+ "from " + HVariableProperty.class.getName() +
+ " as p where p.xmlData.id = ? and p.name = ?";
+
+ private HXmlData _data;
+ private Node _node;
+
+ /**
+ * @param hobj
+ */
+ public XmlDataDaoImpl(SessionManager sm, HXmlData hobj) {
+ super(sm, hobj);
+ entering("XmlDataDaoImpl.XmlDataDaoImpl");
+ _data = hobj;
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.XmlDataDAO#isNull()
+ */
+ public boolean isNull() {
+ entering("XmlDataDaoImpl.isNull");
+ return (_data.getSimpleValue() == null && (_data.getData() == null || _data.getData().length == 0));
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.XmlDataDAO#get()
+ */
+ public Node get() {
+ entering("XmlDataDaoImpl.get");
+ if(_node == null){
+ _node = prepare();
+ }
+ return _node;
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.XmlDataDAO#remove()
+ */
+ public void remove() {
+
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.XmlDataDAO#set(org.w3c.dom.Node)
+ */
+ public void set(Node val) {
+ entering("XmlDataDaoImpl.set");
+ _node = val;
+ if (val != null && val.getNamespaceURI() == null && "temporary-simple-type-wrapper".equals(val.getLocalName())) {
+ _data.setSimpleType(true);
+ String value = _node.getTextContent();
+ if (value.length() <= 255) {
+ _data.setSimpleValue(value);
+ _data.setData(null);
+ } else {
+ _data.setData(value.getBytes());
+ _data.setSimpleValue(null);
+ }
+ } else if (val instanceof Element) {
+ _data.setSimpleType(false);
+ _data.setData(DOMUtils.domToString(_node).getBytes());
+ _data.setSimpleValue(null);
+ } else {
+ _data.setSimpleType(true);
+ _data.setSimpleValue(_node.getNodeValue());
+ _data.setData(null);
+ }
+
+ getSession().saveOrUpdate(_data);
+ leaving("XmlDataDaoImpl.set");
+ }
+ /**
+ * @see org.apache.ode.dao.bpel.XmlDataDAO#getProperty(java.lang.String)
+ */
+ public String getProperty(String propertyName) {
+ entering("XmlDataDaoImpl.getProperty");
+ HVariableProperty p = _getProperty(propertyName);
+ return p == null
+ ? null
+ : p.getValue();
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.XmlDataDAO#setProperty(java.lang.String, java.lang.String)
+ */
+ public void setProperty(String pname, String pvalue) {
+ entering("XmlDataDaoImpl.setProperty");
+ HVariableProperty p = _getProperty(pname);
+ if(p == null){
+ p = new HVariableProperty(_data, pname, pvalue);
+ getSession().save(p);
+// _data.addProperty(p);
+ }else{
+ p.setValue(pvalue);
+ getSession().update(p);
+ }
+ }
+
+ /**
+ * @see org.apache.ode.dao.bpel.XmlDataDAO#getScopeDAO()
+ */
+ public ScopeDAO getScopeDAO() {
+ entering("XmlDataDaoImpl.getScopeDAO");
+ return new ScopeDaoImpl(_sm,_data.getScope());
+ }
+
+ private HVariableProperty _getProperty(String propertyName){
+ entering("XmlDataDaoImpl._getProperty");
+ Iterator iter;
+ Query qry = getSession().createQuery(QUERY_PROPERTY);
+ qry.setLong(0, _data.getId());
+ qry.setString(1, propertyName);
+ iter = qry.iterate();
+ return iter.hasNext()
+ ? (HVariableProperty)iter.next()
+ : null;
+ }
+
+ private Node prepare(){
+ if(_data.isSimpleType()) {
+ String data;
+ if (_data.getSimpleValue() != null) {
+ data = _data.getSimpleValue();
+ } else {
+ if(_data.getData() == null || _data.getData().length == 0)
+ return null;
+ data = new String(_data.getData());
+ }
+ Document d = DOMUtils.newDocument();
+ // we create a dummy wrapper element
+ // prevents some apps from complaining
+ // when text node is not actual child of document
+ Element e = d.createElement("temporary-simple-type-wrapper");
+ Text tnode = d.createTextNode(data);
+ d.appendChild(e);
+ e.appendChild(tnode);
+ return tnode;
+ } else {
+ if(_data.getData() == null || _data.getData().length == 0)
+ return null;
+ String data = new String(_data.getData());
+ try{
+ return DOMUtils.stringToDOM(data);
+ }catch(Exception e){
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ public String getName() {
+ return _data.getName();
+ }
+
+}