Search in sources :

Example 1 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class IEntityIterator method evaluateRemaining.

public default E evaluateRemaining() {
    E result = null;
    IBindingManager bm = getBindings();
    ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
    bm.wEnterScope(resettableScope);
    try {
        while (hasNext()) {
            bm.setResult(result = next());
            resettableScope.commit();
        }
    } finally {
        resettableScope.rollback();
        bm.wExitScope();
    }
    return result;
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 2 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class TestsInterpreterVisitor method evaluate.

protected void evaluate(SubjectStatement entity) {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    getBindings().wEnterScope(ts);
    try {
        IEntity subject = evaluate(entity.getSubject(), true);
        if (!EntityUtils.isNull(subject))
            subject = applyFilterRule(subject);
        IVisitor constraint = evaluate(entity.getConstraint());
        boolean result = Matcher.match(constraint, subject);
        if (getBindings().wIsSet("thrownException"))
            throw (RuntimeException) getBindings().wGetValue("thrownException");
        if (!result)
            throw new TestsException(entity, subject, constraint, getBindings());
    } finally {
        ts.rollback();
        getBindings().wExitScope();
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity) IVisitor(org.whole.lang.visitors.IVisitor)

Example 3 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class TestCase method evaluate.

protected static IEntity evaluate(IEntity model, boolean rollbackScope, boolean catchExceptions) {
    IEntity entity = NullEntity.instance;
    RuntimeException thrownException = null;
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        if (rollbackScope)
            bindings().wEnterScope(ts);
        entity = BehaviorUtils.evaluate(model, 0, bindings());
    } catch (RuntimeException e) {
        if (catchExceptions)
            // save exception for later evaluation
            thrownException = e;
        else
            throw e;
    } finally {
        if (rollbackScope) {
            ts.rollback();
            bindings().wExitScope();
        }
    }
    if (thrownException != null)
        bindings().wDefValue("thrownException", thrownException);
    return entity;
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity)

Example 4 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class FragmentModelTransactionHandler method execute.

@Execute
public void execute(@Named(FRAGMENT_XWL_PARAMETER_ID) String fragmentXwl, @Named(PREDICATE_XWL_PARAMETER_ID) String predicateXwl, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm, IEntityPartViewer viewer) throws Exception {
    CommandStack commandStack = viewer.getEditDomain().getCommandStack();
    ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("focusEntity"));
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        bm.wEnterScope(ts);
        defineBindings(fragmentXwl, predicateXwl, bm);
        mtc.setLabel(getLabel(bm));
        mtc.begin();
        run(bm);
        mtc.commit();
        if (mtc.canUndo())
            commandStack.execute(mtc);
    } catch (RuntimeException e) {
        mtc.rollbackIfNeeded();
        throw e;
    } finally {
        ts.rollback();
        bm.wExitScope();
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) ITransactionScope(org.whole.lang.bindings.ITransactionScope) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 5 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class FragmentModelTransactionHandler method canExecute.

@CanExecute
public boolean canExecute(@Named(FRAGMENT_XWL_PARAMETER_ID) String fragmentXwl, @Named(PREDICATE_XWL_PARAMETER_ID) String predicateXwl, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) throws Exception {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        bm.wEnterScope(ts);
        defineBindings(fragmentXwl, predicateXwl, bm);
        return isEnabled(bm);
    } catch (Exception e) {
        return false;
    } finally {
        ts.rollback();
        bm.wExitScope();
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Aggregations

ITransactionScope (org.whole.lang.bindings.ITransactionScope)27 IEntity (org.whole.lang.model.IEntity)14 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)10 Execute (org.eclipse.e4.core.di.annotations.Execute)4 CommandStack (org.eclipse.gef.commands.CommandStack)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 RollbackException (org.whole.lang.lifecycle.RollbackException)4 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)4 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)3 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)3 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)3 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 InternalIEntity (org.whole.lang.model.InternalIEntity)2 IVisitor (org.whole.lang.visitors.IVisitor)2 MissingVariableException (org.whole.lang.visitors.MissingVariableException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1