Re: [rules-users] One question about Database interface

2008-07-08 Thread Jaroslaw Kijanowski

Mapping is the job of Hibernate, not Drools ;)

To be able to manage data in/from a database (persist, read,...) you 
need to configure Hibernate and one of these config steps is to provide 
the mapping.


Cheers,
 Jarek

Senlin Liang wrote:

Hi,

Thanks a lot! The information is really helpful.

One more question is that: I have to create the mapping between
"objects" to relational database "tables", or Drools can do this
automatically (by create the tables/objects of correct types) ?

Thanks again,
Senlin

On Tue, Jul 8, 2008 at 9:30 AM, Anstis, Michael (M.) <[EMAIL PROTECTED]> wrote:

Hi,

Jaroslaw Kijanowski's article looks like a really good starting point
for you!

Hibernate provide Entity Manager and Annotations extensions if you want
to go the JPA route.

>From a Drool's perspective you need only concern yourself with "from"
which is documented as:-

6.5.2.8. From

The from Conditional Element allows users to specify a source for
patterns to reason over. This allows the engine to reason over data not
in the Working Memory. This could be a sub-field on a bound variable or
the results of a method call. It is a powerful construction that allows
out of the box integration with other application components and
frameworks. One common example is the integration with data retrieved
on-demand from databases using hibernate named queries.

For information on the rest of Jaroslaw's example, you will need to read
up on Hibernate.

With kind regards,

Mike

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Senlin Liang
Sent: 08 July 2008 13:12
To: Rules Users List
Subject: Re: [rules-users] One question about Database interface

Thanks.  Where could I find the related manual or instructions? I
searched through the doc for drools, and the email archive, there is
really no good example or explanation on how to achieve this.

(What I want is to insert, select or delete some objects in relational
database such as mysql.)

Any information is greatly appreciated.
Thanks.

On Tue, Jul 8, 2008 at 4:20 AM, Anstis, Michael (M.) <[EMAIL PROTECTED]>
wrote:

Have a look at an example posted earlier this week whereby somebody
(sorry I forget who) was using JPA from within a rule.

Once you understand how JPA was used then the remaining questions

relate

more specifically to JPA.

As Mark says, (native) Hibernate can also be used very easily.

With kind regards,

Mike


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Senlin Liang
Sent: 08 July 2008 03:18
To: Rules Users List
Subject: [rules-users] One question about Database interface

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?

Thanks,
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




--
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users







___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] One question about Database interface

2008-07-08 Thread Senlin Liang
Hi,

Thanks a lot! The information is really helpful.

One more question is that: I have to create the mapping between
"objects" to relational database "tables", or Drools can do this
automatically (by create the tables/objects of correct types) ?

Thanks again,
Senlin

On Tue, Jul 8, 2008 at 9:30 AM, Anstis, Michael (M.) <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Jaroslaw Kijanowski's article looks like a really good starting point
> for you!
>
> Hibernate provide Entity Manager and Annotations extensions if you want
> to go the JPA route.
>
> >From a Drool's perspective you need only concern yourself with "from"
> which is documented as:-
>
> 6.5.2.8. From
>
> The from Conditional Element allows users to specify a source for
> patterns to reason over. This allows the engine to reason over data not
> in the Working Memory. This could be a sub-field on a bound variable or
> the results of a method call. It is a powerful construction that allows
> out of the box integration with other application components and
> frameworks. One common example is the integration with data retrieved
> on-demand from databases using hibernate named queries.
>
> For information on the rest of Jaroslaw's example, you will need to read
> up on Hibernate.
>
> With kind regards,
>
> Mike
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Senlin Liang
> Sent: 08 July 2008 13:12
> To: Rules Users List
> Subject: Re: [rules-users] One question about Database interface
>
> Thanks.  Where could I find the related manual or instructions? I
> searched through the doc for drools, and the email archive, there is
> really no good example or explanation on how to achieve this.
>
> (What I want is to insert, select or delete some objects in relational
> database such as mysql.)
>
> Any information is greatly appreciated.
> Thanks.
>
> On Tue, Jul 8, 2008 at 4:20 AM, Anstis, Michael (M.) <[EMAIL PROTECTED]>
> wrote:
>> Have a look at an example posted earlier this week whereby somebody
>> (sorry I forget who) was using JPA from within a rule.
>>
>> Once you understand how JPA was used then the remaining questions
> relate
>> more specifically to JPA.
>>
>> As Mark says, (native) Hibernate can also be used very easily.
>>
>> With kind regards,
>>
>> Mike
>>
>>
>> -Original Message-
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of Senlin Liang
>> Sent: 08 July 2008 03:18
>> To: Rules Users List
>> Subject: [rules-users] One question about Database interface
>>
>> 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?
>>
>> Thanks,
>> Senlin Liang
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
>
>
> --
> Senlin Liang
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] One question about Database interface

2008-07-08 Thread Anstis, Michael (M.)
Hi,

Jaroslaw Kijanowski's article looks like a really good starting point
for you!

Hibernate provide Entity Manager and Annotations extensions if you want
to go the JPA route.

>From a Drool's perspective you need only concern yourself with "from"
which is documented as:-

6.5.2.8. From

The from Conditional Element allows users to specify a source for
patterns to reason over. This allows the engine to reason over data not
in the Working Memory. This could be a sub-field on a bound variable or
the results of a method call. It is a powerful construction that allows
out of the box integration with other application components and
frameworks. One common example is the integration with data retrieved
on-demand from databases using hibernate named queries.
 
For information on the rest of Jaroslaw's example, you will need to read
up on Hibernate.

With kind regards,

Mike

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Senlin Liang
Sent: 08 July 2008 13:12
To: Rules Users List
Subject: Re: [rules-users] One question about Database interface

Thanks.  Where could I find the related manual or instructions? I
searched through the doc for drools, and the email archive, there is
really no good example or explanation on how to achieve this.

(What I want is to insert, select or delete some objects in relational
database such as mysql.)

Any information is greatly appreciated.
Thanks.

On Tue, Jul 8, 2008 at 4:20 AM, Anstis, Michael (M.) <[EMAIL PROTECTED]>
wrote:
> Have a look at an example posted earlier this week whereby somebody
> (sorry I forget who) was using JPA from within a rule.
>
> Once you understand how JPA was used then the remaining questions
relate
> more specifically to JPA.
>
> As Mark says, (native) Hibernate can also be used very easily.
>
> With kind regards,
>
> Mike
>
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Senlin Liang
> Sent: 08 July 2008 03:18
> To: Rules Users List
> Subject: [rules-users] One question about Database interface
>
> 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?
>
> Thanks,
> Senlin Liang
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] One question about Database interface

2008-07-08 Thread Jaroslaw Kijanowski

This may be helpful:
http://www.ee.pw.edu.pl/~kijanowj/index.php?site=articles&article=2_drools_hibernate&lang=en

Cheers,
 Jarek

Senlin Liang wrote:

Thanks.  Where could I find the related manual or instructions? I
searched through the doc for drools, and the email archive, there is
really no good example or explanation on how to achieve this.

(What I want is to insert, select or delete some objects in relational
database such as mysql.)

Any information is greatly appreciated.
Thanks.

On Tue, Jul 8, 2008 at 4:20 AM, Anstis, Michael (M.) <[EMAIL PROTECTED]> wrote:

Have a look at an example posted earlier this week whereby somebody
(sorry I forget who) was using JPA from within a rule.

Once you understand how JPA was used then the remaining questions relate
more specifically to JPA.

As Mark says, (native) Hibernate can also be used very easily.

With kind regards,

Mike


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Senlin Liang
Sent: 08 July 2008 03:18
To: Rules Users List
Subject: [rules-users] One question about Database interface

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?

Thanks,
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users







___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] One question about Database interface

2008-07-08 Thread Senlin Liang
Thanks.  Where could I find the related manual or instructions? I
searched through the doc for drools, and the email archive, there is
really no good example or explanation on how to achieve this.

(What I want is to insert, select or delete some objects in relational
database such as mysql.)

Any information is greatly appreciated.
Thanks.

On Tue, Jul 8, 2008 at 4:20 AM, Anstis, Michael (M.) <[EMAIL PROTECTED]> wrote:
> Have a look at an example posted earlier this week whereby somebody
> (sorry I forget who) was using JPA from within a rule.
>
> Once you understand how JPA was used then the remaining questions relate
> more specifically to JPA.
>
> As Mark says, (native) Hibernate can also be used very easily.
>
> With kind regards,
>
> Mike
>
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Senlin Liang
> Sent: 08 July 2008 03:18
> To: Rules Users List
> Subject: [rules-users] One question about Database interface
>
> 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?
>
> Thanks,
> Senlin Liang
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] One question about Database interface

2008-07-08 Thread Ojwang Wilson O

Hi Senlin,

It will be easy to use JPA. Here is an example.
===
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.


public class DroolsTest {

   public static final void main(String[] args) {
   try {
  
   //load up the rulebase

   RuleBase ruleBase = readRule();
   WorkingMemory workingMemory = ruleBase.newStatefulSession();
  
// Start EntityManagerFactory

   EntityManagerFactory emf =
   Persistence.createEntityManagerFactory("persons");

   // Second unit of work
   EntityManager newEm = emf.createEntityManager();
   EntityTransaction newTx = newEm.getTransaction();
   newTx.begin();
  
   workingMemory.setGlobal("entity",newEm);

   ArrayList presult = new ArrayList();
   workingMemory.setGlobal("presult",presult);
   workingMemory.fireAllRules();
  
   System.out.println("=List Results=");

   for ( Person p : presult ){
System.out.println("Person: \"" + p.getFirstName() +
"\", " + p.getLastName() +   
"\", " + p.getAge());

   }
   System.out.println("=End List 
Results=\n\n");
   newTx.commit();

   newEm.close();
// Shutting down the application
   emf.close();

   } catch (Throwable t) {

   t.printStackTrace();
   }
   }
  /**
* Please note that this is the "low level" rule assembly API.
*/
   private static RuleBase readRule() throws Exception {
   //read in the source
   Reader source = new InputStreamReader( 
DroolsTest.class.getResourceAsStream( "/Sample.drl" ) ); 
   PackageBuilder builder = new PackageBuilder(); 
   builder.addPackageFromDrl( source );


   //get the compiled package (which is serializable)
   Package pkg = builder.getPackage();
  
   //add the package to a rulebase (deploy the rule package).

   RuleBase ruleBase = RuleBaseFactory.newRuleBase();
   ruleBase.addPackage( pkg );
   return ruleBase;
   }
}

==
Here is the rule sample.drl

package com.sample

import com.sample.DroolsTest.Message;
import com.sample.Person;
import javax.persistence.EntityManager;
global javax.persistence.EntityManager entity;
global java.util.ArrayList presult;


rule "age"
   when
   $p: Person() from entity.createQuery("from Person p where p.age 
<= 20").getResultList();

   then
   presult.add($p);
end

==

Wilson


Senlin Liang wrote:

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 <[EMAIL PROTECTED]> wrote:
  

Senlin Liang wrote:


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?

  

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.


Thanks,
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


  

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users






  
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] One question about Database interface

2008-07-08 Thread Anstis, Michael (M.)
Have a look at an example posted earlier this week whereby somebody
(sorry I forget who) was using JPA from within a rule.

Once you understand how JPA was used then the remaining questions relate
more specifically to JPA.

As Mark says, (native) Hibernate can also be used very easily.

With kind regards,

Mike
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Senlin Liang
Sent: 08 July 2008 03:18
To: Rules Users List
Subject: [rules-users] One question about Database interface

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?

Thanks,
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] One question about Database interface

2008-07-07 Thread Mark Proctor

Senlin Liang wrote:

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?
  
you use hibernate to retrieve the items from your relational database 
and drools to reason over them using the 'from' keyword.

Thanks

On Mon, Jul 7, 2008 at 10:32 PM, Mark Proctor <[EMAIL PROTECTED]> wrote:
  

Senlin Liang wrote:


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?

  

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.


Thanks,
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


  

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users






  


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] One question about Database interface

2008-07-07 Thread Senlin Liang
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 <[EMAIL PROTECTED]> wrote:
> Senlin Liang wrote:
>>
>> 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?
>>
>
> 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.
>>
>> Thanks,
>> Senlin Liang
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] One question about Database interface

2008-07-07 Thread Mark Proctor

Senlin Liang wrote:

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?
  
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.

Thanks,
Senlin Liang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

  


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users