<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Senlin,<br>
<br>
It will be easy to use JPA. Here is an example.<br>
===============<br>
This example assume that you have a Person POJO and you want to query
all persons with the age lest than or equal to 20.<br>
<br>
public class DroolsTest {<br>
<br>
    public static final void main(String[] args) {<br>
        try {<br>
            <br>
            //load up the rulebase<br>
            RuleBase ruleBase = readRule();<br>
            WorkingMemory workingMemory = ruleBase.newStatefulSession();<br>
        <br>
         // Start EntityManagerFactory<br>
            EntityManagerFactory emf =<br>
                    Persistence.createEntityManagerFactory("persons");<br>
<br>
            // Second unit of work<br>
            EntityManager newEm = emf.createEntityManager();<br>
            EntityTransaction newTx = newEm.getTransaction();<br>
            newTx.begin();<br>
            <br>
            workingMemory.setGlobal("entity",newEm);<br>
            ArrayList&lt;Person&gt; presult = new
ArrayList&lt;Person&gt;();<br>
            workingMemory.setGlobal("presult",presult);<br>
            workingMemory.fireAllRules(); <br>
            <br>
            System.out.println("=============List
Results=============");<br>
            for ( Person p : presult ){<br>
                 System.out.println("Person: \"" + p.getFirstName() +<br>
                         "\", " + p.getLastName() +            <br>
                                     "\", " + p.getAge());<br>
            }<br>
            System.out.println("=============End List
Results=====\n\n");         <br>
            newTx.commit();<br>
            newEm.close();<br>
         // Shutting down the application<br>
            emf.close();<br>
          <br>
        } catch (Throwable t) {<br>
            t.printStackTrace();<br>
        }<br>
    }<br>
   /**<br>
     * Please note that this is the "low level" rule assembly API.<br>
     */<br>
    private static RuleBase readRule() throws Exception {<br>
        //read in the source<br>
        Reader source = new InputStreamReader(
DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );      <br>
        PackageBuilder builder = new PackageBuilder(); <br>
        builder.addPackageFromDrl( source );<br>
<br>
        //get the compiled package (which is serializable)<br>
        Package pkg = builder.getPackage();<br>
        <br>
        //add the package to a rulebase (deploy the rule package).<br>
        RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
        ruleBase.addPackage( pkg );<br>
        return ruleBase;<br>
    }<br>
}<br>
<br>
==============<br>
Here is the rule sample.drl<br>
<br>
package com.sample<br>
 <br>
import com.sample.DroolsTest.Message;<br>
import com.sample.Person;<br>
import javax.persistence.EntityManager;<br>
global javax.persistence.EntityManager entity;<br>
global java.util.ArrayList presult;<br>
<br>
<br>
rule "age"<br>
    when<br>
        $p: Person() from entity.createQuery("from Person p where p.age
&lt;= 20").getResultList();<br>
    then<br>
        presult.add($p);<br>
end<br>
<br>
==========<br>
<br>
Wilson<br>
<br>
<br>
Senlin Liang wrote:
<blockquote
 cite="mid:5e9db1b50807071946n77e7051fh1df78c58f86c216a@mail.gmail.com"
 type="cite">
  <pre wrap="">So, to use a hibernate session, we are storing data in disk in some
"internal format" used by Drools, and we are not actually
communicating with some relational database systems. Is this correct?

Thanks

On Mon, Jul 7, 2008 at 10:32 PM, Mark Proctor <a class="moz-txt-link-rfc2396E" href="mailto:mproctor@codehaus.org">&lt;mproctor@codehaus.org&gt;</a> wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Senlin Liang wrote:
    </pre>
    <blockquote type="cite">
      <pre wrap="">Hi all,

Is there some convinent database interface implemented in Drools
(store and retrieve data from DBMS, such as mysql) ?

I checked the manual, and found no such information. So I am assuming
that I will have to use JDBC. Is it right?

      </pre>
    </blockquote>
    <pre wrap="">you should use Hibernate to access a database. You can then use then pass
the hibernate session as a global and use the "from" keyword to execute
querries to be filtered through a pattern.
    </pre>
    <blockquote type="cite">
      <pre wrap="">Thanks,
Senlin Liang
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>


      </pre>
    </blockquote>
    <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>

    </pre>
  </blockquote>
  <pre wrap=""><!---->


  </pre>
</blockquote>
</body>
</html>