ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r647004 - in /ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel: CorrelatorDaoImpl.java ProcessDaoImpl.java ProcessInstanceDaoImpl.java ScopeDaoImpl.java XmlDataDaoImpl.java
Date Thu, 10 Apr 2008 23:14:21 GMT
Author: mriou
Date: Thu Apr 10 16:14:19 2008
New Revision: 647004

URL: http://svn.apache.org/viewvc?rev=647004&view=rev
Log:
Several optimizations on Hibernate DAOs. Avoid loading a whole collection just to insert an
element. Simple variables transactional cache.

Modified:
    ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/CorrelatorDaoImpl.java
    ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessDaoImpl.java
    ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessInstanceDaoImpl.java
    ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ScopeDaoImpl.java
    ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/XmlDataDaoImpl.java

Modified: ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/CorrelatorDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/CorrelatorDaoImpl.java?rev=647004&r1=647003&r2=647004&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/CorrelatorDaoImpl.java
(original)
+++ ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/CorrelatorDaoImpl.java
Thu Apr 10 16:14:19 2008
@@ -146,10 +146,6 @@
         return null;
     }
 
-    /**
-     * @see org.apache.ode.bpel.dao.CorrelatorDAO#enqueueMessage(byte[],
-     *      CorrelationKey[])
-     */
     public void enqueueMessage(MessageExchangeDAO mex, CorrelationKey[] correlationKeys)
{
         String[] keys = canonifyKeys(correlationKeys);
         String hdr = "enqueueMessage(mex=" + ((MessageExchangeDaoImpl) mex)._hobj.getId()
+ " keys="
@@ -193,7 +189,7 @@
         hsel.setInstance((HProcessInstance) ((ProcessInstanceDaoImpl) target).getHibernateObj());
         hsel.setCorrelator(_hobj);
         hsel.setCreated(new Date());
-        _hobj.getSelectors().add(hsel);
+//        _hobj.addSelector(hsel);
         getSession().save(hsel);
 
         __log.debug(hdr + "saved " + hsel);

Modified: ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessDaoImpl.java?rev=647004&r1=647003&r2=647004&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessDaoImpl.java
(original)
+++ ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessDaoImpl.java
Thu Apr 10 16:14:19 2008
@@ -92,7 +92,7 @@
         instance.setProcess(_process);
         instance.setCreated(new Date());
         getSession().save(instance);
-        _process.getInstances().add(instance);
+//        _process.addInstance(instance);
 
         return new ProcessInstanceDaoImpl(_sm,instance);
     }
@@ -135,7 +135,7 @@
         correlator.setCorrelatorId(corrid);
         correlator.setProcess(_process);
         correlator.setCreated(new Date());
-        _process.getCorrelators().add(correlator);
+//        _process.addCorrelator(correlator);
         getSession().save(correlator);
         getSession().saveOrUpdate(_process);
         return new CorrelatorDaoImpl(_sm, correlator);

Modified: ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessInstanceDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessInstanceDaoImpl.java?rev=647004&r1=647003&r2=647004&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessInstanceDaoImpl.java
(original)
+++ ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ProcessInstanceDaoImpl.java
Thu Apr 10 16:14:19 2008
@@ -180,7 +180,7 @@
     scope.setState(ScopeStateEnum.ACTIVE.toString());
     scope.setInstance(_instance);
     scope.setCreated(new Date());
-    _instance.getScopes().add(scope);
+//    _instance.addScope(scope);
     getSession().save(scope);
 
 		return new ScopeDaoImpl(_sm, scope);
@@ -265,9 +265,10 @@
     return null;
   }
 
-  /**
-	 * @see org.apache.ode.bpel.dao.ProcessInstanceDAO#getVariables(java.lang.String, int)
-	 */
+    /**
+     * TODO this is never used, except by test cases - should be removed
+     * @see org.apache.ode.bpel.dao.ProcessInstanceDAO#getVariables(java.lang.String, int)
+     */
 	public XmlDataDAO[] getVariables(String variableName, int scopeModelId) {
     List<XmlDataDAO> results = new ArrayList<XmlDataDAO>();
 
@@ -371,7 +372,7 @@
     for (int i = 1; i < actions.length; ++i)
       list += " " + actions[i];
     recovery.setActions(list);
-    _instance.getActivityRecoveries().add(recovery);
+//    _instance.addRecovery(recovery);
     getSession().save(recovery);
     _instance.setActivityFailureDateTime(dateTime);
     _instance.setActivityFailureCount(_instance.getActivityFailureCount() + 1);

Modified: ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ScopeDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ScopeDaoImpl.java?rev=647004&r1=647003&r2=647004&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ScopeDaoImpl.java
(original)
+++ ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/ScopeDaoImpl.java
Thu Apr 10 16:14:19 2008
@@ -39,12 +39,7 @@
 import org.hibernate.Query;
 import org.hibernate.criterion.Restrictions;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 /**
  * Hibernate-based {@link ScopeDAO} implementation.
@@ -62,6 +57,7 @@
 
     private HScope _scope;
 
+    private HashMap<String,XmlDataDAO> _variables = new HashMap<String,XmlDataDAO>();
 
     public ScopeDaoImpl(SessionManager sm, HScope scope) {
         super(sm, scope);
@@ -81,7 +77,7 @@
         if(res.size() == 0){
             // if it doesn't exist, we make it
             cs = new HCorrelationSet(_scope, corrSetName);
-            _scope.getCorrelationSets().add(cs);
+//            _scope.addCorrelationSet(cs);
             getSession().save(cs);
         } else {
             cs = (HCorrelationSet)res.get(0);
@@ -125,6 +121,9 @@
      * @see org.apache.ode.bpel.dao.ScopeDAO#getVariable(java.lang.String)
      */
     public XmlDataDAO getVariable(String varName) {
+        XmlDataDAO cached = _variables.get(varName);
+        if (cached != null) return _variables.get(varName);
+
         HXmlData data;
         Query qry = getSession().createQuery(QRY_VARIABLE);
         qry.setString(0,varName);
@@ -133,19 +132,17 @@
 
         if(res.size() > 0)
             data = (HXmlData)res.get(0);
-        else{
+        else {
             data = new HXmlData();
             data.setName(varName);
             data.setScope(_scope);
-            _scope.getVariables().add(data);
-            getSession().save(data);
         }
-        return new XmlDataDaoImpl(_sm, data);
+
+        XmlDataDaoImpl varDao = new XmlDataDaoImpl(_sm, data);
+        _variables.put(varName, varDao);
+        return varDao;
     }
 
-    /**
-     * @see org.apache.ode.bpel.dao.ScopeDAO#createPartnerLink(java.lang.String,java.lang.String)
-     */
     public PartnerLinkDAO createPartnerLink(int modelId, String pLinkName, String myRole,
String partnerRole) {
         HPartnerLink epr = new HPartnerLink();
         epr.setModelId(modelId);
@@ -153,15 +150,12 @@
         epr.setMyRole(myRole);
         epr.setPartnerRole(partnerRole);
         epr.setScope(_scope);
-        _scope.getPartnerLinks().add(epr);
+//        _scope.addPartnerLink(epr);
         getSession().save(epr);
         PartnerLinkDAOImpl eprDao = new PartnerLinkDAOImpl(_sm, epr);
         return eprDao;
     }
 
-    /**
-     * @see org.apache.ode.bpel.dao.ScopeDAO#getPartnerLink(java.lang.String,java.lang.String)
-     */
     public PartnerLinkDAO getPartnerLink(int plinkId) {
         Query qry = getSession().createQuery(QRY_SCOPE_EPR);
         qry.setInteger(0,plinkId);

Modified: ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/XmlDataDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/XmlDataDaoImpl.java?rev=647004&r1=647003&r2=647004&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/XmlDataDaoImpl.java
(original)
+++ ode/branches/APACHE_ODE_1.1/dao-hibernate/src/main/java/org/apache/ode/daohib/bpel/XmlDataDaoImpl.java
Thu Apr 10 16:14:19 2008
@@ -38,130 +38,130 @@
  * Hibernate-based {@link XmlDataDAO} implementation.
  */
 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);
-    _data = hobj;
-	}
-	/**
-	 * @see org.apache.ode.bpel.dao.XmlDataDAO#isNull()
-	 */
-	public boolean isNull() {
-		return _data.getData() == null;
-	}
-  
-	/**
-	 * @see org.apache.ode.bpel.dao.XmlDataDAO#get()
-	 */
-	public Node get() {
-		if(_node == null){
-			_node = prepare();
-    }
-    return _node;
-	}
-	/**
-	 * @see org.apache.ode.bpel.dao.XmlDataDAO#remove()
-	 */
-	public void remove() {
-		
-	}
-	/**
-	 * @see org.apache.ode.bpel.dao.XmlDataDAO#set(org.w3c.dom.Node)
-	 */
-	public void set(Node val) {
-		_node = val;
-    _data.setSimpleType(!(val instanceof Element));
-    if (_data.getData() != null)
-      _sm.getSession().delete(_data.getData());
-    HLargeData ld = new HLargeData();
-    if(_data.isSimpleType()) {
-      ld.setBinary(_node.getNodeValue().getBytes());
-      _data.setData(ld);
-    } else {
-      ld.setBinary(DOMUtils.domToString(_node).getBytes());
-      _data.setData(ld);
-    }
-    getSession().save(ld);
-    getSession().update(_data);
-  }
-	/**
-	 * @see org.apache.ode.bpel.dao.XmlDataDAO#getProperty(java.lang.String)
-	 */
-	public String getProperty(String propertyName) {
-		
-    HVariableProperty p = _getProperty(propertyName);
-    return p == null
-      ? null
-      : p.getValue();
-	}
-	
-	/**
-	 * @see org.apache.ode.bpel.dao.XmlDataDAO#setProperty(java.lang.String, java.lang.String)
-	 */
-	public void setProperty(String pname, String pvalue) {
-		HVariableProperty p = _getProperty(pname);
-    if(p == null){
-    	p = new HVariableProperty(_data, pname, pvalue);
-      getSession().save(p);
-      _data.getProperties().add(p);
-    }else{
-      p.setValue(pvalue);
-      getSession().update(p);
-    }
-  }
-  
-  /**
-   * @see org.apache.ode.bpel.dao.XmlDataDAO#getScopeDAO()
-   */
-  public ScopeDAO getScopeDAO() {
-    return new ScopeDaoImpl(_sm,_data.getScope());
-  }
-  
-  private HVariableProperty _getProperty(String propertyName){
-    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.getData() == null)
-      return null;
-    String data = _data.getData().getText();
-    if(_data.isSimpleType()){
-      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("text-node-wrapper");
-      Text tnode = d.createTextNode(data);
-      d.appendChild(e);
-      e.appendChild(tnode);
-      return tnode;
-    }else{
-      try{
-        return DOMUtils.stringToDOM(data);
-      }catch(Exception e){
-        throw new RuntimeException(e);
-      }
-    }
-  }
-
-  public String getName() {
-    return _data.getName();
-  }
-	
+    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);
+        _data = hobj;
+    }
+    /**
+     * @see org.apache.ode.bpel.dao.XmlDataDAO#isNull()
+     */
+    public boolean isNull() {
+        return _data.getData() == null;
+    }
+
+    /**
+     * @see org.apache.ode.bpel.dao.XmlDataDAO#get()
+     */
+    public Node get() {
+        if(_node == null){
+            _node = prepare();
+        }
+        return _node;
+    }
+    /**
+     * @see org.apache.ode.bpel.dao.XmlDataDAO#remove()
+     */
+    public void remove() {
+
+    }
+    /**
+     * @see org.apache.ode.bpel.dao.XmlDataDAO#set(org.w3c.dom.Node)
+     */
+    public void set(Node val) {
+        _node = val;
+        _data.setSimpleType(!(val instanceof Element));
+        if (_data.getData() != null) _sm.getSession().delete(_data.getData());
+        
+        HLargeData ld = new HLargeData();
+        if(_data.isSimpleType()) {
+            ld.setBinary(_node.getNodeValue().getBytes());
+            _data.setData(ld);
+        } else {
+            ld.setBinary(DOMUtils.domToString(_node).getBytes());
+            _data.setData(ld);
+        }
+        getSession().save(ld);
+        getSession().saveOrUpdate(_data);
+    }
+    /**
+     * @see org.apache.ode.bpel.dao.XmlDataDAO#getProperty(java.lang.String)
+     */
+    public String getProperty(String propertyName) {
+
+        HVariableProperty p = _getProperty(propertyName);
+        return p == null
+                ? null
+                : p.getValue();
+    }
+
+    /**
+     * @see org.apache.ode.bpel.dao.XmlDataDAO#setProperty(java.lang.String, java.lang.String)
+     */
+    public void setProperty(String pname, String pvalue) {
+        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.bpel.dao.XmlDataDAO#getScopeDAO()
+     */
+    public ScopeDAO getScopeDAO() {
+        return new ScopeDaoImpl(_sm,_data.getScope());
+    }
+
+    private HVariableProperty _getProperty(String propertyName){
+        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.getData() == null)
+            return null;
+        String data = _data.getData().getText();
+        if(_data.isSimpleType()){
+            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("text-node-wrapper");
+            Text tnode = d.createTextNode(data);
+            d.appendChild(e);
+            e.appendChild(tnode);
+            return tnode;
+        }else{
+            try{
+                return DOMUtils.stringToDOM(data);
+            }catch(Exception e){
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    public String getName() {
+        return _data.getName();
+    }
+
 }



Mime
View raw message