Search in sources :

Example 96 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class GetObjectsCommand method execute.

public Collection execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    Collection col = null;
    if (getFilter() != null) {
        col = ksession.getObjects(this.filter);
    } else {
        col = ksession.getObjects();
    }
    if (this.outIdentifier != null) {
        List objects = new ArrayList(col);
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, objects);
    }
    return col;
}
Also used : ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) ArrayList(java.util.ArrayList) Collection(java.util.Collection) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.kie.internal.command.RegistryContext) ArrayList(java.util.ArrayList) List(java.util.List)

Example 97 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class InsertObjectCommand method execute.

public FactHandle execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    FactHandle factHandle;
    if (StringUtils.isEmpty(this.entryPoint)) {
        factHandle = ksession.insert(object);
    } else {
        factHandle = ksession.getEntryPoint(this.entryPoint).insert(object);
    }
    if (outIdentifier != null) {
        if (this.returnObject) {
            ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, object);
        }
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).getFactHandles().put(this.outIdentifier, factHandle);
    }
    if (disconnected) {
        DefaultFactHandle disconnectedHandle = ((DefaultFactHandle) factHandle).clone();
        disconnectedHandle.disconnect();
        return disconnectedHandle;
    }
    return factHandle;
}
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) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.kie.internal.command.RegistryContext)

Example 98 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class QueryCommand method execute.

public QueryResults execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    if (this.arguments == null || this.arguments.isEmpty()) {
        this.arguments = Collections.emptyList();
    }
    for (int j = 0; j < arguments.size(); j++) {
        if (arguments.get(j) instanceof Variable) {
            arguments.set(j, Variable.v);
        }
    }
    QueryResults results = ksession.getQueryResults(name, this.arguments.toArray());
    if (this.outIdentifier != null) {
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, new FlatQueryResults((QueryResultsImpl) results));
    }
    return results;
}
Also used : QueryResultsImpl(org.drools.core.QueryResultsImpl) Variable(org.kie.api.runtime.rule.Variable) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.kie.internal.command.RegistryContext) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) QueryResults(org.kie.api.runtime.rule.QueryResults)

Example 99 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class TransactionTestCommand method execute.

public Void execute(Context context) {
    em.joinTransaction();
    em.persist(mainObject);
    if (subObject != null) {
        KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
        // THe following 3 lines are the important ones! (See below for an explanation)
        InternalKnowledgeBase cleanKBase = KnowledgeBaseFactory.newKnowledgeBase();
        cleanKBase.addPackages(ksession.getKieBase().getKiePackages());
        StatefulKnowledgeSession commandKSession = JPAKnowledgeService.newStatefulKnowledgeSession(cleanKBase, null, initializeEnvironment());
        /**
         *  Here's what's going on:
         *  If the PersistableRunner (SSCS) & JtaTransactionManager (JTM) were _not_ aware of transactions,
         *  -> then inserting the mainObject _before_ having inserted the subObject
         *     would cause the operation/persist to fail and the transaction to fail.
         *     - This is because the mainObject contains a foreign key referring to the subObject.
         *
         *  However, the SSCS & JTM check whether or not they're owners of the transaction
         *  when starting and when committing the transaction they use.
         *  -> So that when we insert the mainObject here (via a _new_ CommandBasedStatefulKnowledgeSession),
         *     it does _not_ mess with the transaction state and the operation succeeds.
         */
        TransactionTestCommand transactionTestSubCommand = new TransactionTestCommand(this.subObject, getPersistenceEnvironment());
        commandKSession.execute(transactionTestSubCommand);
    }
    return null;
}
Also used : StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.kie.internal.command.RegistryContext) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase)

Example 100 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class SetDMNActiveModelCommand method execute.

@Override
public DMNModel execute(Context context) {
    RegistryContext registryContext = (RegistryContext) context;
    DMNModel activeModel = getDMNModel(context);
    ;
    registryContext.register(DMNModel.class, activeModel);
    return activeModel;
}
Also used : RegistryContext(org.kie.internal.command.RegistryContext) DMNModel(org.kie.dmn.api.core.DMNModel)

Aggregations

RegistryContext (org.kie.internal.command.RegistryContext)126 KieSession (org.kie.api.runtime.KieSession)106 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)37 Context (org.kie.api.runtime.Context)27 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)27 ArrayList (java.util.ArrayList)17 FactHandle (org.kie.api.runtime.rule.FactHandle)16 Test (org.junit.Test)14 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)13 List (java.util.List)12 CaseEventSupport (org.jbpm.casemgmt.impl.event.CaseEventSupport)12 EntryPoint (org.kie.api.runtime.rule.EntryPoint)12 Map (java.util.Map)11 HashMap (java.util.HashMap)10 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)9 ExecutableCommand (org.kie.api.command.ExecutableCommand)9 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)8 NodeInstance (org.kie.api.runtime.process.NodeInstance)8 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)8 Collection (java.util.Collection)7