Hi Andrea,
In your environment, would it be a problem to prompt users up front for the
list of datasource names they want to access from their specific Drools
semantic validator? Based on this list of datasource names, you could
generate an appropriately configured xbean file that injects either
individual Datasources as globals into your Drools file or individual
DbHelpers that encapsulate the Datasource into the Drools file. This may be
a little more straightforward for Drools writers than forcing them to work
directly with an InitialContext and perform JNDI context lookups themselves?
Any thoughts?
- Ron
Andrea Zoppello-2 wrote:
>
> Hi,
>
> Suggestions made by you and ron are *correct* and i agree with you,
> but all of this has the requirement *to have datasource declared in
> xbean.xml in spring
> way* my users instead wants to have "datasource entry name as
> parameters" without having
> this declared in xbean.xml as spring beans.
>
>
> Is so complicated to get injected a bean that could access jndi
> information, in the dbhelper???
>
> Andrea
>
> Guillaume Nodet ha scritto:
>> Why don't you define two databases in your own DbHelper:
>>
>> <drools:endpoint service="test:service"
>> endpoint="endpoint"
>> ruleBaseResource="classpath:router.drl"
>> globals="#globals" />
>> <util:map id="globals">
>> <entry key="helper" value-ref="helper" />
>> </util:map>
>> <bean id="helper" class="DbHelper" />
>> <bean id="ds1"
>> class="org.springframework.jndi.JndiObjectFactoryBean">
>> <property name="jndiName" value="java:ds1" />
>> </bean>
>> <bean id="ds2"
>> class="org.springframework.jndi.JndiObjectFactoryBean">
>> <property name="jndiName" value="java:ds2" />
>> </bean>
>> </bean>
>>
>> Then in your drools rules:
>>
>> package org.apache.servicemix.drools
>>
>> global DbHelper helper;
>> global DataSource ds1;
>> global DataSource ds2;
>>
>> rule "Rule1"
>> when
>> eval( db.exist( in.valueOf("/ACTION/@name"), "STRING", "attribute",
>> "name", ds1 ) );
>>
>> That way, you just need to patch the DbHelper so that it can take an
>> optional argument which is a dataSource
>> instead of using the one that is configured on the DbHelper.
>> It should be possible to include such a patch.
>>
>> On Jan 30, 2008 9:04 AM, Andrea Zoppello <[EMAIL PROTECTED]> wrote:
>>
>>> Hi.
>>>
>>> I don't understand quite well this approach. Could you provide an
>>> example please.
>>>
>>> But it could be more useful, to inject in dbhelper an object that give
>>> me the access to
>>> JNID tree of servicemix.
>>>
>>> Is there a way to do this, now in my customized version od DroolsHelper
>>> i get the context and
>>> i pass to dbhelper as follow.
>>>
>>> protected void populateWorkingMemory(WorkingMemory memory,
>>> MessageExchange exchange) throws Exception {
>>> memory.setGlobal("jbi", new JbiHelper(this, exchange, memory));
>>> EndpointComponentContext aContext =
>>> (EndpointComponentContext)getContext();
>>> InitialContext jndiContext = aContext.getNamingContext();
>>> memory.assertObject(new DbHelper(jndiContext));
>>> }
>>>
>>> What i need is only a way to inject such object in spring xbean file.
>>>
>>> Is this possible??
>>>
>>>
>>>
>>>
>>> rgavlin ha scritto:
>>>
>>>
>>>> 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...-tp15157362s12049p15179297.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.