Search in sources :

Example 1 with TransactionAware

use of org.drools.persistence.api.TransactionAware in project jbpm by kiegroup.

the class TaskTransactionInterceptor method execute.

@Override
public synchronized RequestContext execute(Executable executable, RequestContext ctx) {
    boolean transactionOwner = false;
    try {
        transactionOwner = txm.begin();
        tpm.beginCommandScopedEntityManager();
        TransactionManagerHelper.registerTransactionSyncInContainer(this.txm, new TaskSynchronizationImpl(this));
        if (txm != null) {
            ObjectMarshallingStrategy[] strategies = (ObjectMarshallingStrategy[]) environment.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES);
            if (strategies != null) {
                for (ObjectMarshallingStrategy strategy : strategies) {
                    if (strategy instanceof TransactionAware) {
                        ((TransactionAware) strategy).onStart(txm);
                    }
                }
            }
        }
        RequestContext context = createContext();
        executeNext(executable, context);
        ctx.setResult(context.getResult());
        postInit(ctx.getResult());
        txm.commit(transactionOwner);
        return ctx;
    } catch (TaskException e) {
        // if transaction is owned by other component like process engine
        if (transactionOwner) {
            rollbackTransaction(e, transactionOwner);
            e.setRecoverable(false);
            throw e;
        } else {
            throw e;
        }
    } catch (RuntimeException re) {
        rollbackTransaction(re, transactionOwner);
        throw re;
    } catch (Exception t1) {
        rollbackTransaction(t1, transactionOwner);
        throw new RuntimeException("Wrapped exception see cause", t1);
    }
}
Also used : TaskException(org.kie.internal.task.exception.TaskException) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) TransactionAware(org.drools.persistence.api.TransactionAware) RequestContext(org.kie.api.runtime.RequestContext) TaskException(org.kie.internal.task.exception.TaskException)

Aggregations

TransactionAware (org.drools.persistence.api.TransactionAware)1 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)1 RequestContext (org.kie.api.runtime.RequestContext)1 TaskException (org.kie.internal.task.exception.TaskException)1