Search in sources :

Example 16 with EntityMetamodel

use of com.blazebit.persistence.parser.EntityMetamodel in project blaze-persistence by Blazebit.

the class FullEntityLoader method createQueryString.

private String createQueryString(EntityViewManagerImpl evm, ManagedViewType<?> subviewType, boolean multiple) {
    EntityMetamodel entityMetamodel = evm.getMetamodel().getEntityMetamodel();
    EntityType<?> entityType = entityMetamodel.getEntity(entityClass);
    // We can't query embeddables
    if (entityType == null) {
        return null;
    }
    Set<String> fetchJoinableRelations = new HashSet<>(subviewType.getAttributes().size());
    addFetchJoinableRelations(fetchJoinableRelations, "", subviewType);
    CriteriaBuilderFactory cbf = evm.getCriteriaBuilderFactory();
    if (fetchJoinableRelations.isEmpty()) {
        return null;
    } else {
        CriteriaBuilder<?> criteriaBuilder = cbf.create(null, entityClass).fetch(fetchJoinableRelations.toArray(new String[fetchJoinableRelations.size()]));
        if (multiple) {
            criteriaBuilder.where(JpaMetamodelUtils.getSingleIdAttribute(entityType).getName()).inExpressions(":entityIds");
        } else {
            criteriaBuilder.where(JpaMetamodelUtils.getSingleIdAttribute(entityType).getName()).eqExpression(":id");
        }
        return criteriaBuilder.getQueryString();
    }
}
Also used : CriteriaBuilderFactory(com.blazebit.persistence.CriteriaBuilderFactory) EntityMetamodel(com.blazebit.persistence.parser.EntityMetamodel) HashSet(java.util.HashSet)

Aggregations

EntityMetamodel (com.blazebit.persistence.parser.EntityMetamodel)16 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ExtendedManagedType (com.blazebit.persistence.spi.ExtendedManagedType)5 AttributeAccessor (com.blazebit.persistence.view.impl.accessor.AttributeAccessor)5 MapAttribute (com.blazebit.persistence.view.metamodel.MapAttribute)5 PluralAttribute (com.blazebit.persistence.view.metamodel.PluralAttribute)5 HashSet (java.util.HashSet)5 ExtendedAttribute (com.blazebit.persistence.spi.ExtendedAttribute)4 LoadOrPersistViewToEntityMapper (com.blazebit.persistence.view.impl.entity.LoadOrPersistViewToEntityMapper)4 ViewToEntityMapper (com.blazebit.persistence.view.impl.entity.ViewToEntityMapper)4 ManagedViewType (com.blazebit.persistence.view.metamodel.ManagedViewType)4 EmbeddableUpdaterBasedViewToEntityMapper (com.blazebit.persistence.view.impl.entity.EmbeddableUpdaterBasedViewToEntityMapper)3 LoadOnlyViewToEntityMapper (com.blazebit.persistence.view.impl.entity.LoadOnlyViewToEntityMapper)3 UpdaterBasedViewToEntityMapper (com.blazebit.persistence.view.impl.entity.UpdaterBasedViewToEntityMapper)3 ManagedViewTypeImplementor (com.blazebit.persistence.view.impl.metamodel.ManagedViewTypeImplementor)3 ViewType (com.blazebit.persistence.view.metamodel.ViewType)3 JpaProvider (com.blazebit.persistence.spi.JpaProvider)2 InverseRemoveStrategy (com.blazebit.persistence.view.InverseRemoveStrategy)2