use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class TypedModelTransactionHandler method canExecute.
@CanExecute
public boolean canExecute(@Named(ED_URI_PARAMETER_ID) String edUri, @Optional @Named(FD_URI_PARAMETER_ID) String fdUri, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
try {
bm.wEnterScope(ts);
defineBindings(edUri, fdUri, bm);
return isEnabled(bm);
} catch (Exception e) {
return false;
} finally {
ts.rollback();
bm.wExitScope();
}
}
use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class OperationHandler method canExecute.
@CanExecute
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) throws Exception {
ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
try {
bm.wEnterScope(ts);
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
return !viewer.getEditDomain().isDisabled() && isEnabled(bm);
} catch (Exception e) {
return false;
} finally {
ts.rollback();
bm.wExitScope();
}
}
use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class ExecuteSampleModelRunnable method run.
@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
IEntity selfEntity = EntityUtils.mapEntity(selfModel, EntityUtils.clone(EntityUtils.getCompoundRoot(selfModel)));
Set<String> initialNames = bm.wNames();
pm.beginTask("Executing sample...", IOperationProgressMonitor.TOTAL_WORK);
behaviorModel = BehaviorUtils.apply("whole:org.whole.lang.ui.views:SamplePerspectiveSemantics#SampleViewBehavior", behaviorModel, bm);
IEntity derivedModel = null;
try {
IEntityIterator<?> iterator = BehaviorUtils.lazyEvaluate(behaviorModel, 0, bm);
iterator.setBindings(selfBindings);
iterator.reset(selfEntity);
if (iterator.getClass().equals(ConstantIterator.class)) {
IEntity result = iterator.next();
if (result == null || !EntityUtils.isData(result))
derivedModel = result;
else {
Object resultValue = result.wGetValue();
derivedModel = IVisitor.class.isInstance(resultValue) ? BindingManagerFactory.instance.createValue(Matcher.match((IVisitor) resultValue, selfEntity)) : result;
}
} else if (iterator.hasNext()) {
derivedModel = MiscEntityFactory.instance.createMisc(0);
ITransactionScope transactionScope = BindingManagerFactory.instance.createTransactionScope();
bm.wEnterScope(transactionScope);
try {
for (IEntity result : iterator) {
transactionScope.commit();
derivedModel.wAdd(GenericEntityFactory.instance.create(CommonsEntityDescriptorEnum.SameStageFragment, // CommonsEntityFactory.instance.createSameStageFragment(
EntityUtils.clone(// TODO substitute with a no containment fragment
result)));
}
} finally {
transactionScope.rollback();
bm.wExitScope();
}
}
} catch (MissingVariableException e) {
addMissingVariables(contextModel, e);
} catch (OperationCanceledException e) {
// gracefully terminate execution
} catch (Exception e) {
if (e.getCause() instanceof MissingVariableException)
addMissingVariables(contextModel, (MissingVariableException) e.getCause());
} finally {
pm.endTask();
}
IEntity variablesModel = null;
if (derivedModel != null) {
EnvironmentEntityFactory ef = EnvironmentEntityFactory.instance;
variablesModel = ef.createBindings(0);
for (String name : new TreeSet<String>(bm.wLocalNames())) if (!initialNames.contains(name))
variablesModel.wAdd(ef.createBinding(ef.createName(name), ef.createValue(BindingUtils.wGet(bm, name))));
final IEntity contents = derivedModel;
final IEntity variables = variablesModel;
context.get(UISynchronize.class).asyncExec(new Runnable() {
public void run() {
context.get(IEntityPartViewer.class).setContents(null, contents);
context.get(IEventBroker.class).post(IE4UIConstants.TOPIC_UPDATE_VARIABLES, variables);
}
});
}
}
use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class WorkflowsInterpreterVisitor method visit.
@Override
public void visit(CreateEntity entity) {
try {
entity.getEntityName().accept(this);
String typeName = getResultString();
EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.parseEntityDescriptor(typeName);
if (ed == null)
throw new WholeIllegalArgumentException("The requested entity does not exist: " + typeName).withSourceEntity(entity).withBindings(getBindings());
IEntityRegistryProvider provider = null;
switch(entity.getRegistry().getValue().getOrdinal()) {
case RegistryEnum.DEFAULT_ord:
provider = RegistryConfigurations.DEFAULT;
break;
case RegistryEnum.RESOLVER_ord:
provider = RegistryConfigurations.RESOLVER;
break;
case RegistryEnum.ADAPTER_ord:
provider = RegistryConfigurations.ADAPTER;
break;
case RegistryEnum.STRICT_ord:
provider = RegistryConfigurations.STRICT;
break;
case RegistryEnum.CUSTOM_ord:
provider = RegistryConfigurations.CUSTOM;
break;
}
IEntityFactory ef = GenericEntityFactory.instance(provider);
IEntity model;
Arguments arguments = entity.getArguments();
if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Assignments, arguments)) {
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
arguments.accept(this);
for (int i = 0; i < arguments.wSize(); i++) {
String name = ((Assignments) arguments).get(i).getName().getValue();
FeatureDescriptor fd = ed.getFeatureDescriptorEnum().valueOf(name);
if (fd != null)
getBindings().wDef(name, EntityUtils.convertCloneIfReparenting(getBindings().wGet(name), ed.getEntityFeatureDescriptor(fd)));
}
model = ef.create(ed, getBindings());
resettableScope.rollback();
getBindings().wExitScope();
} else if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Expressions, arguments)) {
IEntity selfEntity = getBindings().wGet("self");
if (ed.getEntityKind().isData()) {
((Expressions) arguments).get(0).accept(this);
model = DataTypeUtils.convertCloneIfParented(getResult(), ed);
resetSelfEntity(selfEntity);
} else {
IEntity[] values = new IEntity[arguments.wSize()];
for (int i = 0; i < values.length; i++) {
((Expressions) arguments).get(i).accept(this);
values[i] = EntityUtils.convertCloneIfReparenting(getResult(), ed.getEntityFeatureDescriptor(i));
resetSelfEntity(selfEntity);
}
model = ef.create(ed, values);
}
} else
model = ef.create(ed);
setResult(entity.getModel(), model);
} catch (Exception e) {
throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
}
}
use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class QueriesDynamicCompilerVisitor method visit.
@Override
public void visit(Choose entity) {
int size = entity.wSize();
if (size == 1)
entity.get(0).accept(this);
else {
boolean canOptimize = true;
ILanguageKit languageKit = null;
Map<EntityDescriptor<?>, Expression> typeMap = new HashMap<EntityDescriptor<?>, Expression>();
If ifWithTemplate = new IfWithTemplate().create();
If ifWithTypeTest = new IfWithTypeTest().create();
ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(ts);
for (int i = 0; i < size; i++) {
Expression child = entity.get(i);
try {
if (!Matcher.match(ifWithTemplate, child, getBindings()) && !Matcher.match(ifWithTypeTest, child, getBindings())) {
canOptimize = false;
break;
}
EntityDescriptor<?> ed = getBindings().wIsSet("typeTest") && getBindings().wGet("typeTest").wGetEntityDescriptor().getDataKind().isString() ? CommonsDataTypePersistenceParser.getEntityDescriptor(getBindings().wStringValue("typeTest")) : getBindings().wIsSet("pattern") ? getBindings().wGet("pattern").wGetEntityDescriptor() : null;
if (ed == null) {
canOptimize = false;
break;
}
if (typeMap.containsKey(ed)) {
Expression behavior = typeMap.get(ed);
boolean isPattern = behavior.wGetParent() == entity;
if (isPattern) {
canOptimize = false;
break;
}
} else {
if (languageKit == null)
languageKit = ed.getLanguageKit();
else if (!languageKit.equals(ed.getLanguageKit())) {
// ||
// !languageKit.getURI().equals("whole:org.whole.lang.javascript:JavaScript"))
// {
canOptimize = false;
break;
}
typeMap.put(ed, getBindings().wIsSet("pattern") ? child : getBindings().wGet("expression").wGetAdapter(QueriesEntityDescriptorEnum.Expression));
}
} finally {
ts.rollback();
}
}
getBindings().wExitScope();
if (canOptimize && languageKit != null) {
ChooseByTypeIterator<IEntity> chooseIterator = IteratorFactory.chooseIterator(languageKit);
for (Entry<EntityDescriptor<?>, Expression> entry : typeMap.entrySet()) {
Set<String> oldDeclaredNames = declaredNames;
entry.getValue().accept(this);
chooseIterator.setCase(entry.getKey(), getResultIterator());
declaredNames = oldDeclaredNames;
}
setResultIterator(chooseIterator.withSourceEntity(entity));
} else {
IEntityIterator<? extends IEntity>[] iteratorChain = new IEntityIterator<?>[size];
for (int i = 0; i < size; i++) {
entity.get(i).accept(this);
iteratorChain[i] = getResultIterator();
}
setResultIterator(IteratorFactory.chooseIterator(iteratorChain).withSourceEntity(entity));
}
}
}
Aggregations