hmm<br>I will take a look at it.. during the weekend..<br><br><div class="gmail_quote">2009/10/23 Bill Tarr <span dir="ltr"><<a href="mailto:javatestcase@yahoo.com">javatestcase@yahoo.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"><div>I'm not sure this should be comitted to the trunk.</div>
<div> </div>
<div>Users can't use this code as is, because:</div>
<div> </div>
<div>1. Manual/Automatic flush </div>
<div> - they'd need to implement flush() and persist() if they have manual flush set up.</div>
<div>2. HibUtil </div>
<div> - is a system specific implementation used to manage SessionFactory and Sessions</div>
<div> - systems using Hibernate will already have some version of this they will need to leverage</div>
<div> </div>
<div>so this is more of a template. </div>
<div> </div>
<div>In fact, it won't compile without a HibUtil, so that's another problem for adding it to the trunk...</div>
<div> </div>
<div>A test case in examples would let us create a simple HibUtil and hibernate.cfg.xml.</div>
<div><br>The test case could create a H2 DB and the tables needed...</div>
<div> </div>
<div style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"><br>
<div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Tahoma" size="2">
<hr size="1">
<b><span style="font-weight: bold;">From:</span></b> Mauricio Salatino <<a href="mailto:salaboy@gmail.com" target="_blank">salaboy@gmail.com</a>><br><b><span style="font-weight: bold;">To:</span></b> Rules Users List <<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>><br>
<b><span style="font-weight: bold;">Sent:</span></b> Fri, October 23, 2009 4:18:16 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [rules-users] [droolsflow] - one way to use Hibernate mapping with JPAVariablePersister<br>
</font><div><div></div><div class="h5"><br>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"><<a href="mailto:javatestcase@yahoo.com" rel="nofollow" target="_blank">javatestcase@yahoo.com</a>></span> wrote:<br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">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 <a href="mailto:<a href="mailto:kris_verlaenen@hotmail.com" rel="nofollow" target="_blank">kris_verlaenen@hotmail.com</a>">Kris Verlaenen</a><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 && oldValue.getPersister().equals(""))){<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("Could not persist external variable", 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("Restoring JPAPersistedVariable id=" + ((JPAPersistedVariable) variableInstanceInfo).getId() + " entityId=" + ((JPAPersistedVariable) variableInstanceInfo).getEntityId() + " class=" + ((JPAPersistedVariable) variableInstanceInfo).getEntityClass() + " value=" + ((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" rel="nofollow" target="_blank">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users" rel="nofollow" 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" target="_blank">http://salaboy.wordpress.com</a><br>- <a href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br>
- Salatino "Salaboy" Mauricio -<br></div></div></div></div></div><br>
</div><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>
<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 "Salaboy" Mauricio -<br>