Search in sources :

Example 1 with ObjectTypeConfigurationRegistry

use of org.drools.core.common.ObjectTypeConfigurationRegistry 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;
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) InternalFactHandle(org.drools.core.common.InternalFactHandle) ObjectTypeConfigurationRegistry(org.drools.core.common.ObjectTypeConfigurationRegistry)

Example 2 with ObjectTypeConfigurationRegistry

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

the class TraitTest method testTMSConsistencyWithNonTraitableBeans.

@Test(timeout = 10000)
public void testTMSConsistencyWithNonTraitableBeans() {
    String s1 = "package org.drools.test;\n" + "import org.drools.compiler.Person; \n" + "import org.drools.core.factmodel.traits.Traitable; \n" + "" + "declare Person @Traitable end \n" + "" + "rule \"Init\"\n" + "when\n" + "then\n" + "  insertLogical( new Person( \"x\", 18 ) );\n" + "end\n" + "\n" + "declare trait Student\n" + "  age  : int\n" + "  name : String\n" + "end\n" + "\n" + "rule \"Trait\"\n" + "when\n" + "    $p : Person( )\n" + "then\n" + "    don( $p, Student.class, true );\n" + "end\n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ByteArrayResource(s1.getBytes()), ResourceType.DRL);
    if (kbuilder.hasErrors()) {
        fail(kbuilder.getErrors().toString());
    }
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    KieSession ksession = kbase.newKieSession();
    TraitFactory.setMode(mode, ksession.getKieBase());
    ksession.fireAllRules();
    FactHandle personHandle = ksession.getFactHandles(new ClassObjectFilter(Person.class)).iterator().next();
    InternalFactHandle h = ((InternalFactHandle) personHandle);
    ObjectTypeConfigurationRegistry reg = h.getEntryPoint().getObjectTypeConfigurationRegistry();
    ObjectTypeConf conf = reg.getObjectTypeConf(h.getEntryPoint().getEntryPoint(), ((InternalFactHandle) personHandle).getObject());
    assertTrue(conf.isTMSEnabled());
    ksession.dispose();
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ByteArrayResource(org.drools.core.io.impl.ByteArrayResource) InternalFactHandle(org.drools.core.common.InternalFactHandle) Person(org.drools.compiler.Person) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) ObjectTypeConfigurationRegistry(org.drools.core.common.ObjectTypeConfigurationRegistry) Test(org.junit.Test)

Example 3 with ObjectTypeConfigurationRegistry

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

the class TraitHelper method makeTraitable.

private <K> TraitableBean makeTraitable(K core, TraitFactory builder, boolean logical, Activation activation) {
    boolean needsWrapping = !(core instanceof TraitableBean);
    ClassDefinition coreDef = lookupClassDefinition(core);
    TraitableBean<K, ? extends TraitableBean> inner = needsWrapping ? builder.asTraitable(core, coreDef) : (TraitableBean<K, ? extends TraitableBean>) core;
    if (needsWrapping) {
        InternalFactHandle h = (InternalFactHandle) lookupFactHandle(core);
        WorkingMemoryEntryPoint ep = h != null ? h.getEntryPoint() : ((StatefulKnowledgeSessionImpl) workingMemory).getEntryPoint("DEFAULT");
        ObjectTypeConfigurationRegistry reg = ep.getObjectTypeConfigurationRegistry();
        ObjectTypeConf coreConf = reg.getObjectTypeConf(ep.getEntryPoint(), core);
        ObjectTypeConf innerConf = reg.getObjectTypeConf(ep.getEntryPoint(), inner);
        if (coreConf.isTMSEnabled()) {
            innerConf.enableTMS();
        }
        if (inner._getFieldTMS() != null && inner._getFieldTMS().needsInit()) {
            inner._getFieldTMS().init(workingMemory);
        }
    } else {
        TraitFieldTMS ftms = inner._getFieldTMS();
        if (ftms != null) {
            FactHandle handle = lookupFactHandle(inner);
            if (handle == null) {
                handle = this.workingMemory.insert(inner, false, activation.getRule(), activation.getTuple().getTupleSink());
            }
            if (ftms.needsInit()) {
                ftms.init(workingMemory);
            }
        }
    }
    return inner;
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) TraitFieldTMS(org.drools.core.factmodel.traits.TraitFieldTMS) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) TraitableBean(org.drools.core.factmodel.traits.TraitableBean) ClassDefinition(org.drools.core.factmodel.ClassDefinition) InternalFactHandle(org.drools.core.common.InternalFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) ObjectTypeConfigurationRegistry(org.drools.core.common.ObjectTypeConfigurationRegistry)

Example 4 with ObjectTypeConfigurationRegistry

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

the class JTMSBeliefSystem method getObjectTypeConf.

private ObjectTypeConf getObjectTypeConf(BeliefSet<M> jtmsBeliefSet) {
    InternalFactHandle fh = jtmsBeliefSet.getFactHandle();
    ObjectTypeConfigurationRegistry reg;
    ObjectTypeConf typeConf;
    reg = ep.getObjectTypeConfigurationRegistry();
    typeConf = reg.getObjectTypeConf(ep.getEntryPoint(), fh.getObject());
    return typeConf;
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) InternalFactHandle(org.drools.core.common.InternalFactHandle) ObjectTypeConfigurationRegistry(org.drools.core.common.ObjectTypeConfigurationRegistry)

Aggregations

InternalFactHandle (org.drools.core.common.InternalFactHandle)4 ObjectTypeConfigurationRegistry (org.drools.core.common.ObjectTypeConfigurationRegistry)4 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)4 FactHandle (org.kie.api.runtime.rule.FactHandle)2 Person (org.drools.compiler.Person)1 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)1 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)1 ClassDefinition (org.drools.core.factmodel.ClassDefinition)1 TraitFieldTMS (org.drools.core.factmodel.traits.TraitFieldTMS)1 TraitableBean (org.drools.core.factmodel.traits.TraitableBean)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)1 Test (org.junit.Test)1 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)1 KieSession (org.kie.api.runtime.KieSession)1 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)1 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)1