use of org.drools.core.util.bitmask.BitMask in project drools by kiegroup.
the class CursoredDataSource method update.
@Override
public void update(FactHandle handle, T object, String... modifiedProperties) {
BitMask mask = modifiedProperties == null || modifiedProperties.length == 0 ? allSetButTraitBitMask() : calculatePositiveMask(object.getClass(), asList(modifiedProperties), getAccessibleProperties(workingMemory.getKnowledgeBase(), object.getClass()));
internalUpdate((DataSourceFactHandle) handle, object, mask, Object.class, null);
}
use of org.drools.core.util.bitmask.BitMask in project drools by kiegroup.
the class LeftInputAdapterNode method modifyObject.
public void modifyObject(InternalFactHandle factHandle, final ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, InternalWorkingMemory workingMemory) {
ObjectTypeNode.Id otnId = this.sink.getFirstLeftTupleSink().getLeftInputOtnId();
LeftTuple leftTuple = processDeletesFromModify(modifyPreviousTuples, context, workingMemory, otnId);
LiaNodeMemory lm = workingMemory.getNodeMemory(this);
if (leftTuple != null && leftTuple.getInputOtnId().equals(otnId)) {
modifyPreviousTuples.removeLeftTuple(partitionId);
leftTuple.reAdd();
LeftTupleSink sink = getSinkPropagator().getFirstLeftTupleSink();
BitMask mask = sink.getLeftInferredMask();
if (context.getModificationMask().intersects(mask)) {
doUpdateObject(leftTuple, context, workingMemory, (LeftInputAdapterNode) leftTuple.getTupleSource(), true, lm, lm.getOrCreateSegmentMemory(this, workingMemory));
if (leftTuple instanceof Activation) {
((Activation) leftTuple).setActive(true);
}
}
} else {
LeftTupleSink sink = getSinkPropagator().getFirstLeftTupleSink();
BitMask mask = sink.getLeftInferredMask();
if (context.getModificationMask().intersects(mask)) {
doInsertObject(factHandle, context, this, workingMemory, lm, true, true);
}
}
}
use of org.drools.core.util.bitmask.BitMask in project drools by kiegroup.
the class ObjectSource method updateMask.
public BitMask updateMask(BitMask mask) {
BitMask returnMask;
if (source.getType() != NodeTypeEnums.ObjectTypeNode) {
returnMask = source.updateMask(declaredMask.clone().setAll(mask));
} else {
// else ObjectTypeNode
returnMask = declaredMask.clone().setAll(mask);
}
inferredMask = inferredMask.setAll(returnMask);
return returnMask;
}
use of org.drools.core.util.bitmask.BitMask in project drools by kiegroup.
the class TraitObjectTypeNode method updateMask.
@Override
public BitMask updateMask(BitMask mask) {
BitMask returnMask;
returnMask = declaredMask.clone().setAll(mask);
inferredMask = inferredMask.setAll(returnMask);
return returnMask;
}
use of org.drools.core.util.bitmask.BitMask in project drools by kiegroup.
the class JavaConsequenceBuilderPRAlwaysTest method testWhileBlocks.
@Test
public void testWhileBlocks() throws Exception {
String consequence = " System.out.println(\"this is a test\");\n " + " Cheese c1 = $cheese;\n" + " while ( c1 == $cheese ) { \r\n" + " modify( c1 ) { setPrice( 10 ), \n" + " setOldPrice( age ) }\n " + " Cheese c4 = $cheese;\n" + " while ( true ) { \n" + " modify( c4 ) { setPrice( 10 ), setOldPrice( age ) }\n " + " }" + " } \n " + " Cheese c3 = $cheese;\n" + " while ( c4 == $cheese ) modify( $cheese ) { setPrice( 10 ), setOldPrice( age ) }\n " + " modify( $cheese ) { setPrice( 10 ), setOldPrice( age ) }\n " + " System.out.println(\"we are done\");\n " + " while (true) { System.out.println(1);}\n" + " modify( $cheese ) { setPrice( 10 ), setOldPrice( age ) }\n " + " System.out.println(\"we are done\");\n ";
setupTest("", new HashMap<String, Object>());
ruleDescr.setConsequence(consequence);
JavaExprAnalyzer analyzer = new JavaExprAnalyzer();
Map<String, Class<?>> declrCls = new HashMap<String, Class<?>>();
declrCls.put("$cheese", Cheese.class);
JavaAnalysisResult analysis = (JavaAnalysisResult) analyzer.analyzeBlock((String) ruleDescr.getConsequence(), new BoundIdentifiers(declrCls, null));
BoundIdentifiers bindings = new BoundIdentifiers(new HashMap(), null);
bindings.getDeclrClasses().put("$cheese", Cheese.class);
bindings.getDeclrClasses().put("age", int.class);
// Set the inputs for each container, this is needed for modifes when the target context is the result of an expression
List<JavaBlockDescr> descrs = new ArrayList<JavaBlockDescr>();
setContainerBlockInputs(context, descrs, analysis.getBlockDescrs(), consequence, bindings, new HashMap(), 0);
String fixed = fixBlockDescr(context, analysis, context.getDeclarationResolver().getDeclarations(context.getRule()));
List<String> cheeseAccessibleProperties = ClassUtils.getAccessibleProperties(Cheese.class);
BitMask priceOldPrice = PropertySpecificUtil.calculatePositiveMask(Cheese.class, Arrays.asList("price", "oldPrice"), cheeseAccessibleProperties);
String expected = " System.out.println(\"this is a test\");\r\n" + " Cheese c1 = $cheese;\r\n" + " while ( c1 == $cheese ) { \r\n" + " { org.drools.compiler.Cheese __obj__ = ( c1 ); org.kie.api.runtime.rule.FactHandle __obj____Handle2__ = drools.getFactHandle(__obj__);__obj__.setPrice( 10 ); \r\n" + "__obj__.setOldPrice( age ); drools.update( __obj____Handle2__, " + priceOldPrice.getInstancingStatement() + ", org.drools.compiler.Cheese.class ); }\r\n" + " Cheese c4 = $cheese;\r\n" + " while ( true ) { \r\n" + " { org.drools.compiler.Cheese __obj__ = ( c4 ); org.kie.api.runtime.rule.FactHandle __obj____Handle2__ = drools.getFactHandle(__obj__);__obj__.setPrice( 10 ); __obj__.setOldPrice( age ); drools.update( __obj____Handle2__, " + priceOldPrice.getInstancingStatement() + ", org.drools.compiler.Cheese.class ); }\r\n" + " } } \r\n" + " Cheese c3 = $cheese;\r\n" + " while ( c4 == $cheese ) { $cheese.setPrice( 10 ); $cheese.setOldPrice( age ); drools.update( $cheese__Handle__, " + priceOldPrice.getInstancingStatement() + ", org.drools.compiler.Cheese.class ); }\r\n" + " { $cheese.setPrice( 10 ); $cheese.setOldPrice( age ); drools.update( $cheese__Handle__, " + priceOldPrice.getInstancingStatement() + ", org.drools.compiler.Cheese.class ); }\r\n" + " System.out.println(\"we are done\");\r\n" + " while (true) { System.out.println(1);}\r\n" + " { $cheese.setPrice( 10 ); $cheese.setOldPrice( age ); drools.update( $cheese__Handle__, " + priceOldPrice.getInstancingStatement() + ", org.drools.compiler.Cheese.class ); }\r\n" + " System.out.println(\"we are done\");\r\n" + " \r\n" + "";
assertNotNull(context.getErrors().toString(), fixed);
assertEqualsIgnoreSpaces(expected, fixed);
}
Aggregations