Search in sources :

Example 11 with Attribute

use of javax.persistence.metamodel.Attribute in project jbpm by kiegroup.

the class QueryCriteriaUtil method createPredicateFromSingleCriteria.

/**
 * This method is the main method for creating a {@link Predicate} from a (non-group)  {@link QueryCriteria} instance.
 * </p>
 * If it can not figure out how to create a {@link Predicate} from the given {@link QueryCriteria} instance,
 * then the (abstract) {@link #implSpecificCreatePredicateFromSingleCriteria(CriteriaQuery, QueryCriteria, CriteriaBuilder, Root, Class)}
 * method is called.
 *
 * @param query The {@link CriteriaQuery} that is being built
 * @param criteria The given {@link QueryCriteria} instance
 * @param builder The {@link CriteriaBuilder} builder instance
 * @param queryType The (persistent {@link Entity}) {@link Class} that we are querying on
 * @return A {@link Predicate} created on the basis of the given {@link QueryCriteria}
 */
private <R, T> Predicate createPredicateFromSingleCriteria(CriteriaQuery<R> query, CriteriaBuilder builder, Class<T> queryType, QueryCriteria criteria, QueryWhere queryWhere) {
    Predicate predicate = null;
    assert criteria.hasValues() || criteria.hasDateValues() || Integer.parseInt(criteria.getListId()) < 0 : "No values present for criteria with list id: [" + criteria.getListId() + "]";
    String listId = criteria.getListId();
    Attribute attr = getCriteriaAttributes().get(queryType).get(listId);
    if (attr != null) {
        Expression entityField = getEntityField(query, listId, attr);
        predicate = basicCreatePredicateFromSingleCriteria(builder, entityField, criteria);
    } else {
        predicate = implSpecificCreatePredicateFromSingleCriteria(query, builder, queryType, criteria, queryWhere);
    }
    return predicate;
}
Also used : SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) Expression(javax.persistence.criteria.Expression) Predicate(javax.persistence.criteria.Predicate)

Example 12 with Attribute

use of javax.persistence.metamodel.Attribute in project querydsl by querydsl.

the class JPAPathBuilderValidator method validate.

@Override
public Class<?> validate(Class<?> parent, String property, Class<?> propertyType) {
    try {
        ManagedType managedType = metamodel.managedType(parent);
        Attribute attribute = managedType.getAttribute(property);
        if (attribute instanceof PluralAttribute) {
            return ((PluralAttribute) attribute).getElementType().getJavaType();
        } else {
            return PrimitiveUtils.wrap(attribute.getJavaType());
        }
    } catch (IllegalArgumentException e) {
        return null;
    }
}
Also used : ManagedType(javax.persistence.metamodel.ManagedType) Attribute(javax.persistence.metamodel.Attribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute)

Example 13 with Attribute

use of javax.persistence.metamodel.Attribute in project midpoint by Evolveum.

the class EntityRegistry method hasAttributePathOverride.

public boolean hasAttributePathOverride(ManagedType<?> type, ItemPath pathOverride) {
    Map<UniformItemPath, Attribute<?, ?>> overrides = attributeNamePathOverrides.get(type);
    if (overrides == null) {
        return false;
    }
    ItemPath namedOnly = pathOverride.namedSegmentsOnly();
    for (UniformItemPath path : overrides.keySet()) {
        if (path.isSuperPathOrEquivalent(namedOnly)) {
            return true;
        }
    }
    return false;
}
Also used : Attribute(javax.persistence.metamodel.Attribute) UniformItemPath(com.evolveum.midpoint.prism.path.UniformItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) UniformItemPath(com.evolveum.midpoint.prism.path.UniformItemPath)

Example 14 with Attribute

use of javax.persistence.metamodel.Attribute in project hibernate-orm by hibernate.

the class AbstractFromImpl method joinList.

@Override
@SuppressWarnings({ "unchecked" })
public <X, Y> ListJoin<X, Y> joinList(String attributeName, JoinType jt) {
    final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute(attributeName);
    if (!attribute.isCollection()) {
        throw new IllegalArgumentException("Requested attribute was not a list");
    }
    final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
    if (!PluralAttribute.CollectionType.LIST.equals(pluralAttribute.getCollectionType())) {
        throw new IllegalArgumentException("Requested attribute was not a list");
    }
    return (ListJoin<X, Y>) join((ListAttribute) attribute, jt);
}
Also used : ListJoin(javax.persistence.criteria.ListJoin) CollectionAttribute(javax.persistence.metamodel.CollectionAttribute) MapAttribute(javax.persistence.metamodel.MapAttribute) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) SetAttribute(javax.persistence.metamodel.SetAttribute) ListAttribute(javax.persistence.metamodel.ListAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) ListAttribute(javax.persistence.metamodel.ListAttribute)

Example 15 with Attribute

use of javax.persistence.metamodel.Attribute in project hibernate-orm by hibernate.

the class AbstractFromImpl method joinMap.

@Override
@SuppressWarnings({ "unchecked" })
public <X, K, V> MapJoin<X, K, V> joinMap(String attributeName, JoinType jt) {
    final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute(attributeName);
    if (!attribute.isCollection()) {
        throw new IllegalArgumentException("Requested attribute was not a map");
    }
    final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
    if (!PluralAttribute.CollectionType.MAP.equals(pluralAttribute.getCollectionType())) {
        throw new IllegalArgumentException("Requested attribute was not a map");
    }
    return (MapJoin<X, K, V>) join((MapAttribute) attribute, jt);
}
Also used : MapAttribute(javax.persistence.metamodel.MapAttribute) CollectionAttribute(javax.persistence.metamodel.CollectionAttribute) MapAttribute(javax.persistence.metamodel.MapAttribute) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) SetAttribute(javax.persistence.metamodel.SetAttribute) ListAttribute(javax.persistence.metamodel.ListAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) MapJoin(javax.persistence.criteria.MapJoin)

Aggregations

Attribute (javax.persistence.metamodel.Attribute)31 SingularAttribute (javax.persistence.metamodel.SingularAttribute)21 ListAttribute (javax.persistence.metamodel.ListAttribute)13 PluralAttribute (javax.persistence.metamodel.PluralAttribute)12 MapAttribute (javax.persistence.metamodel.MapAttribute)10 Metamodel (javax.persistence.metamodel.Metamodel)9 CollectionAttribute (javax.persistence.metamodel.CollectionAttribute)6 SetAttribute (javax.persistence.metamodel.SetAttribute)6 Path (javax.persistence.criteria.Path)5 EntityType (javax.persistence.metamodel.EntityType)5 ManagedType (javax.persistence.metamodel.ManagedType)5 EntityManager (javax.persistence.EntityManager)4 TypedQuery (javax.persistence.TypedQuery)4 Predicate (javax.persistence.criteria.Predicate)4 Field (java.lang.reflect.Field)3 Expression (javax.persistence.criteria.Expression)3 From (javax.persistence.criteria.From)3 Root (javax.persistence.criteria.Root)3 IdentifiableType (javax.persistence.metamodel.IdentifiableType)3 Type (javax.persistence.metamodel.Type)3