[rules-users] Difference between constraint within a pattern and eval

Mohan mohan at hp.com
Fri Oct 26 12:51:13 EDT 2007


Found the problem, it something do with the getters declared as final. Here
is test case

Test1
DRL: 
package test.drools;

import test.Experience;

rule "test1"
	dialect "mvel"
	when
		exp : Experience( primary == "something" )
	then
		System.out.println(">>>>>>>test1");
end

rule "test2"
	dialect "mvel"
	when
		exp : Experience( eval(exp.getPrimary() == "something") )
	then
		System.out.println(">>>>>>>test2");
end

Fact:
/**
 * rajgo - Oct 26, 2007
 */
package test;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @author rajgo
 */
public class Experience implements Serializable {

	/**
	 * long serialVersionUID.
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * String primary.
	 */
	private String primary;

	/**
	 * Set secondary.
	 */
	private final Set<String> secondary = new HashSet<String>();

	/**
	 * rajgo - Oct 26, 2007.
	 * 
	 * @return primary
	 */
	public final String getPrimary() {
		return this.primary;
	}

	/**
	 * rajgo - Oct 26, 2007.
	 * 
	 * @return secondary
	 */
	public final Set<String> getSecondary() {
		return this.secondary;
	}

	/**
	 * rajgo - Oct 26, 2007.
	 * 
	 * @param pPrimary
	 *            primary
	 */
	public final void setPrimary(final String pPrimary) {
		this.primary = pPrimary;
	}
}

Outcome:
>>>>>>>test2

Test2
Removing the final keyword from getPrimary. DRL is same, Fact class changed
to 

Fact:
/**
 * rajgo - Oct 26, 2007
 */
package test;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @author rajgo
 */
public class Experience implements Serializable {

	/**
	 * long serialVersionUID.
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * String primary.
	 */
	private String primary;

	/**
	 * Set secondary.
	 */
	private final Set<String> secondary = new HashSet<String>();

	/**
	 * rajgo - Oct 26, 2007.
	 * 
	 * @return primary
	 */
	public String getPrimary() {
		return this.primary;
	}

	/**
	 * rajgo - Oct 26, 2007.
	 * 
	 * @return secondary
	 */
	public final Set<String> getSecondary() {
		return this.secondary;
	}

	/**
	 * rajgo - Oct 26, 2007.
	 * 
	 * @param pPrimary
	 *            primary
	 */
	public final void setPrimary(final String pPrimary) {
		this.primary = pPrimary;
	}
}

Outcome:
>>>>>>>test1
>>>>>>>test2

BTW, i upgrade drools to 4.0.3 and still can replicate the issue.

Searching jira I found the bug reported on this problem : 
http://jira.jboss.com/jira/browse/JBRULES-1111 Final methods of POJO's aer
never evaluated 
Please update documentation 

Thanks

--Mohan

(Note to self : Smart thing to do is first search buglist before wasting
time)


-- 
View this message in context: http://www.nabble.com/Difference-between-constraint-within-a-pattern-and-eval-tf4688141.html#a13431172
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list