[jboss-jira] [JBoss JIRA] Commented: (JBRULES-695) Cannot reference a global in a query.

Edson Tirelli (JIRA) jira-events at lists.jboss.org
Mon Feb 26 14:30:36 EST 2007


    [ http://jira.jboss.com/jira/browse/JBRULES-695?page=comments#action_12354355 ] 
            
Edson Tirelli commented on JBRULES-695:
---------------------------------------

Jack,

I see the problem and we will fix it for 3.2 version. 
To work around the problem in 3.0.x and while we don't have the fix, make your global be referenced inside a return value constraint. In other words, just add () around it:

cardholderobj : CardHolder (cardnum == ( gbl_deletecardnumber ) ) 

This shall make it work.

As soon as I commit the fix I will let you know.

Edson

> Cannot reference a global in a query.
> -------------------------------------
>
>                 Key: JBRULES-695
>                 URL: http://jira.jboss.com/jira/browse/JBRULES-695
>             Project: JBoss Rules
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>    Affects Versions: 3.0.5, 3.0.4
>         Environment: Windows XP using JBoss Eclipse IDE with drools plugin.
>            Reporter: Jack Curtin
>         Assigned To: Edson Tirelli
>
> I have a query that references a global, and I get the following error during startup:
> org.drools.rule.InvalidRulePackage: Unable to return Declaration for identifier 'gbl_deletecardnumber'
> Relevant code from rule file follows:
> import java.lang.String;
> import com.m2syscorp.i24card.rulesengine.facts.CardHolder;
> global String gbl_deletecardnumber
> query "delete cardholder"
>      cardholderobj : CardHolder (cardnum == gbl_deletecardnumber)
> end;
> Relevant Java code follows:
> public class CardHolder implements Serializable {
>     private String cardnum;
> 	public String getCardnum() {
> 		return cardnum;
> 	}
> 	public void setCardnum(String cardnum) {
> 		this.cardnum = cardnum;
> 	}
> }
>     public void deleteCardHolderFromWorkingMemory(WorkingMemory workingMemory, String sDeleteCardNumber) {
>     	
>     	workingMemory.setGlobal("gbl_deletecardnumber", sDeleteCardNumber);    	
>     	QueryResults results = workingMemory.getQueryResults("delete cardholder");
>     	for (Iterator it = results.iterator(); it.hasNext(); ) {
>     		QueryResult result = (QueryResult) it.next();
>     		CardHolder chDelObj = (CardHolder) result.get("cardholderobj");
>     		FactHandle fhCardHolder = workingMemory.getFactHandle(chDelObj);
>     		workingMemory.retractObject(fhCardHolder);
>     		break;  // should only be one matching CardHolder object.
>     	}
>     }
> As you can see from the Java code, my goal is to be able to set the global variable gbl_deletecardnumber with a card number string, call the query which will find the CardHolder object with the matching card number, and then retract that object.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list