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;
}
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;
}
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);
}
Aggregations