nice.. do you mind if I commit it to the trunk?<br>can you create some unit testing too?<br><br><br><div class="gmail_quote">On Fri, Oct 23, 2009 at 3:27 PM, Bill Tarr <span dir="ltr">&lt;<a href="mailto:javatestcase@yahoo.com">javatestcase@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Here is an alternate version of JPAVariablePersister for people who are already using Hibernate xml mapping files. <br>

<br>
This implementation has some downsides, but it seems to be working for now.<br>
<br>
I am going to keep using JPA to manage all the Drools Flow tables.<br>
<br>
My domain object persistence will be managed by Hibernate Session. <br>
<br>
We are also currently using automatic flush (so no code to persist domain objects in this class)<br>
<br>
Obviously you need to use your own version of HibUtil.<br>
<br>
import java.util.logging.Level;<br>
import java.util.logging.Logger;<br>
import org.drools.persistence.processinstance.variabletypes.JPAPersistedVariable;<br>
import org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo;<br>
import org.drools.persistence.processinstance.persisters.VariablePersister;<br>
import org.drools.runtime.Environment;<br>
import org.hibernate.Session;<br>
import HibUtil;<br>
/**<br>
 * Variation on Drools JPA Variable Persister.<br>
 * org.drools.persistence.processinstance.persisters.JPAVariablePersister<br>
 * for using variables persisted by Hibernate, while still using JPA to<br>
 * persist DroolsFlow data.<br>
 *<br>
 * @author &lt;a href=&quot;mailto:<a href="mailto:kris_verlaenen@hotmail.com">kris_verlaenen@hotmail.com</a>&quot;&gt;Kris Verlaenen&lt;/a&gt;<br>
 * @author salaboy<br>
 */<br>
public class JPAVariablePersisterHibernate implements VariablePersister {<br>
 public VariableInstanceInfo persistExternalVariable(String name, Object o,<br>
   VariableInstanceInfo oldValue, Environment env) {<br>
                if(o == null || (oldValue != null &amp;&amp; oldValue.getPersister().equals(&quot;&quot;))){<br>
                    return null;<br>
                }<br>
  try {<br>
   JPAPersistedVariable result = null;<br>
   if (oldValue instanceof JPAPersistedVariable) {<br>
    result = (JPAPersistedVariable) oldValue;<br>
   }<br>
   if (result == null) {<br>
    result = new JPAPersistedVariable();<br>
   }<br>
   Long idValue = geHibIdValue(o);<br>
   result.setPersister(this.getClass().getName());<br>
            result.setName(name);<br>
   result.setEntityId(idValue);<br>
   result.setEntity(o);<br>
   result.setEntityClass(o.getClass().getCanonicalName());<br>
            return result;<br>
  } catch (Throwable t) {<br>
   Logger.getLogger(JPAVariablePersisterHibernate.class.getName())<br>
    .log(Level.SEVERE, null, t);<br>
   throw new RuntimeException(&quot;Could not persist external variable&quot;, t);<br>
  }<br>
 }<br>
 public Object getExternalPersistedVariable(<br>
   VariableInstanceInfo variableInstanceInfo, Environment env) {<br>
        if(((JPAPersistedVariable) variableInstanceInfo) == null || ((JPAPersistedVariable) variableInstanceInfo).getEntityId() == null){<br>
            return null;<br>
        }<br>
        System.out.println(&quot;Restoring JPAPersistedVariable id=&quot; + ((JPAPersistedVariable) variableInstanceInfo).getId() + &quot; entityId=&quot; + ((JPAPersistedVariable) variableInstanceInfo).getEntityId() + &quot; class=&quot; + ((JPAPersistedVariable) variableInstanceInfo).getEntityClass() + &quot; value=&quot; + ((JPAPersistedVariable) variableInstanceInfo).getEntity());<br>

  String varType = ((JPAPersistedVariable) variableInstanceInfo).getEntityClass();<br>
       <br>
        Object obj = HibUtil.getCurrentSession().get(varType, ((JPAPersistedVariable) variableInstanceInfo).getEntityId());<br>
        HibUtil.closeCurrentSession();<br>
        return obj;<br>
 }<br>
/**<br>
 * Hibernate lookup to get ID column.<br>
 * @param o Dto to look up.<br>
 * @return Long id.<br>
 */<br>
 private Long geHibIdValue(Object o)  {<br>
        Session session = HibUtil.getCurrentSession();<br>
        return (Long) session.getIdentifier(o);<br>
 }<br>
} <br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br> - <a href="http://salaboy.wordpress.com">http://salaboy.wordpress.com</a><br> - <a href="http://www.jbug.com.ar">http://www.jbug.com.ar</a><br> - Salatino &quot;Salaboy&quot; Mauricio -<br>