public MapKeyAttribute(CriteriaBuilderImpl criteriaBuilder, MapAttribute<?, K, ?> attribute) { this.attribute = attribute; this.jpaType = attribute.getKeyType(); this.jpaBinableJavaType = attribute.getKeyJavaType(); this.jpaBindableType = Type.PersistenceType .ENTITY.equals( jpaType.getPersistenceType() ) ? BindableType.ENTITY_TYPE : BindableType.SINGULAR_ATTRIBUTE; String guessedRoleName = determineRole( attribute ); SessionFactoryImplementor sfi = criteriaBuilder.getEntityManagerFactory().getSessionFactory(); mapPersister = sfi.getCollectionPersister( guessedRoleName ); if ( mapPersister == null ) { throw new IllegalStateException( "Could not locate collection persister [" + guessedRoleName + "]" ); } mapKeyType = mapPersister.getIndexType(); if ( mapKeyType == null ) { throw new IllegalStateException( "Could not determine map-key type [" + guessedRoleName + "]" ); } this.persistentAttributeType = mapKeyType.isEntityType() ? PersistentAttributeType.MANY_TO_ONE : mapKeyType.isComponentType() ? PersistentAttributeType.EMBEDDED : PersistentAttributeType.BASIC; }
@Override @SuppressWarnings({ "unchecked" }) public <K, V, M extends Map<K, V>> Expression<M> get(MapAttribute<X, K, V> attribute) { if ( ! canBeDereferenced() ) { throw illegalDereference(); } PluralAttributePath path = (PluralAttributePath) resolveCachedAttributePath( attribute.getName() ); if ( path == null ) { path = new PluralAttributePath( criteriaBuilder(), this, attribute ); registerAttributePath( attribute.getName(), path ); } return path; }
@Override @SuppressWarnings({ "unchecked" }) public Path<K> key() { final MapKeyHelpers.MapKeySource<K,V> mapKeySource = new MapKeyHelpers.MapKeySource<K,V>( criteriaBuilder(), getAttribute().getJavaType(), this, getAttribute() ); final MapKeyHelpers.MapKeyAttribute mapKeyAttribute = new MapKeyHelpers.MapKeyAttribute( criteriaBuilder(), getAttribute() ); return new MapKeyHelpers.MapKeyPath( criteriaBuilder(), mapKeySource, mapKeyAttribute ); }
private String determineRole(MapAttribute<?,K,?> attribute) { return attribute.getDeclaringType().getJavaType().getName() + '.' + attribute.getName(); }
@Override public Class<K> getJavaType() { return attribute.getKeyJavaType(); }
/** * Gets a new path that represents the given map-valued attribute from this path. */ public <K, V, M extends java.util.Map<K, V>> Expression<M> get(MapAttribute<X, K, V> map) { if (getType() != map.getDeclaringType()) { map = (MapAttribute)((ManagedType)getType()).getAttribute(map.getName()); } return new PathImpl<X,M>(this, (Members.MapAttributeImpl<? super X,K,V>)map, (Class<M>)map.getJavaType()); }
@Override public Type<Y> getType() { return attribute.getKeyType(); }
public boolean selects(Attribute<? super X, ?> attr) { boolean result = (attr instanceof MapAttribute<?, ?, ?>) && (_keyType == null || ((MapAttribute<?, ?, ?>) attr).getKeyType().getJavaType() == _keyType) && (_valueType == null || ((MapAttribute<?, ?, ?>) attr).getElementType().getJavaType() == _valueType); return _invert ? !result : result; }
Assert.assertEquals(mapSetId.getName(), fieldName); Assert.assertEquals(Map.class, mapSetId.getJavaType()); Assert.assertEquals(mapDeclaredId.getName(), fieldName); Assert.assertEquals(Map.class, mapDeclaredId.getJavaType());
if (p instanceof MapAttribute) { MapAttribute<?,?,?> map = (MapAttribute<?,?,?>) p; Type keyType = typeFactory.get(map.getKeyJavaType()); Type valueType = typeFactory.get(map.getElementType().getJavaType()); valueType = getPropertyType(p, valueType); propertyType = new SimpleType(propertyType,
public <K, V> MapJoin<X, K, V> join(MapAttribute<? super X, K, V> map, JoinType jt) { org.eclipse.persistence.expressions.Expression node; Class clazz = map.getBindableJavaType(); MapJoin<X, K, V> join = null; if (jt.equals(JoinType.INNER)) { node = this.currentNode.anyOf(map.getName()); } else if (jt.equals(JoinType.RIGHT)) { throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); } else { node = this.currentNode.anyOfAllowingNone(map.getName()); } if (map.getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { join = new BasicMapJoinImpl(this, this.metamodel, clazz, node, (Bindable) map, jt); } else { join = new MapJoinImpl(this, metamodel.managedType(clazz), this.metamodel, clazz, node, (Bindable) map, jt); } this.joins.add(join); ((FromImpl)join).isJoin = true; return join; }
/** * Gets name of the attribute type. For collection and map type attribute, the name is * appended with generic type argument names. * @param attr */ public static String getAttributeTypeName(Attribute<?, ?> attr) { StringBuilder name = new StringBuilder(attr.getJavaType().getSimpleName()); switch (attr.getPersistentAttributeType()) { case ONE_TO_MANY: case ELEMENT_COLLECTION: name.append("<") .append(((PluralAttribute<?,?,?>)attr).getBindableJavaType().getSimpleName()) .append(">"); break; case MANY_TO_MANY: name.append("<") .append(((MapAttribute<?,?,?>)attr).getKeyJavaType().getSimpleName()) .append(',') .append(((MapAttribute<?,?,?>)attr).getBindableJavaType().getSimpleName()) .append(">"); break; default: } return name.toString(); }
public static Class<?> resolveKeyClass(Class<?> baseClass, MapAttribute<?, ?, ?> attr) { Class<?> resolverBaseClass = baseClass == null ? null : getConcreterClass(baseClass, attr.getDeclaringType().getJavaType()); Class<?> jpaReportedFieldClass; Class<?> fieldClass; fieldClass = attr.getKeyType().getJavaType(); jpaReportedFieldClass = fieldClass; if (attr.getJavaMember() instanceof Method) { Method method = (Method) attr.getJavaMember(); Class<?>[] typeArguments = ReflectionUtils.getResolvedMethodReturnTypeArguments(resolverBaseClass, method); Field field = (Field) attr.getJavaMember(); Class<?>[] typeArguments = ReflectionUtils.getResolvedFieldTypeArguments(resolverBaseClass, field);
@Test @TestForIssue(jiraKey = "HHH-11111") public void testEmbeddableCanBeResolvedWhenUsedAsInterface() { doInJPA( this::entityManagerFactory, entityManager -> { assertNotNull( entityManager.getMetamodel().embeddable( LocalizedValue.class ) ); assertEquals( LocalizedValue.class, ProductEntity_.description.getElementType().getJavaType() ); assertNotNull( LocalizedValue_.value ); } ); }
private <K, V> MapJoinImplementor<X, K, V> constructJoin(MapAttribute<? super X, K, V> map, JoinType jt) { if ( jt.equals( JoinType.RIGHT ) ) { throw new UnsupportedOperationException( "RIGHT JOIN not supported" ); } // TODO : runtime check that the attribute in fact belongs to this From's model/bindable final Class<V> attributeType = map.getBindableJavaType(); return new MapAttributeJoin<X, K, V>( criteriaBuilder(), attributeType, this, map, jt ); }
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 ); } }
/** * Gets a new path that represents the given map-valued attribute from this path. */ public <K, V, M extends java.util.Map<K, V>> Expression<M> get(MapAttribute<X, K, V> map) { if (getType() != map.getDeclaringType()) { map = (MapAttribute)((ManagedType)getType()).getAttribute(map.getName()); } return new PathImpl<X,M>(this, (Members.MapAttributeImpl<? super X,K,V>)map, (Class<M>)map.getJavaType()); }
@Override public Type<Y> getType() { return attribute.getKeyType(); }
public boolean selects(Attribute<? super X, ?> attr) { boolean result = (attr instanceof MapAttribute<?, ?, ?>) && (_keyType == null || ((MapAttribute<?, ?, ?>) attr).getKeyType().getJavaType() == _keyType) && (_valueType == null || ((MapAttribute<?, ?, ?>) attr).getElementType().getJavaType() == _valueType); return _invert ? !result : result; }
if (p instanceof MapAttribute) { MapAttribute<?,?,?> map = (MapAttribute<?,?,?>)p; Type keyType = typeFactory.get(map.getKeyJavaType()); Type valueType = typeFactory.get(map.getElementType().getJavaType()); valueType = getPropertyType(p, valueType); propertyType = new SimpleType(propertyType,