Skip to content

Commit

Permalink
[DROOLS-707] implement clone of MVELDataProvider
Browse files Browse the repository at this point in the history
(cherry picked from commit ef552a6)
  • Loading branch information
mariofusco committed Feb 12, 2015
1 parent a7b0cdd commit eec8bfc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7141,4 +7141,24 @@ public void testPassiveExists() {

assertEquals(4, ksession.fireAllRules());
}

@Test
public void testFromAfterOr() {
// DROOLS-707
String drl2 =
"rule \"Disaster Rule\"\n" +
" when\n" +
" eval(true) or ( eval(false) and Integer() )\n" +
" $a : Integer()\n" +
" Integer() from $a\n" +
" then\n" +
"end\n";

KieSession ksession = new KieHelper().addContent(drl2, ResourceType.DRL)
.build()
.newKieSession();

ksession.insert(1);
assertEquals(1, ksession.fireAllRules());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class MVELDataProvider
implements
Expand All @@ -54,6 +56,8 @@ public class MVELDataProvider

private Serializable expr;

private List<MVELDataProvider> clones;

public MVELDataProvider() {

}
Expand All @@ -68,21 +72,23 @@ public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
id = in.readUTF();
unit = (MVELCompilationUnit) in.readObject();
// expr = (Serializable)in.readObject();
// prototype = (DroolsMVELFactory)in.readObject();
clones = (List<MVELDataProvider>) in.readObject();
}

public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF( id );
out.writeObject( unit );
// out.writeObject(expr);
// out.writeObject(prototype);
out.writeObject(unit);
out.writeObject( clones );
}

@SuppressWarnings("unchecked")
public void compile(MVELDialectRuntimeData runtimeData) {
expr = unit.getCompiledExpression( runtimeData );

if (clones != null) {
for (MVELDataProvider clone : clones) {
clone.expr = clone.unit.getCompiledExpression(runtimeData);
}
}
// @TODO URGENT DO NOT FORGET!!!!
// Map previousDeclarations = this.unit.getFactory().getPreviousDeclarations();
// this.requiredDeclarations = (Declaration[]) previousDeclarations.values().toArray( new Declaration[previousDeclarations.size()] );
Expand Down Expand Up @@ -130,9 +136,12 @@ public Iterator getResults(final Tuple tuple,
}

public DataProvider clone() {
// not sure this is safe, but at this point we don't have a classloader
// reference to compile a new copy of the data provider. My require
// refactory later.
return this;
MVELDataProvider clone = new MVELDataProvider(unit.clone(), id);
clone.expr = expr;
if (clones == null) {
clones = new ArrayList<MVELDataProvider>();
}
clones.add(clone);
return clone;
}
}

0 comments on commit eec8bfc

Please sign in to comment.