Updating an existing fact w/o using fact handle
by Fenderbosch, Eric
Is it required to use WorkingMemory.update to update an existing fact?
I thought if assert behavior was set to equality and you implemented the
equals method properly, then you could simply use WorkingMemory.insert
to overwrite a fact in working memory with a new version. If this isn't
the case, then are there other settings that will give this behavior?
I'm using 4.0.7.
Thanks for any help.
Eric
Here's my RuleBaseConfiguration:
AlphaNodeHashingThreshold : 3
CompositeKeyDepth : 3
ExecutorServiceorg.drools.concurrent.DefaultExecutorService
RuleBaseUpdateHandler :
org.drools.base.FireAllRulesRuleBaseUpdateListener
AgendaGroupFactory :
org.drools.common.PriorityQueueAgendaGroupFactory@17653ae
AssertBehaviour : equality
ConflictResolver : org.drools.conflict.DepthConflictResolver@16fe0f4
ConsequenceExceptionHandler :
org.drools.base.DefaultConsequenceExceptionHandler@19d0a1
LogicalOverride : discard
SequentialAgenda : sequential
AlphaMemory : false
IndexLeftBetaMemory : true
IndexRightBetaMemory : true
MaintainTms : true
RemoveIdenities : true
Sequential : false
ShadowProxy : true
ShareAlphaNodes : true
ShareBetaNodes : true
UseStaticObjensis : false
My TestFact class:
public class TestFact {
private String id;
private String value;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public int hashCode() {
return id.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof TestFact)) return false;
TestFact other = (TestFact) obj;
// not null safe, i know
return this.id.equals(other.id);
}
}
And the JUnit Test Case that fails:
public void testFactUpdate() throws Exception {
TestFact testFact = new TestFact();
testFact.setId("1234");
testFact.setValue("old");
FactHandle testFactHandle =
workingMemory.insert(testFact);
TestFact updatedFact = new TestFact();
updatedFact.setId("1234");
updatedFact.setValue("new");
FactHandle updatedFactHandle =
workingMemory.insert(updatedFact);
// using workingMemory.update here works
// passes
assertTrue(testFactHandle == updatedFactHandle);
TestFact retrievedTestFact = (TestFact)
workingMemory.getObject(testFactHandle);
// fails
assertEquals("new", retrievedTestFact.getValue());
}
18 years
phone number validation using drools
by Nagaraju runkana
Hi ,
i am trying validate complex expression for phone numberl?
rule "test2"
when
$m : Message(email:email,phone:phone)
Message(phone matches
"^(([\\+]?\\d{1,3}(-|\\.)?\\(?\\w\\)?(-|\\.)?\\d{1,3})|(
\\(?\\d{2,3}\\)?))(-|\\.)?(\\d{3,4})(-|\\.)?(\\d{4<file://(/?\\d{2,3}\\)?))(-|\\.)?(\\d{3,4})(-|\\.)?(\\d{4>})((
x| ext)\\d{1,5}){0,1}$"
then
System.out.println("Invalid phone number: " + phone );
end "
in this case some error should be comming.pls find out whethere the
expression is correct or not.
java.util.regex.PatternSyntaxException: Unknown inline modifier near index
21
^(([+]?d{1,3}(-|.)?(?w)?(-|.)?d{1,3})|((?d{2,3})?))(-|.)?(d{3,4})(-|.)?(d{4})((
x| ext)d{1,5}){0,1}$
^
at java.util.regex.Pattern.error(Pattern.java:1713)
at java.util.regex.Pattern.group0(Pattern.java:2519)
at java.util.regex.Pattern.sequence(Pattern.java:1806)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.group0(Pattern.java:2530)
at java.util.regex.Pattern.sequence(Pattern.java:1806)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.group0(Pattern.java:2530)
at java.util.regex.Pattern.sequence(Pattern.java:1806)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.compile(Pattern.java:1460)
at java.util.regex.Pattern.<init>(Pattern.java:1133)
at java.util.regex.Pattern.compile(Pattern.java:823)
at java.util.regex.Pattern.matches(Pattern.java:928)
at java.lang.String.matches(String.java:2091)
at
org.drools.base.evaluators.StringFactory$StringMatchesEvaluator.evaluate(StringFactory.java:211)
at org.drools.rule.LiteralRestriction.isAllowed(LiteralRestriction.java:61)
at org.drools.rule.LiteralConstraint.isAllowed(LiteralConstraint.java:82)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:132)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:318)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
at org.drools.reteoo.Rete.assertObject(Rete.java:175)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at
org.drools.reteoo.ReteooWorkingMemory.doInsert(ReteooWorkingMemory.java:71)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:909)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:881)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:682)
at com.sample.DroolsTest.main(DroolsTest.java:40)
regards,
Chanti
18 years
creating package files through ant script
by Shreekanta Prasad
Hi All,
While generating .pkg files from ant scripts using custom ant task
which calls org.drools.contrib.DroolsCompilerAntTask class.
Is it not possible to use excel spreadsheets for decision table with
drools-ant task?
Is there any custom ant solution for converting xls file to drl file?
Internally xls file will be converted into drl file when we use BRMS
web client application.
So why this drools-ant module is not taking xls input?
Please revert me if you have some idea as early as possible.
Thanks and Regards -
Shreekanta Prasad
Bangalore,India.
18 years