public AbstractJoinImpl( CriteriaBuilderImpl criteriaBuilder, Class<X> javaType, PathSource<Z> pathSource, Attribute<? super Z, ?> joinAttribute, JoinType joinType) { super( criteriaBuilder, javaType, pathSource ); this.joinAttribute = joinAttribute; this.joinType = joinType; }
private ManagedType<X> resolveManagedType(SingularAttribute<?, X> attribute) { if ( Attribute.PersistentAttributeType.BASIC == attribute.getPersistentAttributeType() ) { return null; } else if ( Attribute.PersistentAttributeType.EMBEDDED == attribute.getPersistentAttributeType() ) { return (EmbeddableType<X>) attribute.getType(); } else { return (IdentifiableType<X>) attribute.getType(); } }
public RootImpl(CriteriaBuilderImpl criteriaBuilder, EntityType<X> entityType, boolean allowJoins) { super( criteriaBuilder, entityType.getJavaType() ); this.entityType = entityType; this.allowJoins = allowJoins; }
private String [] createOriginalAndExpectedKeys(Attribute embeddedAttr, PluralAttribute listAttr) { String originalKey = embeddedAttr.getDeclaringType().getJavaType().getName() + "." + embeddedAttr.getName() + "." + listAttr.getName(); String copyKey = listAttr.getDeclaringType().getJavaType().getName() + "." + listAttr.getName(); String [] keys = { originalKey, copyKey }; return keys; }
private String tryFindSingularIdAttributeNameOrUseFallback(Class<? extends Object> idPropertyValueType, String fallbackIdTypePropertyName) { ManagedType<? extends Object> idPropertyType = metamodel.managedType(idPropertyValueType); for (SingularAttribute<?, ?> sa : idPropertyType.getSingularAttributes()) { if (sa.isId()) { return sa.getName(); } } return fallbackIdTypePropertyName; }
@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 ); }
private String determineRole(MapAttribute<?,K,?> attribute) { return attribute.getDeclaringType().getJavaType().getName() + '.' + attribute.getName(); }
@SuppressWarnings("unchecked") public IdMetadata(IdentifiableType<T> source) { this.type = source; this.attributes = (Set<SingularAttribute<? super T, ?>>) (source.hasSingleIdAttribute() ? Collections.singleton(source.getId(source.getIdType().getJavaType())) : source.getIdClassAttributes()); }
public boolean isBasicCollection() { return Type.PersistenceType.BASIC.equals( getAttribute().getElementType().getPersistenceType() ); }
@Override @SuppressWarnings("unchecked") default Class<J> getClassType() { return getGraphedType().getJavaType(); } }
@Override @SuppressWarnings({"unchecked"}) protected Attribute<X, ?> locateAttributeInternal(String name) { return (Attribute<X, ?>) locateManagedType().getAttribute( name ); }
@Override protected ManagedType<E> locateManagedType() { return isBasicCollection() ? null : (ManagedType<E>) getAttribute().getElementType(); }
@Override public Class<K> getJavaType() { return attribute.getKeyJavaType(); }
public PluralAttributePath( CriteriaBuilderImpl criteriaBuilder, PathSource source, PluralAttribute<?,X,?> attribute) { super( criteriaBuilder, attribute.getJavaType(), source ); this.attribute = attribute; this.persister = resolvePersister( criteriaBuilder, attribute ); }
@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 ); }
CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Metamodel m = em.getMetamodel(); EntityType<Pet> Pet_ = m.entity(Pet.class); Root<Pet> pet = cq.from(Pet.class); Join<Pet, Owner> owner = pet.join(Pet_.owners);
private <K,V> void checkMapKeyType(MapAttribute<? super J, K, V> mapAttribute, String name, Class<K> keyType) { if ( mapAttribute.getKeyJavaType() != keyType ) { throw new IllegalArgumentException( "MapAttribute named " + name + " does not support a key of type " + keyType ); } }
@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 ); }
@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 ); }