use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class MVELEvalBuilderTest method testSimpleExpression.
@Test
public void testSimpleExpression() {
InternalKnowledgePackage pkg = new KnowledgePackageImpl("pkg1");
final RuleDescr ruleDescr = new RuleDescr("rule 1");
KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg);
final KnowledgeBuilderConfigurationImpl conf = pkgBuilder.getBuilderConfiguration();
DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
MVELDialect mvelDialect = (MVELDialect) dialectRegistry.getDialect("mvel");
final RuleBuildContext context = new RuleBuildContext(pkgBuilder, ruleDescr, dialectRegistry, pkg, mvelDialect);
final InstrumentedDeclarationScopeResolver declarationResolver = new InstrumentedDeclarationScopeResolver();
final InternalReadAccessor extractor = store.getReader(Cheese.class, "price");
final Pattern pattern = new Pattern(0, new ClassObjectType(int.class));
final Declaration declaration = new Declaration("a", extractor, pattern);
final Map map = new HashMap();
map.put("a", declaration);
declarationResolver.setDeclarations(map);
context.setDeclarationResolver(declarationResolver);
final EvalDescr evalDescr = new EvalDescr();
evalDescr.setContent("a == 10");
final MVELEvalBuilder builder = new MVELEvalBuilder();
final EvalCondition eval = (EvalCondition) builder.build(context, evalDescr);
((MVELEvalExpression) eval.getEvalExpression()).compile((MVELDialectRuntimeData) pkgBuilder.getPackageRegistry(pkg.getName()).getDialectRuntimeRegistry().getDialectData("mvel"));
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
MockLeftTupleSink sink = new MockLeftTupleSink();
final Cheese cheddar = new Cheese("cheddar", 10);
final InternalFactHandle f0 = (InternalFactHandle) ksession.insert(cheddar);
final LeftTupleImpl tuple = new LeftTupleImpl(f0, sink, true);
f0.removeLeftTuple(tuple);
Object evalContext = eval.createContext();
assertTrue(eval.isAllowed(tuple, ksession, evalContext));
cheddar.setPrice(9);
ksession.update(f0, cheddar);
assertFalse(eval.isAllowed(tuple, ksession, evalContext));
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class MVELSalienceBuilderTest method testSimpleExpression.
@Test
public void testSimpleExpression() {
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
final Person p = new Person("mark", "", 31);
final InternalFactHandle f0 = (InternalFactHandle) ksession.insert(p);
final LeftTupleImpl tuple = new LeftTupleImpl(f0, null, true);
RuleTerminalNode rtn = new RuleTerminalNode();
rtn.setSalienceDeclarations(context.getDeclarationResolver().getDeclarations(context.getRule()).values().toArray(new Declaration[1]));
AgendaItem item = new AgendaItemImpl(0, tuple, 0, null, rtn, null);
assertEquals(25, context.getRule().getSalience().getValue(new DefaultKnowledgeHelper(item, ksession), context.getRule(), ksession));
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class WorkingMemoryLogger method extractFactHandleIds.
private String extractFactHandleIds(Activation activation) {
InternalFactHandle activatingFact = activation.getPropagationContext().getFactHandle();
StringBuilder sb = new StringBuilder();
if (activatingFact != null) {
sb.append(activatingFact.getId());
}
InternalFactHandle[] factHandles = activation.getTuple().toFactHandles();
for (int i = 0; i < factHandles.length; i++) {
if (activatingFact != null) {
if (activatingFact.getId() == factHandles[i].getId()) {
continue;
}
sb.append(",");
} else {
if (i > 0) {
sb.append(",");
}
}
sb.append(factHandles[i].getId());
}
return sb.toString();
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class DefaultKnowledgeHelper method update.
public void update(final FactHandle handle, BitMask mask, Class<?> modifiedClass) {
InternalFactHandle h = (InternalFactHandle) handle;
if (h.getDataSource() != null) {
// This handle has been insert from a datasource, so update it
h.getDataSource().update(h, ((InternalFactHandle) handle).getObject(), mask, modifiedClass, this.activation);
return;
}
((InternalWorkingMemoryEntryPoint) h.getEntryPoint()).update(h, ((InternalFactHandle) handle).getObject(), mask, modifiedClass, this.activation);
if (h.isTraitOrTraitable()) {
workingMemory.updateTraits(h, mask, modifiedClass, this.activation);
}
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class TraitHelper method update.
public void update(final FactHandle handle, BitMask mask, Class<?> modifiedClass, Activation activation) {
InternalFactHandle h = (InternalFactHandle) handle;
((NamedEntryPoint) h.getEntryPoint()).update(h, ((InternalFactHandle) handle).getObject(), mask, modifiedClass, activation);
if (h.isTraitOrTraitable()) {
workingMemory.updateTraits(h, mask, modifiedClass, activation);
}
}
Aggregations