Search in sources :

Example 1 with EntityLoadInfo

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);
}
Also used : EntityLoadInfo(com.haulmont.cuba.core.global.EntityLoadInfo) LoadContext(com.haulmont.cuba.core.global.LoadContext)

Example 2 with EntityLoadInfo

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;
}
Also used : EntityLoadInfo(com.haulmont.cuba.core.global.EntityLoadInfo) Entity(com.haulmont.cuba.core.entity.Entity) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) View(com.haulmont.cuba.core.global.View)

Aggregations

EntityLoadInfo (com.haulmont.cuba.core.global.EntityLoadInfo)2 EntityManager (com.haulmont.cuba.core.EntityManager)1 Transaction (com.haulmont.cuba.core.Transaction)1 Entity (com.haulmont.cuba.core.entity.Entity)1 LoadContext (com.haulmont.cuba.core.global.LoadContext)1 View (com.haulmont.cuba.core.global.View)1