Modify / Update element in ArrayList in working memory in rule Drools -
we working on rule structured follows:
- we have list contains validated , non-validated elements. difference between validated , non-validated done giving different status elements.
- we obtain non-validated elements list.
- each non-validated element compared validated elements in same list.
- after comparison non-validated element become validated element needs considered when validating non-validated elements.
the problem arises when want update original arraylist of elements. need able update non-validated element has become validated in original arraylist in working memory loop can take "refreshed" arraylist account.
three questions:
first of all, exact difference between using modify , update in drools. according drools documentation:
"on right hand side of rule modifystatement recommended, makes changes , notifies engine in single statement."
so difference between 1 , other simple semantics like:
modify( $sprinkler ) { seton( true ) };
and
$sprinkler.seton(true); update($sprinkler);
is assumption correct?
secondly, possible update or modify specific element within arraylist in working memory in drools without using plain java iterator (a "for"). in our case each element identified unique id obtain list have valid reference updating status (validated or non-validated).
finally, aware updating working memory cause rule fire again. let's have arraylist 2 non-validated items. if obtain non-validated items validate them, create rule "first" fires twice, each non-validated item once:
rule "first" when $listofelements : java.util.arraylist ( ) $itemstovalidate : element ( status == "not validated" ) $listofelements //do or not end
if in second rule validate items , wish change status of non-validated element validated in working memory this:
rule "second" extends "first" when //we validate attributes of non-validated element against attributes of validated elements //my second question if possible (solution without java iterator) $itemstovalidate.setstatus("validated") modify ($listofelements) { $itemstovalidate }; end
how affect whole process? actualisation of working memory provoke first rule reevaluated. rule launched twice because had encountered 2 non-validated elements. remaining element evaluated once or more once?
the answer first question there no difference between 2 snippets. (statements inserted between 2 of second 1 influence answer.)
the scenario second question doesn't use update in same form. inserting list fact operating on list elements considered bad. insert list elements. container may or may not useful container holding list elements 1 transaction or whatever.
Comments
Post a Comment