Search in sources :

Example 1 with TraitFieldTMS

use of org.drools.core.factmodel.traits.TraitFieldTMS in project drools by kiegroup.

the class MapCore method _getFieldTMS.

public TraitFieldTMS _getFieldTMS() {
    TraitFieldTMS tms = (TraitFieldTMS) _getDynamicProperties().get(FIELDTMS_FIELD_NAME);
    if (tms == null) {
        tms = new TraitFieldTMSImpl();
        _getDynamicProperties().put(FIELDTMS_FIELD_NAME, tms);
    }
    return tms;
}
Also used : TraitFieldTMSImpl(org.drools.core.factmodel.traits.TraitFieldTMSImpl) TraitFieldTMS(org.drools.core.factmodel.traits.TraitFieldTMS)

Example 2 with TraitFieldTMS

use of org.drools.core.factmodel.traits.TraitFieldTMS in project drools by kiegroup.

the class TraitHelper method updateCore.

private <T> void updateCore(TraitableBean inner, Object core, Class<T> trait, boolean logical, Activation activation) {
    FactHandle handle = lookupFactHandle(inner);
    InternalFactHandle h = (InternalFactHandle) handle;
    if (handle != null) {
        TraitFieldTMS fieldTMS = inner._getFieldTMS();
        BitMask mask = fieldTMS == null ? onlyTraitBitSetMask() : fieldTMS.getModificationMask();
        Object o = h.getObject();
        NamedEntryPoint nep = (NamedEntryPoint) h.getEntryPoint();
        PropagationContext propagationContext = nep.getPctxFactory().createPropagationContext(nep.getInternalWorkingMemory().getNextPropagationIdCounter(), PropagationContext.Type.MODIFICATION, activation.getRule(), activation.getTuple().getTupleSink(), h, nep.getEntryPoint(), mask, core.getClass(), null);
        nep.update(h, o, o, nep.getObjectTypeConfigurationRegistry().getObjectTypeConf(nep.getEntryPoint(), o), propagationContext);
    } else {
        handle = this.workingMemory.insert(inner, false, activation.getRule(), activation.getTuple().getTupleSink());
    }
}
Also used : TraitFieldTMS(org.drools.core.factmodel.traits.TraitFieldTMS) PropagationContext(org.drools.core.spi.PropagationContext) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) BitMask(org.drools.core.util.bitmask.BitMask) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 3 with TraitFieldTMS

use of org.drools.core.factmodel.traits.TraitFieldTMS in project drools by kiegroup.

the class TraitableMap method _getFieldTMS.

default TraitFieldTMS _getFieldTMS() {
    TraitFieldTMS tms = (TraitFieldTMS) _getDynamicProperties().get(FIELDTMS_FIELD_NAME);
    if (tms == null) {
        tms = new TraitFieldTMSImpl();
        _getDynamicProperties().put(FIELDTMS_FIELD_NAME, tms);
    }
    return tms;
}
Also used : TraitFieldTMSImpl(org.drools.core.factmodel.traits.TraitFieldTMSImpl) TraitFieldTMS(org.drools.core.factmodel.traits.TraitFieldTMS)

Example 4 with TraitFieldTMS

use of org.drools.core.factmodel.traits.TraitFieldTMS 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)

Aggregations

TraitFieldTMS (org.drools.core.factmodel.traits.TraitFieldTMS)4 InternalFactHandle (org.drools.core.common.InternalFactHandle)2 TraitFieldTMSImpl (org.drools.core.factmodel.traits.TraitFieldTMSImpl)2 FactHandle (org.kie.api.runtime.rule.FactHandle)2 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)1 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 ObjectTypeConfigurationRegistry (org.drools.core.common.ObjectTypeConfigurationRegistry)1 ClassDefinition (org.drools.core.factmodel.ClassDefinition)1 TraitableBean (org.drools.core.factmodel.traits.TraitableBean)1 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)1 PropagationContext (org.drools.core.spi.PropagationContext)1 BitMask (org.drools.core.util.bitmask.BitMask)1