[rules-users] Maintaining DB/Working Memory Synchronization

Dan Miller dmiller at versatile.com
Sat Nov 7 01:56:12 EST 2009


Greg Barton <greg_barton <at> yahoo.com> writes:

> 
> I don't think there's a built in way to do this with drools, but in general
this is done using database
> triggers.  The trigger fires when the data changes, and from there it's up to
you how the record is
> transported to working memory.  
> 
> If you use oracle there's a specific mechanism for this called "Database
Change Notification"
> 
> --- On Fri, 11/6/09, Daniel Miller <dmiller <at> versatile.com> wrote:
> 
> > From: Daniel Miller <dmiller <at> versatile.com>
> > Subject: [rules-users] Maintaining DB/Working Memory Synchronization
> > To: rules-users <at> lists.jboss.org
> > Date: Friday, November 6, 2009, 2:43 PM
> > So I hope that someone out here, or
> > many of you, can give me some idea  
> > of how you do this.
> > 
> > I have about 20+ entities in my database that I want Drools
> > to know  
> > about.  Obviously my hope is to apply CEP, rules and
> > processes to  
> > these items.  However, I feel like I'm missing some
> > type of connection  
> > between how Drools recommends keeping my working memory in
> > sync with  
> > my database changes.
> > 
> > Ideally, I'd love to be able to just update my entities as
> > I have been  
> > doing in the database, but have those changes automatically
> > move their  
> > way over into the working memory.  How do any of you
> > recommend I  
> > accomplish this?
> > 
> > Thanks in advance for any suggestions.
> > 
> > Dan Miller 
> >   
> > _______________________________________________
> > rules-users mailing list
> > rules-users <at> lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> > 
> 
> _______________________________________________
> rules-users mailing list
> rules-users <at> lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

Thanks for the suggestion. 

So I did something similar, not using database triggers, but trying something I
saw in a blog post.  I modified my rule so that instead of loading the working
memory and then firing the rules, the rule does something like this: 

rule
    when
        a : AssetRemote(assetType='Temperature Probe',removed=false) from
assetService.getAllUndeletedAssets();
    then
       //do some work here
end

"assetService" is my service class that does my query to the database and
returns a List<AssetRemote> objects.

This worked great -- except it only fired once.  There are no objects in my
working memory, but if I call fireAllRules(), this rule gets ignored the second,
third, nth time it's fired. 

What am I missing?  Before I was manually calling an update(a); in the "then"
section to refresh the session on the object.  But, since there are no objects
using the from method, I don't know how to refresh the session so that this rule
will fire each time fireAllRules() is called. 

Keep the suggestions coming though.

Thanks, 

Dan Miller








More information about the rules-users mailing list