use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class TestsLearningInterpreterVisitor method visit.
@Override
public void visit(TestSuite entity) {
if (isLearning()) {
Map<IEntity, List<IEntity>> learntMap = getLearntMap();
IEntity result = null;
for (int cycle = 1; cycle <= learnCycles(); cycle++) {
printWriter().printf("*** Learning cycle %d ***\n\n", cycle);
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
try {
getBindings().wDefValue("learnCycle", cycle);
super.visit(entity);
result = getBindings().getResult();
} finally {
resettableScope.rollback();
getBindings().wExitScope();
}
}
getBindings().setResult(result);
FilterFamily filterFamily = getFilterFamily(entity);
FilterRules filterRules = filterFamily.getFilterRules();
FreshNameGenerator fnGen = new FreshNameGenerator();
for (IEntity name : BehaviorUtils.compileAndLazyEvaluate(createFindAllFilterRuleNamesQuery(), filterFamily)) fnGen.addBoundName(name.wStringValue());
for (IEntity adapter : learntMap.keySet()) {
List<IEntity> learntEntities = learntMap.get(adapter);
IEntity value = learntEntities.get(0);
if (learntEntities.size() > 1 && EntityUtils.isData(value)) {
for (IEntity learntEntity : learntEntities) if (!learntEntity.wEquals(value))
continue;
} else if (learntEntities.size() > 1) {
for (IEntity learntEntity2 : learntEntities) if (EntityUtils.isData(learntEntity2))
continue;
// generate filter rule
FilterRule filterRule = TestsHelpers.createFilterRule(learntEntities);
if (EntityUtils.isNotResolver(filterRule)) {
String filterName;
IEntity filterBody;
if ((filterBody = Matcher.find(filterRule.getBody(), filterRules, false)) != null) {
// try to reuse a generated filter
filterName = ((FilterRule) filterBody.wGetParent()).getName().getValue();
} else {
// add the filter rule to the filter family
filterName = fnGen.nextFreshName(GENERATED_FILTER_NAME);
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
try {
getBindings().wDefValue("filterName", filterName);
Matcher.substitute(filterRule, getBindings(), false);
filterRules.wAdd(filterRule);
} finally {
resettableScope.rollback();
getBindings().wExitScope();
}
}
// wrap SubjectStatement with a UsingFilter
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
try {
SubjectStatement statement = BehaviorUtils.evaluateFirstResult(createFindAncestorSubjectStatement(), adapter, getBindings());
UsingFilter usingFilter = createUsingFilter(filterName);
statement.wGetParent().wSet(statement, usingFilter);
usingFilter.setSubjectStatement(statement);
} finally {
resettableScope.rollback();
getBindings().wExitScope();
}
}
}
TestsHelpers.replace(adapter, value);
}
// add the newly generated family
if (!EntityUtils.hasParent(filterFamily) && !filterRules.wIsEmpty())
entity.getFilterFamilies().wAdd(filterFamily);
} else
super.visit(entity);
}
use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class IEntityIterator method evaluateSingleton.
public default E evaluateSingleton() {
E result = null;
IBindingManager bm = getBindings();
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
bm.wEnterScope(resettableScope);
try {
if (hasNext()) {
bm.setResult(result = next());
resettableScope.commit();
}
if (result == null || hasNext())
throw new IllegalArgumentException("The result is not a singleton");
} finally {
resettableScope.rollback();
bm.wExitScope();
}
return result;
}
use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class DynamicInterpreterVisitor method apply.
protected void apply(IEntityIterator<?> iterator) {
IBindingManager bm = getBindings();
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
bm.wEnterScope(resettableScope);
for (IEntity e : iterator) {
bm.setResult(e);
resettableScope.commit();
}
resettableScope.rollback();
bm.wExitScope();
}
use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class GenericCloneVisitor method setChildren.
protected void setChildren(IEntity entity, IEntity entityClone) {
IEntity oldSelfEntity2 = getBindings().wGet("self");
for (int index = 0; index < entity.wSize(); index++) {
int resultSize = entityClone.wSize();
stagedVisitIfNeeded(entityClone.wGet(index));
// was applyIfNeeded(entity.wGet(index));
int nextResultSize = entityClone.wSize();
index += (nextResultSize - resultSize);
if (isResultIterator()) {
IEntityIterator<?> iterator = getResultIterator();
setResultIterator(null);
IEntity selfEntity = getBindings().wGet("self");
if (selfEntity != oldSelfEntity2)
getBindings().wDef("self", selfEntity = oldSelfEntity2);
iterator.reset(selfEntity);
FeatureDescriptor resultChildDescriptor = entityClone.wGetFeatureDescriptor(index);
if (EntityUtils.isComposite(entityClone)) {
entityClone.wRemove(index--);
if (iterator.hasNext()) {
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
resultSize = entityClone.wSize();
for (IEntity value : iterator) {
nextResultSize = entityClone.wSize();
index += (nextResultSize - resultSize);
if (BindingManagerFactory.instance.isVoid(value))
resultSize = nextResultSize;
else {
entityClone.wAdd(++index, EntityUtils.convertCloneIfReparenting(value, resultChildDescriptor));
resultSize = entityClone.wSize();
}
resettableScope.commit();
}
resettableScope.rollback();
getBindings().wExitScope();
}
} else {
IEntity value = null;
if (iterator.hasNext()) {
ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
getBindings().wEnterScope(resettableScope);
for (IEntity r : iterator) {
if (!BindingManagerFactory.instance.isVoid(r))
value = r;
resettableScope.commit();
}
resettableScope.rollback();
getBindings().wExitScope();
}
if (value != null)
entityClone.wSet(index, EntityUtils.convertCloneIfReparenting(value, resultChildDescriptor));
else
entityClone.wRemove(index);
}
} else {
IEntity value = getResult();
if (value != null && !BindingManagerFactory.instance.isVoid(value)) {
FeatureDescriptor resultChildDescriptor = entityClone.wGetFeatureDescriptor(index);
entityClone.wSet(index, EntityUtils.convertCloneIfReparenting(value, resultChildDescriptor));
} else
entityClone.wRemove(index);
}
}
}
use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.
the class ActionCallHandler method canExecute.
@CanExecute
public boolean canExecute(@Named(FUNCTION_URI_PARAMETER_ID) String functionUri, @Named(PREDICATE_XWL_PARAMETER_ID) String predicateXwl, @Optional @Named(ANALYSING_PARAMETER_ID) String analyzing, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) throws Exception {
ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
try {
bm.wEnterScope(ts);
defineBindings(functionUri, predicateXwl, analyzing, bm);
return HandlersBehavior.canCallAction(bm);
} catch (Exception e) {
return false;
} finally {
ts.rollback();
bm.wExitScope();
}
}
Aggregations