Search in sources :

Example 36 with DefaultFactHandle

use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.

the class InsertObjectInEntryPointCommand method execute.

public FactHandle execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    EntryPoint ep = ksession.getEntryPoint(entryPoint);
    FactHandle factHandle = ep.insert(object);
    DefaultFactHandle disconnectedHandle = ((DefaultFactHandle) factHandle).clone();
    disconnectedHandle.disconnect();
    if (outIdentifier != null) {
        if (this.returnObject) {
            ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, object);
        }
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).getFactHandles().put(this.outIdentifier, disconnectedHandle);
    }
    return disconnectedHandle;
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.kie.internal.command.RegistryContext)

Example 37 with DefaultFactHandle

use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.

the class FactHandleTest method testHashCode.

@Test
public void testHashCode() {
    final DefaultFactHandle f0 = new DefaultFactHandle(234, "cheese");
    assertEquals("cheese".hashCode(), f0.getObjectHashCode());
    assertEquals(234, f0.hashCode());
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) Test(org.junit.Test)

Example 38 with DefaultFactHandle

use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.

the class FactHandleTest method testFactHandleImpllong.

/*
     * Class under test for void FactHandleImpl(long)
     */
@Test
public void testFactHandleImpllong() {
    final DefaultFactHandle f0 = new DefaultFactHandle(134, "cheese");
    assertEquals(134, f0.getId());
    assertEquals(134, f0.getRecency());
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) Test(org.junit.Test)

Example 39 with DefaultFactHandle

use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.

the class ProtobufOutputMarshallerTest method testOrderFacts.

@Test
public void testOrderFacts() throws Exception {
    List<InternalFactHandle> list = new ArrayList<InternalFactHandle>();
    List<Integer> ids = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 30, 31, 32, -2147483640, 7, 8, 9, 10, 11, 12, 13, 14, 15, 28, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
    for (Integer i : ids) {
        list.add(new DefaultFactHandle(i.intValue(), i));
    }
    InternalFactHandle first = ProtobufOutputMarshaller.orderFacts(list)[0];
    assertEquals(-2147483640, first.getId());
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ArrayList(java.util.ArrayList) InternalFactHandle(org.drools.core.common.InternalFactHandle) Test(org.junit.Test)

Example 40 with DefaultFactHandle

use of org.drools.core.common.DefaultFactHandle in project drools by kiegroup.

the class RemoveRuleTest method testRuleRemovalWithJoinedRootPattern.

@Test
public void testRuleRemovalWithJoinedRootPattern() {
    String str = "";
    str += "package org.drools.compiler \n";
    str += "import " + Person.class.getCanonicalName() + ";\n";
    str += "import " + Cheese.class.getCanonicalName() + ";\n";
    str += "rule rule1 \n";
    str += "when \n";
    str += "  String() \n";
    str += "  Person() \n";
    str += "then \n";
    str += "end  \n";
    str += "rule rule2 \n";
    str += "when \n";
    str += "  String() \n";
    str += "  Cheese() \n";
    str += "then \n";
    str += "end  \n";
    final KieServices kieServices = KieServices.get();
    final ReleaseId releaseId = kieServices.newReleaseId("org.kie", "test-remove-rule-with-joined-root-pattern", "1.0");
    KieUtil.getKieModuleFromDrls(releaseId, kieBaseTestConfiguration, str);
    final KieContainer kieContainer = kieServices.newKieContainer(releaseId);
    final KieBase kbase = kieContainer.getKieBase();
    final KieSession ksession = kbase.newKieSession();
    final DefaultFactHandle handle = (DefaultFactHandle) ksession.insert("hello");
    ksession.fireAllRules();
    LeftTuple leftTuple = handle.getFirstLeftTuple();
    assertNotNull(leftTuple);
    assertNotNull(leftTuple.getPeer());
    kbase.removeRule("org.drools.compiler", "rule2");
    leftTuple = handle.getFirstLeftTuple();
    assertNotNull(leftTuple);
    assertNull(leftTuple.getHandleNext());
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) KieBase(org.kie.api.KieBase) Cheese(org.drools.testcoverage.common.model.Cheese) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) Person(org.drools.testcoverage.common.model.Person) LeftTuple(org.drools.core.reteoo.LeftTuple) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

DefaultFactHandle (org.drools.core.common.DefaultFactHandle)92 Test (org.junit.Test)78 InternalFactHandle (org.drools.core.common.InternalFactHandle)30 FactHandle (org.kie.api.runtime.rule.FactHandle)29 Cheese (org.drools.core.test.model.Cheese)24 ArrayList (java.util.ArrayList)23 ClassObjectType (org.drools.core.base.ClassObjectType)22 KieSession (org.kie.api.runtime.KieSession)19 FieldIndex (org.drools.core.util.AbstractHashTable.FieldIndex)18 RightTupleImpl (org.drools.core.reteoo.RightTupleImpl)16 Declaration (org.drools.core.rule.Declaration)15 RightTuple (org.drools.core.reteoo.RightTuple)14 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)14 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)13 StatefulKnowledgeSessionImpl (org.drools.kiesession.session.StatefulKnowledgeSessionImpl)13 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)12 Pattern (org.drools.core.rule.Pattern)12 Tuple (org.drools.core.spi.Tuple)12 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)12 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)11