Search in sources :

Example 11 with BitMask

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);
}
Also used : PropertySpecificUtil.allSetButTraitBitMask(org.drools.core.reteoo.PropertySpecificUtil.allSetButTraitBitMask) BitMask(org.drools.core.util.bitmask.BitMask)

Example 12 with BitMask

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);
        }
    }
}
Also used : Id(org.drools.core.reteoo.ObjectTypeNode.Id) BitMask(org.drools.core.util.bitmask.BitMask) AllSetBitMask(org.drools.core.util.bitmask.AllSetBitMask) Activation(org.drools.core.spi.Activation)

Example 13 with BitMask

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;
}
Also used : EmptyBitMask(org.drools.core.util.bitmask.EmptyBitMask) BitMask(org.drools.core.util.bitmask.BitMask) AllSetBitMask(org.drools.core.util.bitmask.AllSetBitMask)

Example 14 with BitMask

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;
}
Also used : BitMask(org.drools.core.util.bitmask.BitMask)

Example 15 with BitMask

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BoundIdentifiers(org.drools.compiler.compiler.BoundIdentifiers) BitMask(org.drools.core.util.bitmask.BitMask) JavaBlockDescr(org.drools.compiler.rule.builder.dialect.java.parser.JavaBlockDescr) Test(org.junit.Test)

Aggregations

BitMask (org.drools.core.util.bitmask.BitMask)15 AllSetBitMask (org.drools.core.util.bitmask.AllSetBitMask)5 PropertySpecificUtil.allSetButTraitBitMask (org.drools.core.reteoo.PropertySpecificUtil.allSetButTraitBitMask)4 TypeDeclaration (org.drools.core.rule.TypeDeclaration)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 BoundIdentifiers (org.drools.compiler.compiler.BoundIdentifiers)3 JavaBlockDescr (org.drools.compiler.rule.builder.dialect.java.parser.JavaBlockDescr)3 Test (org.junit.Test)3 ClassObjectType (org.drools.core.base.ClassObjectType)2 ConsequenceMetaData (org.drools.core.rule.ConsequenceMetaData)2 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)1 JavaModifyBlockDescr (org.drools.compiler.rule.builder.dialect.java.parser.JavaModifyBlockDescr)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 TraitFieldTMS (org.drools.core.factmodel.traits.TraitFieldTMS)1 Id (org.drools.core.reteoo.ObjectTypeNode.Id)1 Declaration (org.drools.core.rule.Declaration)1 IndexableConstraint (org.drools.core.rule.IndexableConstraint)1 MutableTypeConstraint (org.drools.core.rule.MutableTypeConstraint)1