[jboss-svn-commits] JBL Code SVN: r17408 - in labs/jbossrules/branches/4.0.x: drools-core/src/main/java/org/drools/base and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 26 15:47:36 EST 2007
Author: tirelli
Date: 2007-12-26 15:47:36 -0500 (Wed, 26 Dec 2007)
New Revision: 17408
Modified:
labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
Log:
JBRULES-1308: fixing the getFactHandle() method contract
Modified: labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2007-12-26 12:05:02 UTC (rev 17407)
+++ labs/jbossrules/branches/4.0.x/drools-compiler/src/test/java/org/drools/integrationtests/MiscTest.java 2007-12-26 20:47:36 UTC (rev 17408)
@@ -42,6 +42,7 @@
import org.drools.Attribute;
import org.drools.Cell;
import org.drools.Cheese;
+import org.drools.CheeseEqual;
import org.drools.Cheesery;
import org.drools.Child;
import org.drools.FactA;
@@ -4637,5 +4638,33 @@
1,
list.size() );
}
+
+ public void testGetFactHandleEqualityBehavior() throws Exception {
+ final RuleBaseConfiguration conf = new RuleBaseConfiguration();
+ conf.setAssertBehaviour( RuleBaseConfiguration.AssertBehaviour.EQUALITY );
+ final RuleBase ruleBase = RuleBaseFactory.newRuleBase( conf );
+ final StatefulSession session = ruleBase.newStatefulSession();
+
+ CheeseEqual cheese = new CheeseEqual("stilton", 10);
+ session.insert(cheese);
+ FactHandle fh = session.getFactHandle(new CheeseEqual("stilton", 10));
+ assertNotNull(fh);
+ }
+
+ public void testGetFactHandleIdentityBehavior() throws Exception {
+ final RuleBaseConfiguration conf = new RuleBaseConfiguration();
+ conf.setAssertBehaviour( RuleBaseConfiguration.AssertBehaviour.IDENTITY );
+ final RuleBase ruleBase = RuleBaseFactory.newRuleBase( conf );
+
+ final StatefulSession session = ruleBase.newStatefulSession();
+
+ CheeseEqual cheese = new CheeseEqual("stilton", 10);
+ session.insert(cheese);
+ FactHandle fh1 = session.getFactHandle(new Cheese("stilton", 10));
+ assertNull(fh1);
+ FactHandle fh2 = session.getFactHandle( cheese );
+ assertNotNull(fh2);
+ }
+
}
Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java 2007-12-26 12:05:02 UTC (rev 17407)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/base/DefaultKnowledgeHelper.java 2007-12-26 20:47:36 UTC (rev 17408)
@@ -88,7 +88,7 @@
}
public void update(final Object object) throws FactException {
- FactHandle handle = this.workingMemory.getFactHandle( object );
+ FactHandle handle = this.workingMemory.getFactHandleByIdentity( object );
if ( handle == null ) {
throw new FactException( "Update error: handle not found for object: " + object + ". Is it in the working memory?" );
}
@@ -108,7 +108,7 @@
}
public void retract(final Object object) throws FactException {
- FactHandle handle = this.workingMemory.getFactHandle( object );
+ FactHandle handle = this.workingMemory.getFactHandleByIdentity( object );
if ( handle == null ) {
throw new FactException( "Retract error: handle not found for object: " + object + ". Is it in the working memory?" );
}
@@ -120,7 +120,7 @@
}
public void modifyRetract(final Object object) {
- FactHandle handle = this.workingMemory.getFactHandle( object );
+ FactHandle handle = this.workingMemory.getFactHandleByIdentity( object );
this.workingMemory.modifyRetract( handle, rule, activation );
}
@@ -129,7 +129,7 @@
}
public void modifyInsert(final Object object) {
- FactHandle handle = this.workingMemory.getFactHandle( object );
+ FactHandle handle = this.workingMemory.getFactHandleByIdentity( object );
this.workingMemory.modifyInsert( handle, object, rule, activation );
}
Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2007-12-26 12:05:02 UTC (rev 17407)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2007-12-26 20:47:36 UTC (rev 17408)
@@ -581,6 +581,20 @@
public FactHandle getFactHandle(final Object object) {
try {
this.lock.lock();
+ final FactHandle factHandle = (FactHandle) this.assertMap.get( object );
+
+ return factHandle;
+ } finally {
+ this.lock.unlock();
+ }
+ }
+
+ /**
+ * @see InternalWorkingMemory
+ */
+ public FactHandle getFactHandleByIdentity(final Object object) {
+ try {
+ this.lock.lock();
final FactHandle factHandle = (FactHandle) this.identityMap.get( object );
return factHandle;
Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java 2007-12-26 12:05:02 UTC (rev 17407)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java 2007-12-26 20:47:36 UTC (rev 17408)
@@ -46,6 +46,16 @@
public void queueWorkingMemoryAction(final WorkingMemoryAction action);
public FactHandleFactory getFactHandleFactory();
+
+ /**
+ * Looks for the fact handle associated to the given object
+ * by looking up the object IDENTITY (==), even if rule base
+ * is configured to AssertBehavior.EQUALITY.
+ *
+ * @param object
+ * @return null if fact handle not found
+ */
+ public FactHandle getFactHandleByIdentity(final Object object);
public void removeLogicalDependencies(final Activation activation,
final PropagationContext context,
More information about the jboss-svn-commits
mailing list