@Nullable protected Entity findEntity(String entityName, Object entityId) { Entity entity = null; if (entityId != null && !Strings.isNullOrEmpty(entityName)) { MetaClass metaClass = metadata.getClass(entityName); if (metaClass != null) { LoadContext ctx = new LoadContext(metaClass).setQuery( LoadContext.createQuery(String.format("select e from %s e where e.%s = :entityId", entityName, referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass))) .setParameter("entityId", entityId)) .setView(View.MINIMAL); entity = dataManager.load(ctx); } } return entity; }
String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass); List<BaseGenericIdEntity> entitiesValues = em.createQuery(format("select e from %s e where e.%s in :ids", metaClass.getName(), pkName)) .setParameter("ids", ids)
@SuppressWarnings("unchecked") protected void fillDefaultEntities(Class entityClass) { MetaClass metaClass = metadata.getClassNN(entityClass); if (attribute.getObjectDefaultEntityId() != null) { LoadContext<Entity> lc = new LoadContext<>(entityClass).setView(View.MINIMAL); String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass); lc.setQueryString(format("select e from %s e where e.%s = :entityId", metaClass.getName(), pkName)) .setParameter("entityId", attribute.getObjectDefaultEntityId()); Entity entity = dataManager.load(lc); if (entity != null) { defaultEntityField.setValue(entity); } else { defaultEntityField.setValue(null); } } }
LoadContext.createQuery(String.format("select e from %s e where e.%s = :entityId", metaClass.getName(), referenceToEntitySupport.getPrimaryKeyForLoadingEntity(metaClass))) .setParameter("entityId", entityId)); Entity entity = dataManager.load(ctx);
MetaClass entityMetaClass = metadata.getClassNN(categoryAttribute.getJavaClassForEntity()); LoadContext<Entity> lc = new LoadContext<>(entityMetaClass).setView(View.MINIMAL); String pkName = referenceToEntitySupport.getPrimaryKeyForLoadingEntity(entityMetaClass); lc.setQueryString(format("select e from %s e where e.%s = :entityId", entityMetaClass.getName(), pkName)) .setParameter("entityId", categoryAttribute.getDefaultValue());