Search in sources :

Example 21 with ClassFieldAccessorCache

use of org.drools.core.base.ClassFieldAccessorCache in project drools by kiegroup.

the class InstancesHashcodedTest method build.

/*
        <dimension name="bck_cycle_dm"  item-expression="cycleDimension"
                   mode="ignore" cache="10" export-to="cycle_id">
            <id    name="objid"            type="long"             generator-sql="select bck_dimensions_uid.nextval from dual"/>
            <field name="cut_date"         type="java.util.Date"   value="cutDate"     key="true"/>
            <field name="due_date"         type="java.util.Date"   value="dueDate"     key="true"/>
            <field name="cycle_code"       type="java.lang.String" value="cycleCode"/>
            <field name="issue_date"       type="java.util.Date"   value="issueDate"/>
        </dimension>
 */
private Class build(ClassBuilder builder, ClassDefinition classDef) throws Exception {
    ProjectClassLoader prjClassLoader = ProjectClassLoader.createProjectClassLoader();
    byte[] d = builder.buildClass(classDef, prjClassLoader);
    JavaDialectRuntimeData data = new JavaDialectRuntimeData();
    data.write(convertClassToResourcePath(classDef.getClassName()), d);
    ClassLoader classLoader = new PackageClassLoader(data, prjClassLoader);
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(classLoader));
    store.setEagerWire(true);
    Class clazz = classLoader.loadClass(classDef.getClassName());
    classDef.setDefinedClass(clazz);
    return clazz;
}
Also used : ProjectClassLoader(org.drools.core.common.ProjectClassLoader) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) PackageClassLoader(org.drools.core.rule.JavaDialectRuntimeData.PackageClassLoader) ProjectClassLoader(org.drools.core.common.ProjectClassLoader) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData) PackageClassLoader(org.drools.core.rule.JavaDialectRuntimeData.PackageClassLoader)

Example 22 with ClassFieldAccessorCache

use of org.drools.core.base.ClassFieldAccessorCache in project drools by kiegroup.

the class AlphaNodeTest method setUp.

@Before
public void setUp() throws Exception {
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) Before(org.junit.Before)

Example 23 with ClassFieldAccessorCache

use of org.drools.core.base.ClassFieldAccessorCache in project drools by kiegroup.

the class CompositeObjectSinkAdapterTest method setUp.

@Before
public void setUp() throws Exception {
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    this.kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    this.buildContext = new BuildContext(kBase);
    this.buildContext.setRule(new RuleImpl("test"));
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) BuildContext(org.drools.core.reteoo.builder.BuildContext) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) Before(org.junit.Before)

Example 24 with ClassFieldAccessorCache

use of org.drools.core.base.ClassFieldAccessorCache in project drools by kiegroup.

the class ReteooRuleBaseMultiThreadedTest method setUp.

@Before
public void setUp() {
    this.kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    pkg = new KnowledgePackageImpl("org.droos.test");
    pkg.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    JavaDialectRuntimeData data = new JavaDialectRuntimeData();
    data.onAdd(pkg.getDialectRuntimeRegistry(), kBase.getRootClassLoader());
    pkg.getDialectRuntimeRegistry().setDialectData("java", data);
    // we need to add one rule to the package because the previous deadlock was encountered
    // while removing rules from a package when said package is removed from the rulebase
    rule = new RuleImpl("Test");
    rule.setDialect("java");
    rule.setConsequence(new Consequence() {

        public void evaluate(KnowledgeHelper knowledgeHelper, WorkingMemory workingMemory) throws Exception {
        }

        public String getName() {
            return "default";
        }
    });
    pkg.addRule(rule);
    kBase.addPackage(pkg);
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) WorkingMemory(org.drools.core.WorkingMemory) Consequence(org.drools.core.spi.Consequence) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) KnowledgeHelper(org.drools.core.spi.KnowledgeHelper) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData) Before(org.junit.Before)

Example 25 with ClassFieldAccessorCache

use of org.drools.core.base.ClassFieldAccessorCache in project drools by kiegroup.

the class DeclarationTest method setUp.

@Before
public void setUp() throws Exception {
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) Before(org.junit.Before)

Aggregations

ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)34 Before (org.junit.Before)22 ClassFieldAccessorStore (org.drools.core.base.ClassFieldAccessorStore)17 TestBean (org.drools.core.base.TestBean)9 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)9 ClassObjectType (org.drools.core.base.ClassObjectType)7 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)6 MvelConstraintTestUtil (org.drools.core.rule.MvelConstraintTestUtil)6 Pattern (org.drools.core.rule.Pattern)6 WorkingMemory (org.drools.core.WorkingMemory)5 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)5 Consequence (org.drools.core.spi.Consequence)5 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)5 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)4 IOException (java.io.IOException)3 ObjectInput (java.io.ObjectInput)3 ObjectOutput (java.io.ObjectOutput)3 ClassFieldReader (org.drools.core.base.ClassFieldReader)3 Declaration (org.drools.core.rule.Declaration)3 JavaDialectRuntimeData (org.drools.core.rule.JavaDialectRuntimeData)3