use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class SimpleBeliefSystem method getObjectTypeConf.
private ObjectTypeConf getObjectTypeConf(BeliefSet beliefSet) {
InternalFactHandle fh = beliefSet.getFactHandle();
ObjectTypeConfigurationRegistry reg;
ObjectTypeConf typeConf;
reg = ep.getObjectTypeConfigurationRegistry();
typeConf = reg.getObjectTypeConf(ep.getEntryPoint(), fh.getObject());
return typeConf;
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class SimpleBeliefSystem method delete.
@Override
public void delete(SimpleMode mode, RuleImpl rule, Activation activation, Object payload, BeliefSet<SimpleMode> beliefSet, PropagationContext context) {
beliefSet.remove(mode);
InternalFactHandle bfh = beliefSet.getFactHandle();
if (beliefSet.isEmpty() && bfh.getEqualityKey() != null && bfh.getEqualityKey().getStatus() == EqualityKey.JUSTIFIED) {
ep.delete(bfh, bfh.getObject(), getObjectTypeConf(beliefSet), context.getRuleOrigin(), null, activation != null ? activation.getTuple().getTupleSink() : null);
} else if (!beliefSet.isEmpty() && bfh.getObject() == payload && payload != bfh.getObject()) {
// prime has changed, to update new object
// Equality might have changed on the object, so remove (which uses the handle id) and add back in
bfh.getEntryPoint().getObjectStore().updateHandle(bfh, beliefSet.getFirst().getObject().getObject());
bfh.getEntryPoint().update(bfh, bfh.getObject(), allSetButTraitBitMask(), Object.class, null);
}
if (beliefSet.isEmpty() && bfh.getEqualityKey() != null) {
// if the beliefSet is empty, we must null the logical handle
EqualityKey key = bfh.getEqualityKey();
key.setLogicalFactHandle(null);
key.setBeliefSet(null);
if (key.getStatus() == EqualityKey.JUSTIFIED) {
// if it's stated, there will be other handles, so leave it in the TMS
tms.remove(key);
}
}
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class SetVariableCommandFromLastReturn method execute.
public Object execute(Context context) {
Context targetCtx;
if (this.contextName == null) {
targetCtx = context;
} else {
targetCtx = ((RegistryContext) context).getContextManager().getContext(this.contextName);
}
GetDefaultValue sim = (GetDefaultValue) context.get("simulator");
Object o = sim.getObject();
// for FactHandle's we store the handle on a map and the actual object as
if (o instanceof FactHandle) {
Map<String, FactHandle> handles = (Map<String, FactHandle>) targetCtx.get("h");
if (handles == null) {
handles = new HashMap<String, FactHandle>();
targetCtx.set("h", handles);
}
handles.put(identifier, (FactHandle) o);
o = ((InternalFactHandle) o).getObject();
}
targetCtx.set(identifier, o);
return o;
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class GetFactHandleCommand method execute.
public FactHandle execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
InternalFactHandle factHandle = (InternalFactHandle) ksession.getFactHandle(object);
if (factHandle != null) {
InternalFactHandle handle = factHandle.clone();
if (disconnected) {
handle.disconnect();
}
return handle;
}
return null;
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class IndexingTest method testFullFastIteratorResume.
@Test(timeout = 10000)
public void testFullFastIteratorResume() throws Exception {
String str = "";
str += "package org.drools.compiler.test \n";
str += "import org.drools.compiler.Person \n";
str += "query peeps( String $name, int $age ) \n";
str += " not $p2 : Person( $name := name, age > $age ) \n";
str += "end\n";
KieBase kbase = loadKnowledgeBaseFromString(str);
List<ObjectTypeNode> nodes = ((KnowledgeBaseImpl) kbase).getRete().getObjectTypeNodes();
ObjectTypeNode node = null;
for (ObjectTypeNode n : nodes) {
if (((ClassObjectType) n.getObjectType()).getClassType() == DroolsQuery.class) {
node = n;
break;
}
}
StatefulKnowledgeSessionImpl wm = ((StatefulKnowledgeSessionImpl) kbase.newKieSession());
AlphaNode alphanode = (AlphaNode) node.getObjectSinkPropagator().getSinks()[0];
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) alphanode.getObjectSinkPropagator().getSinks()[0];
NotNode n = (NotNode) liaNode.getSinkPropagator().getSinks()[0];
DoubleNonIndexSkipBetaConstraints c = (DoubleNonIndexSkipBetaConstraints) n.getRawConstraints();
// assertEquals( "$name", ((VariableConstraint)c.getConstraint()).getRequiredDeclarations()[0].getIdentifier() );
assertTrue(c.isIndexed());
BetaMemory bm = (BetaMemory) wm.getNodeMemory(n);
System.out.println(bm.getLeftTupleMemory().getClass());
System.out.println(bm.getRightTupleMemory().getClass());
assertTrue(bm.getLeftTupleMemory() instanceof TupleIndexHashTable);
assertTrue(bm.getRightTupleMemory() instanceof TupleIndexHashTable);
final Map<String, Integer> map = new HashMap<String, Integer>();
map.put("inserted", new Integer(0));
map.put("deleted", new Integer(0));
map.put("updated", new Integer(0));
wm.openLiveQuery("peeps", new Object[] { Variable.v, 99 }, new ViewChangedEventListener() {
@Override
public void rowInserted(Row row) {
}
@Override
public void rowDeleted(Row row) {
}
@Override
public void rowUpdated(Row row) {
}
});
Map<String, InternalFactHandle> peeps = new HashMap<String, InternalFactHandle>();
Person p = new Person("x0", 100);
InternalFactHandle fh = (InternalFactHandle) wm.insert(p);
peeps.put(p.getName(), fh);
for (int i = 1; i < 100; i++) {
p = new Person("x" + i, 101);
fh = (InternalFactHandle) wm.insert(p);
wm.fireAllRules();
peeps.put(p.getName(), fh);
}
List<RightTuple> list = new ArrayList<RightTuple>(100);
FastIterator it = n.getRightIterator(bm.getRightTupleMemory());
for (RightTuple rt = n.getFirstRightTuple(null, bm.getRightTupleMemory(), null, it); rt != null; rt = (RightTuple) it.next(rt)) {
list.add(rt);
}
assertEquals(100, list.size());
// check we can resume from each entry in the list above.
for (int i = 0; i < 100; i++) {
RightTuple rightTuple = list.get(i);
// resumes from the current rightTuple
it = n.getRightIterator(bm.getRightTupleMemory(), rightTuple);
int j = i + 1;
for (RightTuple rt = (RightTuple) it.next(rightTuple); rt != null; rt = (RightTuple) it.next(rt)) {
assertSame(list.get(j), rt);
j++;
}
}
}
Aggregations