use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.
the class BaseClassFieldAccessorFactoryTest method testInterface.
@Test
public void testInterface() throws Exception {
final InternalReadAccessor ex = store.getReader(TestInterface.class, "something");
assertEquals(1, ex.getIndex());
assertEquals("foo", ex.getValue(null, new TestInterfaceImpl()));
}
use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.
the class BaseClassFieldAccessorFactoryTest method testIt.
@Test
public void testIt() throws Exception {
ClassFieldAccessorFactory factory = new ClassFieldAccessorFactory();
ClassFieldAccessorCache.CacheEntry cachEntry = new ClassFieldAccessorCache.CacheEntry(Thread.currentThread().getContextClassLoader());
InternalReadAccessor ex = factory.getClassFieldReader(TestBean.class, "name", cachEntry);
assertEquals("michael", ex.getValue(null, new TestBean()));
ex = factory.getClassFieldReader(TestBean.class, "age", cachEntry);
assertEquals(42, ((Number) ex.getValue(null, new TestBean())).intValue());
}
use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.
the class BaseClassFieldAccessorFactoryTest method testInherited.
@Test
public void testInherited() throws Exception {
final InternalReadAccessor ex = store.getReader(BeanInherit.class, "text");
assertEquals("hola", ex.getValue(null, new BeanInherit()));
}
use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.
the class CompositeObjectSinkAdapter method removeObjectSink.
public ObjectSinkPropagator removeObjectSink(final ObjectSink sink) {
// dirty it, so it'll rebuild on next get
this.sinks = null;
if (this.sinksMap != null) {
this.sinksMap.remove(sink);
}
if (sink.getType() == NodeTypeEnums.AlphaNode) {
final AlphaNode alphaNode = (AlphaNode) sink;
final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
if (fieldConstraint instanceof IndexableConstraint) {
final IndexableConstraint indexableConstraint = (IndexableConstraint) fieldConstraint;
final FieldValue value = indexableConstraint.getField();
if (isHashable(indexableConstraint)) {
final InternalReadAccessor fieldAccessor = indexableConstraint.getFieldExtractor();
final int index = fieldAccessor.getIndex();
final FieldIndex fieldIndex = unregisterFieldIndex(index);
if (fieldIndex.isHashed()) {
HashKey hashKey = new HashKey(index, value, fieldAccessor);
this.hashedSinkMap.remove(hashKey);
if (fieldIndex.getCount() <= this.alphaNodeHashingThreshold - 1) {
// we have less than three so unhash
unHashSinks(fieldIndex);
}
} else {
this.hashableSinks.remove(alphaNode);
}
if (this.hashableSinks != null && this.hashableSinks.isEmpty()) {
this.hashableSinks = null;
}
return size() == 1 ? new SingleObjectSinkAdapter(getSinks()[0]) : this;
}
}
}
this.otherSinks.remove((ObjectSinkNode) sink);
if (this.otherSinks.isEmpty()) {
this.otherSinks = null;
}
return size() == 1 ? new SingleObjectSinkAdapter(getSinks()[0]) : this;
}
use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.
the class CompositeObjectSinkAdapter method hashSinks.
void hashSinks(final FieldIndex fieldIndex) {
if (this.hashedSinkMap == null) {
this.hashedSinkMap = new ObjectHashMap();
}
final int index = fieldIndex.getIndex();
final InternalReadAccessor fieldReader = fieldIndex.getFieldExtractor();
ObjectSinkNode currentSink = this.hashableSinks.getFirst();
while (currentSink != null) {
final AlphaNode alphaNode = (AlphaNode) currentSink;
final AlphaNodeFieldConstraint fieldConstraint = alphaNode.getConstraint();
final IndexableConstraint indexableConstraint = (IndexableConstraint) fieldConstraint;
// position to the next sink now because alphaNode may be removed if the index is equal. If we were to do this
// afterwards, currentSink.nextNode would be null
currentSink = currentSink.getNextObjectSinkNode();
// the right field index
if (index == indexableConstraint.getFieldExtractor().getIndex()) {
final FieldValue value = indexableConstraint.getField();
this.hashedSinkMap.put(new HashKey(index, value, fieldReader), alphaNode);
// remove the alpha from the possible candidates of hashable sinks since it is now hashed
hashableSinks.remove(alphaNode);
}
}
if (this.hashableSinks.isEmpty()) {
this.hashableSinks = null;
}
fieldIndex.setHashed(true);
}
Aggregations