use of org.drools.core.rule.IndexableConstraint 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.rule.IndexableConstraint in project drools by kiegroup.
the class CompositeObjectSinkAdapter method unHashSinks.
void unHashSinks(final FieldIndex fieldIndex) {
final int index = fieldIndex.getIndex();
// this is the list of sinks that need to be removed from the hashedSinkMap
final List<HashKey> unhashedSinks = new ArrayList<HashKey>();
final Iterator iter = this.hashedSinkMap.newIterator();
ObjectHashMap.ObjectEntry entry = (ObjectHashMap.ObjectEntry) iter.next();
while (entry != null) {
final AlphaNode alphaNode = (AlphaNode) entry.getValue();
final IndexableConstraint indexableConstraint = (IndexableConstraint) alphaNode.getConstraint();
// the right field index
if (index == indexableConstraint.getFieldExtractor().getIndex()) {
final FieldValue value = indexableConstraint.getField();
if (this.hashableSinks == null) {
this.hashableSinks = new ObjectSinkNodeList();
}
this.hashableSinks.add(alphaNode);
unhashedSinks.add(new HashKey(index, value, fieldIndex.getFieldExtractor()));
}
entry = (ObjectHashMap.ObjectEntry) iter.next();
}
for (HashKey hashKey : unhashedSinks) {
this.hashedSinkMap.remove(hashKey);
}
if (this.hashedSinkMap.isEmpty()) {
this.hashedSinkMap = null;
}
fieldIndex.setHashed(false);
}
use of org.drools.core.rule.IndexableConstraint 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;
}
Aggregations