Search in sources :

Example 1 with PluralAttribute

use of javax.persistence.metamodel.PluralAttribute 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 Primitives.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 2 with PluralAttribute

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

the class AbstractManagedType method getBuilder.

public Builder<X> getBuilder() {
    if (locked) {
        throw new IllegalStateException("Type has been locked");
    }
    return new Builder<X>() {

        @Override
        @SuppressWarnings("unchecked")
        public void addAttribute(Attribute<X, ?> attribute) {
            declaredAttributes.put(attribute.getName(), attribute);
            final Bindable.BindableType bindableType = ((Bindable) attribute).getBindableType();
            switch(bindableType) {
                case SINGULAR_ATTRIBUTE:
                    {
                        declaredSingularAttributes.put(attribute.getName(), (SingularAttribute<X, ?>) attribute);
                        break;
                    }
                case PLURAL_ATTRIBUTE:
                    {
                        declaredPluralAttributes.put(attribute.getName(), (PluralAttribute<X, ?, ?>) attribute);
                        break;
                    }
                default:
                    {
                        throw new AssertionFailure("unknown bindable type: " + bindableType);
                    }
            }
        }
    };
}
Also used : SingularAttribute(javax.persistence.metamodel.SingularAttribute) AssertionFailure(org.hibernate.annotations.common.AssertionFailure) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) SetAttribute(javax.persistence.metamodel.SetAttribute) CollectionAttribute(javax.persistence.metamodel.CollectionAttribute) MapAttribute(javax.persistence.metamodel.MapAttribute) ListAttribute(javax.persistence.metamodel.ListAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) Bindable(javax.persistence.metamodel.Bindable)

Example 3 with PluralAttribute

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

the class AbstractFromImpl method joinCollection.

@Override
@SuppressWarnings({ "unchecked" })
public <X, Y> CollectionJoin<X, Y> joinCollection(String attributeName, JoinType jt) {
    final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute(attributeName);
    if (!attribute.isCollection()) {
        throw new IllegalArgumentException("Requested attribute was not a collection");
    }
    final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
    if (!PluralAttribute.CollectionType.COLLECTION.equals(pluralAttribute.getCollectionType())) {
        throw new IllegalArgumentException("Requested attribute was not a collection");
    }
    return (CollectionJoin<X, Y>) join((CollectionAttribute) attribute, jt);
}
Also used : CollectionAttribute(javax.persistence.metamodel.CollectionAttribute) CollectionJoin(javax.persistence.criteria.CollectionJoin) 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)

Example 4 with PluralAttribute

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

the class AbstractFromImpl method joinSet.

@Override
@SuppressWarnings({ "unchecked" })
public <X, Y> SetJoin<X, Y> joinSet(String attributeName, JoinType jt) {
    final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute(attributeName);
    if (!attribute.isCollection()) {
        throw new IllegalArgumentException("Requested attribute was not a set");
    }
    final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
    if (!PluralAttribute.CollectionType.SET.equals(pluralAttribute.getCollectionType())) {
        throw new IllegalArgumentException("Requested attribute was not a set");
    }
    return (SetJoin<X, Y>) join((SetAttribute) attribute, jt);
}
Also used : 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) SetJoin(javax.persistence.criteria.SetJoin) SetAttribute(javax.persistence.metamodel.SetAttribute)

Example 5 with PluralAttribute

use of javax.persistence.metamodel.PluralAttribute 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)

Aggregations

Attribute (javax.persistence.metamodel.Attribute)6 PluralAttribute (javax.persistence.metamodel.PluralAttribute)6 CollectionAttribute (javax.persistence.metamodel.CollectionAttribute)5 ListAttribute (javax.persistence.metamodel.ListAttribute)5 MapAttribute (javax.persistence.metamodel.MapAttribute)5 SetAttribute (javax.persistence.metamodel.SetAttribute)5 SingularAttribute (javax.persistence.metamodel.SingularAttribute)5 CollectionJoin (javax.persistence.criteria.CollectionJoin)1 ListJoin (javax.persistence.criteria.ListJoin)1 MapJoin (javax.persistence.criteria.MapJoin)1 SetJoin (javax.persistence.criteria.SetJoin)1 Bindable (javax.persistence.metamodel.Bindable)1 ManagedType (javax.persistence.metamodel.ManagedType)1 AssertionFailure (org.hibernate.annotations.common.AssertionFailure)1