Hi,

How about using xbean/spring as in the referenced blog to populate the
Drools globals map with key/value pairs, the key being the datasource name
and the value begin a DbHelper instance that wraps the corresponding
datasource instance? In the drools file, one can reference the desired
DbHelper by datasource name key. Using this technique, there should be no
need to package the DbHelper class within the Drools SE component.

- Ron


Andrea Zoppello-2 wrote:
> 
> Hi all,
> 
> I need to use drools servicemix component, and in my rules, i need to 
> use a db helper object to
> evaluate some rule conditions against database.
> 
> I've just read the very good approach, proposed in 
> http://gnodet.blogspot.com/2007/06/accessing-databases-in-servicemix.html.
> 
> The only problem, that i've with this approach is that some of my 
> customer, want to have in
> the dbhelper methods, a parameter that switch the datasource to use for 
> a query:
> 
> for example they want to write something like:
> 
> 
> package org.apache.servicemix.drools
>  
> import org.apache.servicemix.drools.model.Exchange;
> import org.apache.servicemix.drools.model.DbHelper;
> global org.apache.servicemix.drools.model.JbiHelper jbi;
> 
>     rule "Rule1"
>     when
>         me : Exchange( status == Exchange.ACTIVE, in : in != null );
>         db : DbHelper ( );
>         eval( db.exist( in.valueOf("/ACTION/@name"), "STRING", 
> "attribute", "name", "ds1" ) );
>     then
>         jbi.fault( "<ERROR> The value is already present in db </ERROR>"
> );
>     end
> 
>     rule "Rule1"
>     when
>         me : Exchange( status == Exchange.ACTIVE, in : in != null );
>         db : DbHelper ( );
>         eval( db.exist( in.valueOf("/ACTION/@name"), "STRING", 
> "attribute", "name", "ds2" ) );
>     then
>         jbi.fault( "<ERROR> The value is already present in db </ERROR>"
> );
>     end
> 
> where the last parameter of db.exist method identidies the datasource 
> and they could have rules that
> switch from ds1 to ds2.
> 
> To do this it could be enough to have an object that let's my helper to 
> access the jndi context of servicemix.
> 
> To get this type of behaviour at the moment, we've a customized version 
> of servicemix-drools, but
> in future i'd like to rely on the standard component.
> 
> Is this possible to achieve this, maybe injectiong in a helper object 
> that lets me to access to jndi of servicemix???
> 
> 
> Thanks in advance
> 
> 
> Andrea
> 
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Drools-DbHelper-Question...-tp15157362s12049p15167168.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to