use of com.haulmont.cuba.core.global.EntityLoadInfo in project cuba by cuba-platform.
the class EntityFactory method build.
@Override
public Object build(String string) {
if (StringUtils.isBlank(string))
return null;
EntityLoadInfo info = EntityLoadInfo.parse(string);
if (info == null)
throw new IllegalArgumentException("Invalid entity info: " + string);
LoadContext ctx = new LoadContext(info.getMetaClass()).setId(info.getId());
if (info.getViewName() != null)
ctx.setView(info.getViewName());
return ds.load(ctx);
}
use of com.haulmont.cuba.core.global.EntityLoadInfo in project cuba by cuba-platform.
the class EntityFactory method build.
@Override
public Object build(String string) {
if (StringUtils.isBlank(string)) {
return null;
}
EntityLoadInfo info = EntityLoadInfo.parse(string);
if (info == null) {
throw new IllegalArgumentException("Invalid entity info: " + string);
}
Entity entity;
String property = AppContext.getProperty("cuba.useCurrentTxForConfigEntityLoad");
Transaction tx = Boolean.valueOf(property) ? persistence.getTransaction() : persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
View view = null;
if (info.getViewName() != null) {
view = metadata.getViewRepository().getView(info.getMetaClass(), info.getViewName());
}
Class javaClass = info.getMetaClass().getJavaClass();
if (view != null) {
entity = em.find(javaClass, info.getId(), view);
} else {
entity = em.find(javaClass, info.getId());
}
tx.commit();
} finally {
tx.end();
}
return entity;
}
Aggregations