public <T> List<T> getCats(EntityViewSetting<T, CriteriaBuilder<T>> setting) { // formulate a query via a CriteriaBuilder CriteriaBuilder<Cat> cb = cbf.create(emHolder.getEntityManager(), Cat.class); // you could extend the query by restrictions // at this point we combine the entity view setting with the CriteriaBuilder // this results in a CriteriaBuilder returning instances of the desired entity view CriteriaBuilder<T> basicCb = evm.applySetting(setting, cb); // now we can issue the query and get the results return basicCb.getResultList(); }
public <T> List<T> getCats(EntityViewSetting<T, CriteriaBuilder<T>> setting) { // formulate a query via a CriteriaBuilder CriteriaBuilder<Cat> cb = cbf.create(emHolder.getEntityManager(), Cat.class); // you could extend the query by restrictions // at this point we combine the entity view setting with the CriteriaBuilder // this results in a CriteriaBuilder returning instances of the desired entity view CriteriaBuilder<T> basicCb = evm.applySetting(setting, cb); // now we can issue the query and get the results return basicCb.getResultList(); }
public <T> List<T> getCats(EntityViewSetting<T, CriteriaBuilder<T>> setting) { // formulate a query via a CriteriaBuilder CriteriaBuilder<Cat> cb = cbf.create(emHolder.getEntityManager(), Cat.class); // you could extend the query by restrictions // at this point we combine the entity view setting with the CriteriaBuilder // this results in a CriteriaBuilder returning instances of the desired entity view CriteriaBuilder<T> basicCb = evm.applySetting(setting, cb); // now we can issue the query and get the results return basicCb.getResultList(); }
@Override public List<V> findAll() { return context.getEntityViewManager().applySetting( createSetting(), createCriteriaBuilder() ).getResultList(); }
@Override public V findBy(PK pk) { CriteriaBuilder<E> cb = createCriteriaBuilder(); List<V> result = context.getEntityViewManager().applySetting( createSetting(), cb.where(idAttribute()).eq(pk) ).getResultList(); return result.isEmpty() ? null : result.get(0); }
@Override public <T> T find(EntityManager entityManager, EntityViewSetting<T, CriteriaBuilder<T>> entityViewSetting, Object entityId) { ViewTypeImpl<T> managedViewType = metamodel.view(entityViewSetting.getEntityViewClass()); EntityType<?> entityType = (EntityType<?>) managedViewType.getJpaManagedType(); SingularAttribute<?, ?> idAttribute = JpaMetamodelUtils.getSingleIdAttribute(entityType); CriteriaBuilder<?> cb = cbf.create(entityManager, managedViewType.getEntityClass()) .where(idAttribute.getName()).eq(entityId); List<T> resultList = applySetting(entityViewSetting, cb).getResultList(); return resultList.isEmpty() ? null : resultList.get(0); }
public List<PostFlushDeleter> removeByOwnerId(UpdateContext context, Object ownerId) { EntityViewManagerImpl evm = context.getEntityViewManager(); List<Object> elementIds = (List<Object>) evm.getCriteriaBuilderFactory().create(context.getEntityManager(), parentEntityClass, "e") .where(parentIdAttributeName).eq(ownerId) .select("e." + attributeName + "." + childIdAttributeName) .getResultList(); if (!elementIds.isEmpty()) { // We must always delete this, otherwise we might get a constraint violation because of the cascading delete DeleteCriteriaBuilder<?> cb = evm.getCriteriaBuilderFactory().deleteCollection(context.getEntityManager(), parentEntityClass, "e", attributeName); cb.where(parentIdAttributeName).eq(ownerId); cb.executeUpdate(); } return Collections.<PostFlushDeleter>singletonList(new PostFlushInverseCollectionElementByIdDeleter(deleter, elementIds)); }
.where(ownerIdAttributeName).eq(ownerId) .select("e." + attributeName + "." + elementDescriptor.getEntityIdAttributeName()) .getResultList(); if (!elementIds.isEmpty() && !jpaProviderDeletesCollection) {
.where(ownerIdAttributeName).eq(ownerId) .select("e." + mapping + "." + elementDescriptor.getEntityIdAttributeName()) .getResultList(); if (!elementIds.isEmpty() && !jpaProviderDeletesCollection) {
.where(ownerIdAttributeName).eq(ownerId) .select("e." + attributeName + "." + elementIdAttributeName) .getResultList(); if (!elementIds.isEmpty()) {
.where(ownerIdAttributeName).eq(ownerId) .select("e." + attributeName + "." + elementIdAttributeName) .getResultList(); if (!elementIds.isEmpty()) {
public <T> List<T> getCatHierarchy(Integer catId, EntityViewSetting<T, CriteriaBuilder<T>> setting) { CriteriaBuilder<Tuple> cb = cbf.create(emHolder.getEntityManager(), Tuple.class) .withRecursive(CatHierarchyCTE.class) .from(Cat.class) .bind("id").select("id") .bind("motherId").select("mother.id") .bind("fatherId").select("father.id") .bind("generation").select("0") .where("id").eqExpression(catId.toString()) .unionAll() .from(Cat.class, "cat") .from(CatHierarchyCTE.class, "cte") .bind("id").select("cat.id") .bind("motherId").select("cat.mother.id") .bind("fatherId").select("cat.father.id") .bind("generation").select("cte.generation + 1") .whereOr() .where("cat.id").eqExpression("cte.motherId") .where("cat.id").eqExpression("cte.fatherId") .endOr() .end() .from(Cat.class, "cat") .innerJoinOn(CatHierarchyCTE.class, "cte").on("cte.id").eqExpression("cat.id").end() .orderByAsc("cte.generation"); return evm.applySetting(setting, cb).getResultList(); }
public <T> List<T> getCatHierarchy(Integer catId, EntityViewSetting<T, CriteriaBuilder<T>> setting) { CriteriaBuilder<Tuple> cb = cbf.create(emHolder.getEntityManager(), Tuple.class) .withRecursive(CatHierarchyCTE.class) .from(Cat.class) .bind("id").select("id") .bind("motherId").select("mother.id") .bind("fatherId").select("father.id") .bind("generation").select("0") .where("id").eqExpression(catId.toString()) .unionAll() .from(Cat.class, "cat") .from(CatHierarchyCTE.class, "cte") .bind("id").select("cat.id") .bind("motherId").select("cat.mother.id") .bind("fatherId").select("cat.father.id") .bind("generation").select("cte.generation + 1") .whereOr() .where("cat.id").eqExpression("cte.motherId") .where("cat.id").eqExpression("cte.fatherId") .endOr() .end() .from(Cat.class, "cat") .innerJoinOn(CatHierarchyCTE.class, "cte").on("cte.id").eqExpression("cat.id").end() .orderByAsc("cte.generation"); return evm.applySetting(setting, cb).getResultList(); }
public <T> List<T> getCatHierarchy(Integer catId, EntityViewSetting<T, CriteriaBuilder<T>> setting) { CriteriaBuilder<Tuple> cb = cbf.create(emHolder.getEntityManager(), Tuple.class) .withRecursive(CatHierarchyCTE.class) .from(Cat.class) .bind("id").select("id") .bind("motherId").select("mother.id") .bind("fatherId").select("father.id") .bind("generation").select("0") .where("id").eqExpression(catId.toString()) .unionAll() .from(Cat.class, "cat") .from(CatHierarchyCTE.class, "cte") .bind("id").select("cat.id") .bind("motherId").select("cat.mother.id") .bind("fatherId").select("cat.father.id") .bind("generation").select("cte.generation + 1") .whereOr() .where("cat.id").eqExpression("cte.motherId") .where("cat.id").eqExpression("cte.fatherId") .endOr() .end() .from(Cat.class, "cat") .innerJoinOn(CatHierarchyCTE.class, "cte").on("cte.id").eqExpression("cat.id").end() .orderByAsc("cte.generation"); return evm.applySetting(setting, cb).getResultList(); }