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, 1 month
Don't process rules when adding new package to rulebase
by Barraq
Hi there,
I'm developing a library that uses drools as a REAL-TIME rule engine. What
i'm a doing right now is to have a thread that wakes up each 100ms and do a
fireAllRules(1000).
I need to be able to load Facts and Rules on the fly, even after the
statefullsession is created. The problem is that when i add a new
RulePackage to the current rulebase's session, all the rules inside this
package are evaluated ! and so i never exit from this addPackage function !!
System.out.println("Start loading rules");
// build builder package configuration
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
conf.setClassLoader(factionary);
// Load file
File file = new File(chooser.getSelectedFile().getPath());
PackageBuilder builder = new PackageBuilder(conf);
builder.addPackageFromDrl(new FileReader(file));
// Load package to session
session.getRuleBase().addPackage(builder.getPackage()); // GET STUCK HERE
!!!!!!!!!!!
// Print success
jTextArea2.append(chooser.getSelectedFile().getPath()+"\n");
jTextArea2.setCaretPosition(jTextArea1.getDocument().getLength());
System.out.println("Done loading rules");
What i want is just to add the rules from the package that's all.... Since
i've a thread that call fireAllRules(1000) each 100ms the rules will get
proceced next time :)
Do you have any idea of how to do that ?
Thanks.
Barraquand Rémi
--
View this message in context: http://www.nabble.com/Don%27t-process-rules-when-adding-new-package-to-ru...
Sent from the drools - user mailing list archive at Nabble.com.
18 years, 1 month
Using global in LHS
by Markus Helbig
Hi,
again a question, any body had success using globals in LHS?
Following DSL
[condition][]is a Item=Item()
[condition][]-is of type Advertisment=advertisment contains catId
rule
when
$pli: is a Item
- is of type Advertisment
then
// do whatever you want
end
catId is a member of Item
advertisment is a Integer[] array set as global
comiling ends with:
Unable to create Field Extractor for 'advertisment' of '[ClassObjectType
It works fine if advertisment is a member of Item, but i want to have
it as global ...
Cheers
Markus
18 years, 1 month
Re: [rules-users] how to write regular expressions in drools..
by Christine
Chanti,
what exactly is your question?
I think that checking zipcode and credit card formats is easier to do in
java than with rules. Rules are more efficient in more complex situations,
like when you have multiple objects that need to meet various conditions.
Christine
On Fri, May 30, 2008 09:24, Nagaraju runkana wrote:
> HI Guys,
>
> present i am using drools 4.0 in this case.now, i am writting some rules
> validation using regular expression ZIPCODE,EMAIL,CREDIT CARD number.like
> this..
> --------------------
> validation.dslr
> --------------------
> rule "email.mandatory:[insert][update][ui]"
> when
> There is an Order
> Order email address checking for first letter
> then
> Reject with response : "email address must not start with @ "
> end
> rule "phone.mandatory:[insert][update][ui]"
> when
> There is an Order
> Order phone number format should checking
> then
> Reject with response : "The phone number you entered is not valid.Please
> enter a phone number with the format xxx-xxx-xxxx."\
> end
> -----------------------
> validation.dsl
> --------------------
> [*][]Order email address checking for first letter= OrderBean(email
> matches
> "@[A-Za-z0-9]*")
> [*][]Order phone number format should checking=OrderBean( phone not
> matches
> "(/\d{3}\-\d{3}\-\d{4}/)==-1)")
> this rules are not working ...any one can help me.ASAP
>
> thanks,
> chanti
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
18 years, 1 month
RE: [rules-users] Re: To know about correct Drools rule file (drl)syntaxes
by Christine
On Thu, May 29, 2008 16:17, Hareendra Pelige wrote:
> According to your experience, which rule file language is commonly used?
I would say that this syntax from your email is easiest to use. As Mark
explained, the xml-type language is old, version 2.0. You can define a
domain specific language, but that's worth the effort only in larger
projects, I'd say.
Christine
rule "Hello World"
when
m : Message( status == Message.HELLO, message : message)
then
System.out.println( message );
modify ( m ) { message = "Goodbyte cruel world",
status = Message.GOODBYE };
System.out.println( message );
end
18 years, 1 month