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(); } }
@SuppressWarnings({ "unchecked" }) public SingularAttributeJoin( CriteriaBuilderImpl criteriaBuilder, Class<X> javaType, PathSource<O> pathSource, SingularAttribute<? super O, ?> joinAttribute, JoinType joinType) { super( criteriaBuilder, javaType, pathSource, joinAttribute, joinType ); if ( Attribute.PersistentAttributeType.EMBEDDED == joinAttribute.getPersistentAttributeType() ) { this.model = (Bindable<X>) joinAttribute; } else { if ( javaType != null ) { this.model = (Bindable<X>) criteriaBuilder.getEntityManagerFactory().getMetamodel().managedType( javaType ); } else { this.model = (Bindable<X>) joinAttribute.getType(); } } }
private <Y> JoinImplementor<X, Y> constructJoin(SingularAttribute<? super X, Y> attribute, JoinType jt) { if ( Type.PersistenceType.BASIC.equals( attribute.getType().getPersistenceType() ) ) { throw new BasicPathUsageException( "Cannot join to attribute of basic type", attribute ); } // TODO : runtime check that the attribute in fact belongs to this From's model/bindable if ( jt.equals( JoinType.RIGHT ) ) { throw new UnsupportedOperationException( "RIGHT JOIN not supported" ); } final Class<Y> attributeType = attribute.getBindableJavaType(); return new SingularAttributeJoin<X, Y>( criteriaBuilder(), attributeType, this, attribute, jt ); }
@Override @SuppressWarnings("unchecked") protected ManagedType<? super X> locateManagedType() { if ( getModel().getBindableType() == Bindable.BindableType.ENTITY_TYPE ) { return (ManagedType<? super X>) getModel(); } else if ( getModel().getBindableType() == Bindable.BindableType.SINGULAR_ATTRIBUTE ) { final Type joinedAttributeType = ( (SingularAttribute) getAttribute() ).getType(); if ( !ManagedType.class.isInstance( joinedAttributeType ) ) { throw new UnsupportedOperationException( "Cannot further dereference attribute join [" + getPathIdentifier() + "] as its type is not a ManagedType" ); } return (ManagedType<? super X>) joinedAttributeType; } else if ( getModel().getBindableType() == Bindable.BindableType.PLURAL_ATTRIBUTE ) { final Type elementType = ( (PluralAttribute) getAttribute() ).getElementType(); if ( !ManagedType.class.isInstance( elementType ) ) { throw new UnsupportedOperationException( "Cannot further dereference attribute join [" + getPathIdentifier() + "] (plural) as its element type is not a ManagedType" ); } return (ManagedType<? super X>) elementType; } return super.locateManagedType(); }
@Test @TestForIssue(jiraKey = "HHH-12124") public void testEmbeddableEquality() { doInJPA( this::entityManagerFactory, entityManager -> { assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Company_.address.getType() ) ); assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Person_.address.getType() ) ); } ); } }
@Override public Type<?> getIdType() { if (idAttribute != null && !isIdClass) { return idAttribute.getType(); } return getSupertype().getIdType(); }
/** * Assert on embeddable. * * @param embeddableAttrib * the embeddable attrib * @param clazz * the clazz */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void assertOnEmbeddable(SingularAttribute embeddableAttrib, Class clazz) { Assert.assertNotNull(embeddableAttrib); Assert.assertEquals(PersistentAttributeType.EMBEDDED, embeddableAttrib.getPersistentAttributeType()); Assert.assertEquals(PersistenceType.EMBEDDABLE, embeddableAttrib.getType().getPersistenceType()); Assert.assertEquals(clazz, embeddableAttrib.getType().getJavaType()); }
/** * Assert on embeddable. * * @param embeddableAttrib * the embeddable attrib * @param clazz * the clazz */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void assertOnEmbeddable(SingularAttribute embeddableAttrib, Class clazz) { Assert.assertNotNull(embeddableAttrib); Assert.assertEquals(PersistentAttributeType.EMBEDDED, embeddableAttrib.getPersistentAttributeType()); Assert.assertEquals(PersistenceType.EMBEDDABLE, embeddableAttrib.getType().getPersistenceType()); Assert.assertEquals(clazz, embeddableAttrib.getType().getJavaType()); } }
EmbeddableType<X> embeddableType = (EmbeddableType<X>) embeddableAttrib.getType(); Attribute<X, String> attribute = (Attribute<X, String>) embeddableType.getAttribute("embeddedField"); assertOnEmbeddableType(EmbeddableTransientEntity.class, attribute, embeddableType, "embeddedField",
EmbeddableType<X> embeddableType = (EmbeddableType<X>) embeddableAttrib.getType(); Attribute<X, String> attribute = (Attribute<X, String>) embeddableType.getAttribute("engineId"); assertOnEmbeddableType(CarEngine.class, attribute, embeddableType, "engineId", String.class);
EmbeddableType<X> embeddableType = (EmbeddableType<X>) embeddableAttrib.getType(); Attribute<X, String> attribute = (Attribute<X, String>) embeddableType.getAttribute("embeddedField"); assertOnEmbeddableType(EmbeddableEntity.class, attribute, embeddableType, "embeddedField", String.class); EmbeddableType<X> embeddableTypeTwo = (EmbeddableType<X>) embeddableAttribTwo.getType(); assertOnEmbeddable(embeddableAttribTwo, EmbeddableEntityTwo.class); assertOnEmbeddableType(EmbeddableEntityTwo.class, attribute, embeddableTypeTwo, "embeddedField",
@Override public Type<?> getIdType() { return id.getType(); }
Assert.assertEquals(OToOOwnerBiEntity.class, ownerAttribute.getJavaType()); Assert.assertEquals(managedTypes.get(OToOOwnerBiEntity.class), ((SingularAttribute<? super X, ?>) ownerAttribute).getType());
private ManagedType<X> getManagedType(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(); } }
private ManagedType<X> getManagedType(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(); } }
private <Y> AbstractJoin<X, Y> constructJoin(SingularAttribute<? super X, Y> attribute, String alias, JoinType jt) { if (Type.PersistenceType.BASIC.equals(attribute.getType().getPersistenceType())) { throw new IllegalArgumentException("Cannot join to attribute of basic type: " + attribute.getJavaType().getName()); } checkJoin(attribute, jt); final Class<Y> attributeType = attribute.getBindableJavaType(); SingularAttributeJoin<X, Y> join = new SingularAttributeJoin<X, Y>(criteriaBuilder, attributeType, this, attribute, jt); join.setAlias(alias); return join; }
private <Y> AbstractJoin<X, Y> constructJoin(SingularAttribute<? super X, Y> attribute, String alias, JoinType jt) { if (Type.PersistenceType.BASIC.equals(attribute.getType().getPersistenceType())) { throw new IllegalArgumentException("Cannot join to attribute of basic type: " + attribute.getJavaType().getName()); } checkJoin(attribute, jt); final Class<Y> attributeType = attribute.getBindableJavaType(); SingularAttributeJoin<X, Y> join = new SingularAttributeJoin<X, Y>(criteriaBuilder, attributeType, this, attribute, jt); join.setAlias(alias); return join; }
static OEntityKey toOEntityKey(Object jpaEntity, SingularAttribute<?, ?> idAtt) { boolean hasEmbeddedCompositeKey = idAtt.getPersistentAttributeType() == PersistentAttributeType.EMBEDDED; if (!hasEmbeddedCompositeKey) { Object id = SetResponseCommand.getIdValue(jpaEntity, idAtt, null); return OEntityKey.create(id); } ManagedType<?> keyType = (ManagedType<?>) idAtt.getType(); Map<String, Object> nameValues = new HashMap<String, Object>(); for (Attribute<?, ?> att : keyType.getAttributes()) nameValues.put(att.getName(), SetResponseCommand.getIdValue(jpaEntity, idAtt, att.getName())); return OEntityKey.create(nameValues); }