use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class AbstractReusablesSemanticsVisitor method readModel.
public static IEntity readModel(IEntity resource) {
Object[] pkpp = (Object[]) resource.wGetValue();
IPersistenceKit pk = (IPersistenceKit) pkpp[0];
IPersistenceProvider pp = (IPersistenceProvider) pkpp[1];
try {
return pk.readModel(pp);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("Resource not found with the " + pk.getId() + " persistence at " + e.getMessage(), e);
} catch (Exception e) {
throw new IllegalArgumentException("Failed to load the resource with the given persistence: " + pk.getId(), e);
}
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class WorkflowsInterpreterVisitor method visit.
@Override
public void visit(LoadArtifacts entity) {
try {
IArtifactsEntity model = null;
Variable variable = entity.getModel();
String variableName = variable.getValue();
boolean isDefined = getBindings().wIsSet(variableName);
if (isDefined) {
variable.accept(this);
model = (IArtifactsEntity) getResult();
}
entity.getRootResource().accept(this);
String resource = getResultString();
ResourceKind resourceKind = entity.getRootResourceKind();
Traverse traverse = Traverse.valueOf(DataTypeUtils.getAsPersistenceString(entity.getTraversalStrategy()));
Synchronize synchronize = Synchronize.valueOf(DataTypeUtils.getAsPersistenceString(entity.getSynchronizeStrategy()));
IPersistenceKit defaultPersistenceKit = getPersistenceKit(entity.getDefaultPersistence());
IArtifactsEntity result = ArtifactsSynchronizerVisitor.synchronize(model, traverse, synchronize, createArtifactsBindings(resource, resourceKind), defaultPersistenceKit, true);
if (isDefined) {
if (EntityUtils.hasParent(model))
model.wGetParent().wSet(model, result);
getBindings().wSet(variableName, result);
} else
getBindings().wDef(variableName, result);
setResult(result);
} catch (Exception e) {
throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
}
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class WorkflowsInterpreterVisitor method visit.
@Override
public void visit(LoadModel entity) {
try {
IPersistenceKit persistenceKit = getPersistenceKit(entity.getPersistence());
IPersistenceProvider provider = getPersistenceProvider(entity);
try {
IEntity model = persistenceKit.readModel(provider);
setResult(entity.getModel(), model);
} catch (Exception e) {
throw new IllegalArgumentException("Failed to load the resource with the given persistence: " + getResourceString(entity) + ", " + getPersistenceId(entity.getPersistence()), e);
}
} catch (Exception e) {
throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
}
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class WorkflowsInterpreterVisitor method visit.
@Override
public void visit(SaveArtifacts entity) {
try {
entity.getModel().accept(this);
IArtifactsEntity model = (IArtifactsEntity) getResult();
entity.getRootResource().accept(this);
String resource = getResultString();
ResourceKind resourceKind = entity.getRootResourceKind();
Traverse traverse = Traverse.valueOf(DataTypeUtils.getAsPersistenceString(entity.getTraversalStrategy()));
Synchronize synchronize = Synchronize.valueOf(DataTypeUtils.getAsPersistenceString(entity.getSynchronizeStrategy()));
IPersistenceKit defaultPersistenceKit = getPersistenceKit(entity.getDefaultPersistence());
ArtifactsSynchronizerVisitor.synchronize(model, traverse, synchronize, createArtifactsBindings(resource, resourceKind), defaultPersistenceKit, false);
} catch (Exception e) {
throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
}
}
use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.
the class AbstractReusablesSemanticsVisitor method writeModel.
public static void writeModel(IEntity model, IEntity resource) {
Object[] pkpp = (Object[]) resource.wGetValue();
IPersistenceKit pk = (IPersistenceKit) pkpp[0];
IPersistenceProvider pp = (IPersistenceProvider) pkpp[1];
try {
pk.writeModel(model, pp);
} catch (Exception e) {
throw new IllegalArgumentException("Failed to write the resource with the given persistence: " + pp + ", " + pk.getId(), e);
}
}
Aggregations