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(); } } }
if (attribute.getPersistentAttributeType().equals(PersistentAttributeType.EMBEDDED)) {
/** * 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()); }
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 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(); // return criteriaBuilder.getEntityManagerFactory() // .getMetamodel() // .managedType( javaType ); } }
@SuppressWarnings({"unchecked"}) public SingularAttributeJoin(BlazeCriteriaBuilderImpl criteriaBuilder, Class<X> javaType, AbstractPath<Z> pathSource, SingularAttribute<? super Z, ?> joinAttribute, JoinType joinType) { super(criteriaBuilder, javaType, pathSource, joinAttribute, joinType); this.model = (Bindable<X>) (Attribute.PersistentAttributeType.EMBEDDED == joinAttribute .getPersistentAttributeType() ? joinAttribute : criteriaBuilder.getEntityMetamodel().managedType(javaType)); }
@SuppressWarnings({"unchecked"}) public SingularAttributeJoin(BlazeCriteriaBuilderImpl criteriaBuilder, Class<X> javaType, AbstractPath<Z> pathSource, SingularAttribute<? super Z, ?> joinAttribute, JoinType joinType) { super(criteriaBuilder, javaType, pathSource, joinAttribute, joinType); this.model = (Bindable<X>) (Attribute.PersistentAttributeType.EMBEDDED == joinAttribute .getPersistentAttributeType() ? joinAttribute : criteriaBuilder.getEntityMetamodel().managedType(javaType)); }
public SingularAttributePath( AbstractPath<?> parentPath, SingularAttribute<?, X> attribute) { super(Arguments.mustNotBeNull("parentPath", parentPath).getCriteriaBuilder(), parentPath); this.attribute = attribute; if ( Attribute.PersistentAttributeType.BASIC != attribute.getPersistentAttributeType() ) { if ( Attribute.PersistentAttributeType.EMBEDDED == attribute.getPersistentAttributeType() ) { this.managedType = (EmbeddableType<X>)attribute.getType(); } else { this.managedType = (IdentifiableType<X>)attribute.getType(); } } }
public <T> List<Predicate> byExample(ManagedType<T> mt, Path<T> mtPath, T mtValue, SearchParameters sp, CriteriaBuilder builder) { List<Predicate> predicates = newArrayList(); for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) { if (attr.getPersistentAttributeType() == MANY_TO_ONE // || attr.getPersistentAttributeType() == ONE_TO_ONE // || attr.getPersistentAttributeType() == EMBEDDED) { continue; } Object attrValue = jpaUtil.getValue(mtValue, attr); if (attrValue != null) { if (attr.getJavaType() == String.class) { if (isNotEmpty((String) attrValue)) { predicates.add(jpaUtil.stringPredicate(mtPath.get(jpaUtil.stringAttribute(mt, attr)), attrValue, sp, builder)); } } else { predicates.add(builder.equal(mtPath.get(jpaUtil.attribute(mt, attr)), attrValue)); } } } return predicates; }
@SuppressWarnings({ "unchecked" }) public SingularAttributeJoin( CriteriaBuilderImpl criteriaBuilder, Class<X> javaType, PathSource<Z> pathSource, SingularAttribute<? super Z, ?> joinAttribute, JoinType joinType) { super( criteriaBuilder, javaType, pathSource, joinAttribute, joinType ); this.model = (Bindable<X>) ( Attribute.PersistentAttributeType.EMBEDDED == joinAttribute.getPersistentAttributeType() ? joinAttribute : criteriaBuilder.getEntityManagerFactory().getMetamodel().managedType( javaType ) ); }
@SuppressWarnings("unchecked") public <T> Predicate byPattern(Root<T> root, CriteriaBuilder builder, SearchParameters sp, Class<T> type) { if (!sp.hasSearchPattern()) { return null; } List<Predicate> predicates = newArrayList(); EntityType<T> entity = em.getMetamodel().entity(type); String pattern = sp.getSearchPattern(); for (SingularAttribute<? super T, ?> attr : entity.getSingularAttributes()) { if (attr.getPersistentAttributeType() == MANY_TO_ONE || attr.getPersistentAttributeType() == ONE_TO_ONE) { continue; } if (attr.getJavaType() == String.class) { predicates.add(jpaUtil.stringPredicate((Expression<String>) root.get(jpaUtil.attribute(entity, attr)), pattern, sp, builder)); } } return jpaUtil.orPredicate(builder, predicates); } }
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); }
private static boolean isLeftOrNonNullReferenceJoin(Join<?, ?> join, boolean dbSchemaStrict) { if (join.getAttribute().isCollection()) { return false; } if (join.getJoinType() == JoinType.LEFT) { return true; } if (!dbSchemaStrict) { return false; } SingularAttribute<?, ?> singularAttribute = (SingularAttribute<?, ?>)join.getAttribute(); return !singularAttribute.isOptional() && singularAttribute.getPersistentAttributeType() == PersistentAttributeType.MANY_TO_ONE; } }
@SuppressWarnings("unchecked") protected Bindable<X> onGetModel() { SingularAttribute<? super Z, ?> attribute = this.getAttribute(); if (Attribute.PersistentAttributeType.EMBEDDED == attribute.getPersistentAttributeType()) { return (Bindable<X>)attribute; } return (Bindable<X>)this.getCriteriaBuilder().getEntityManagerFactory().getMetamodel().managedType(this.getJavaType()); }
/** * {@inheritDoc} * */ @Override @SuppressWarnings("unchecked") public final <Y> AbstractPath<Y> get(SingularAttribute<? super X, Y> attribute) { final AbstractMapping<? super X, Y, Y> mapping = this.getMapping(attribute.getName()); switch (attribute.getPersistentAttributeType()) { case EMBEDDED: return new EmbeddedAttributePath<X, Y>(this, (EmbeddedMappingImpl<? super X, Y>) mapping); case BASIC: return new BasicPath<Y>(this, (BasicMappingImpl<? super X, Y>) mapping); default: return new EntityPath<X, Y>(this, (SingularAssociationMappingImpl<Z, X>) mapping, (EntityTypeImpl<Y>) attribute.getType()); } }
/** * {@inheritDoc} * */ @Override @SuppressWarnings("unchecked") public final <Y> AbstractPath<Y> get(SingularAttribute<? super X, Y> attribute) { final AbstractMapping<? super X, Y, Y> mapping = this.getMapping(attribute.getName()); switch (attribute.getPersistentAttributeType()) { case EMBEDDED: return new EmbeddedAttributePath<X, Y>(this, (EmbeddedMappingImpl<? super X, Y>) mapping); case BASIC: return new BasicPath<Y>(this, (BasicMappingImpl<? super X, Y>) mapping); default: return new EntityPath<X, Y>(this, (SingularAssociationMappingImpl<Z, X>) mapping, (EntityTypeImpl<Y>) attribute.getType()); } }
/** * Return the path corresponding to the referenced non-collection valued * attribute. * * @param model * attribute * @return path corresponding to the referenced attribute */ public <Y> Path<Y> get(SingularAttribute<? super X, Y> att){ if (att.getPersistentAttributeType().equals(PersistentAttributeType.BASIC)){ return new PathImpl<Y>(this, this.metamodel, att.getBindableJavaType(),this.currentNode.get(att.getName()), att); }else{ Class<Y> clazz = att.getBindableJavaType(); Join join = new JoinImpl<X, Y>(this, this.metamodel.managedType(clazz), this.metamodel, clazz,this.currentNode.get(att.getName()), att); this.joins.add(join); return join; } }