Search in sources :

Example 56 with InternalReadAccessor

use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.

the class CompositeObjectSinkAdapter method addObjectSink.

public ObjectSinkPropagator addObjectSink(ObjectSink sink, int alphaNodeHashingThreshold) {
    // dirty it, so it'll rebuild on next get
    this.sinks = null;
    if (this.sinksMap != null) {
        this.sinksMap.put(sink, sink);
    }
    if (sink.getType() == NodeTypeEnums.AlphaNode) {
        final AlphaNode alphaNode = (AlphaNode) sink;
        final InternalReadAccessor readAccessor = getHashableAccessor(alphaNode);
        if (readAccessor != null) {
            final int index = readAccessor.getIndex();
            final FieldIndex fieldIndex = registerFieldIndex(index, readAccessor);
            // DROOLS-678 : prevent null values from being hashed as 0s
            final FieldValue value = ((IndexableConstraint) alphaNode.getConstraint()).getField();
            if (fieldIndex.getCount() >= this.alphaNodeHashingThreshold && this.alphaNodeHashingThreshold != 0 && !value.isNull()) {
                if (!fieldIndex.isHashed()) {
                    hashSinks(fieldIndex);
                }
                // no need to check, we know  the sink  does not exist
                this.hashedSinkMap.put(new HashKey(index, value, fieldIndex.getFieldExtractor()), alphaNode, false);
            } else {
                if (this.hashableSinks == null) {
                    this.hashableSinks = new ObjectSinkNodeList();
                }
                this.hashableSinks.add(alphaNode);
            }
            return this;
        }
    }
    if (this.otherSinks == null) {
        this.otherSinks = new ObjectSinkNodeList();
    }
    this.otherSinks.add((ObjectSinkNode) sink);
    return this;
}
Also used : IndexableConstraint(org.drools.core.rule.IndexableConstraint) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) FieldValue(org.drools.core.spi.FieldValue) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) IndexableConstraint(org.drools.core.rule.IndexableConstraint)

Example 57 with InternalReadAccessor

use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.

the class CompositePartitionAwareObjectSinkAdapter method hashSink.

private boolean hashSink(ObjectSink sink) {
    InternalReadAccessor readAccessor = getHashableAccessor(sink);
    if (readAccessor != null) {
        int index = readAccessor.getIndex();
        if (fieldIndex == null) {
            this.fieldIndex = new CompositeObjectSinkAdapter.FieldIndex(index, readAccessor);
            this.hashedSinkMap = new ObjectHashMap();
        }
        if (fieldIndex.getIndex() == index) {
            AlphaNode alpha = (AlphaNode) sink;
            this.hashedSinkMap.put(new CompositeObjectSinkAdapter.HashKey(index, ((IndexableConstraint) alpha.getConstraint()).getField(), fieldIndex.getFieldExtractor()), alpha, false);
            return true;
        }
    }
    this.fieldIndex = null;
    this.hashedSinkMap = null;
    return false;
}
Also used : FieldIndex(org.drools.core.reteoo.CompositeObjectSinkAdapter.FieldIndex) IndexableConstraint(org.drools.core.rule.IndexableConstraint) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) ObjectHashMap(org.drools.core.util.ObjectHashMap) IndexableConstraint(org.drools.core.rule.IndexableConstraint)

Example 58 with InternalReadAccessor

use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.

the class ReteTesterHelper method getLiteralConstraint.

public AlphaNodeFieldConstraint getLiteralConstraint(final Pattern pattern, final String fieldName, final String evaluatorString, final String value) {
    final Class<?> clazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
    final InternalReadAccessor extractor = store.getReader(clazz, fieldName);
    FieldValue fieldValue = FieldFactory.getInstance().getFieldValue(value, extractor.getValueType());
    return new MvelConstraintTestUtil(fieldName + evaluatorString + value, fieldValue, extractor);
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) FieldValue(org.drools.core.spi.FieldValue) MvelConstraintTestUtil(org.drools.core.rule.MvelConstraintTestUtil)

Aggregations

InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)58 Declaration (org.drools.core.rule.Declaration)27 Test (org.junit.Test)27 ClassObjectType (org.drools.core.base.ClassObjectType)26 Pattern (org.drools.core.rule.Pattern)23 Cheese (org.drools.core.test.model.Cheese)15 MvelConstraintTestUtil (org.drools.core.rule.MvelConstraintTestUtil)14 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)10 InternalFactHandle (org.drools.core.common.InternalFactHandle)9 FieldValue (org.drools.core.spi.FieldValue)9 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)8 TypeDeclaration (org.drools.core.rule.TypeDeclaration)7 FieldIndex (org.drools.core.util.AbstractHashTable.FieldIndex)7 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)6 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)6 LeftTupleImpl (org.drools.core.reteoo.LeftTupleImpl)6 RightTupleImpl (org.drools.core.reteoo.RightTupleImpl)6 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)5 ClassFieldAccessorStore (org.drools.core.base.ClassFieldAccessorStore)5