/** * Checks if is bindable. * * @param <E> * the element type * @param attribute * the attribute * @param elementType * the element type * @return true, if is bindable */ private <E> boolean isBindable(Bindable<?> attribute, Class<E> elementType) { return attribute != null && attribute.getBindableJavaType().equals(elementType); }
@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(); }
Assert.assertEquals(PersistentAttributeType.ONE_TO_MANY, associationAttribute.getPersistentAttributeType()); Assert.assertEquals(Collection.class, associationAttribute.getJavaType()); Assert.assertEquals(AssociationEntity.class, ((Bindable) associationAttribute).getBindableJavaType()); Assert.assertEquals(true, associationAttribute.isAssociation()); Assert.assertEquals(OToMOwnerEntity.class, associationAttribute.getDeclaringType().getJavaType());
if ( getPathSource().getModel().getBindableType() == Bindable.BindableType.ENTITY_TYPE ) { "Unexpected BindableType; expected [%s]; instead got [%s]", Bindable.BindableType.ENTITY_TYPE, getPathSource().getModel().getBindableType()
private static Object getValueForPath(Path path, String value) { if (value == null) return null; Class c = path.getModel().getBindableJavaType(); try { if (c.equals(Date.class)) return Date.from(ZonedDateTime.parse(value).toInstant()); if (c.equals(Instant.class)) return ZonedDateTime.parse(value).toInstant(); if (c.equals(Boolean.class)) return Boolean.parseBoolean(value); if (c.isEnum()) return Enum.valueOf(c, value); if (c.equals(UUID.class)) return UUID.fromString(value); } catch (IllegalArgumentException | DateTimeParseException e) { throw new InvalidFieldValueException(e.getMessage(), path.getAlias(), value); } return value; }
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 ); } } } };
private Set<String> computeEntityMapping(Class<?> type, String basePath, Set<Class<?>> nestedTypes, java.util.function.Predicate<Attribute<?, ?>> attributePredicate) { Set<String> entityMapping = new HashSet<>(2); EntityType<?> entity = getEntityManager().getMetamodel().entity(type); for (Attribute<?, ?> attribute : entity.getAttributes()) { if (attributePredicate.test(attribute)) { entityMapping.add(basePath + attribute.getName()); } if (attribute instanceof Bindable) { Class<?> nestedType = ((Bindable<?>) attribute).getBindableJavaType(); if (BaseEntity.class.isAssignableFrom(nestedType) && nestedType != entityType && nestedTypes.add(nestedType)) { entityMapping.addAll(computeEntityMapping(nestedType, basePath + attribute.getName() + '.', nestedTypes, attributePredicate)); } } } return unmodifiableSet(entityMapping); }
@Override @SuppressWarnings({"unchecked"}) protected ManagedType<? super X> getManagedType() { Bindable<X> m = getModel(); Bindable.BindableType t = m.getBindableType(); switch (t) { case ENTITY_TYPE: return (ManagedType<? super X>) m; case SINGULAR_ATTRIBUTE: final Type<?> joinedAttributeType = ((SingularAttribute<?, ?>) getAttribute()).getType(); if (!(joinedAttributeType instanceof ManagedType<?>)) { throw new IllegalArgumentException("Joins on '" + getPathExpression() + "' are not allowed"); } return (ManagedType<? super X>) joinedAttributeType; case PLURAL_ATTRIBUTE: final Type<?> elementType = ((PluralAttribute<?, ?, ?>) getAttribute()).getElementType(); if (!(elementType instanceof ManagedType<?>)) { throw new IllegalArgumentException("Joins on '" + getPathExpression() + "' are not allowed"); } return (ManagedType<? super X>) elementType; default: break; } return super.getManagedType(); }
if (depth == 1 && isTransient(path.getModel().getBindableJavaType(), attribute)) { path = guessManyOrOneToOnePath(attribute);
@Override @SuppressWarnings({"unchecked"}) protected ManagedType<? super X> getManagedType() { Bindable<X> m = getModel(); Bindable.BindableType t = m.getBindableType(); switch (t) { case ENTITY_TYPE: return (ManagedType<? super X>) m; case SINGULAR_ATTRIBUTE: final Type<?> joinedAttributeType = ((SingularAttribute<?, ?>) getAttribute()).getType(); if (!(joinedAttributeType instanceof ManagedType<?>)) { throw new IllegalArgumentException("Joins on '" + getPathExpression() + "' are not allowed"); } return (ManagedType<? super X>) joinedAttributeType; case PLURAL_ATTRIBUTE: final Type<?> elementType = ((PluralAttribute<?, ?, ?>) getAttribute()).getElementType(); if (!(elementType instanceof ManagedType<?>)) { throw new IllegalArgumentException("Joins on '" + getPathExpression() + "' are not allowed"); } return (ManagedType<? super X>) elementType; default: break; } return super.getManagedType(); }
public <E> Predicate byExampleOnEmbeddable(Path<E> embeddablePath, E embeddableValue, SearchParameters sp, CriteriaBuilder builder) { if (embeddableValue == null) { return null; } Class<E> type = embeddablePath.getModel().getBindableJavaType(); ManagedType<E> mt = em.getMetamodel().embeddable(type); // note: calling .managedType() does not work return jpaUtil.orPredicate(builder, byExample(mt, embeddablePath, embeddableValue, sp, builder)); }
public <E> Predicate byExampleOnEmbeddable(Path<E> embeddablePath, E embeddableValue, SearchParameters sp, CriteriaBuilder builder) { if (embeddableValue == null) { return null; } Class<E> type = embeddablePath.getModel().getBindableJavaType(); ManagedType<E> mt = em.getMetamodel().embeddable(type); // note: calling .managedType() does not work return jpaUtil.andPredicate(builder, byExample(mt, embeddablePath, embeddableValue, sp, builder)); }
public <E> Predicate byExampleOnEmbeddable(Path<E> embeddablePath, E embeddableValue, SearchParameters sp, CriteriaBuilder builder) { if (embeddableValue == null) { return null; } Class<E> type = embeddablePath.getModel().getBindableJavaType(); ManagedType<E> mt = em.getMetamodel().embeddable(type); // note: calling .managedType() does not work return jpaUtil.andPredicate(builder, byExample(mt, embeddablePath, embeddableValue, sp, builder)); }
public <E> Predicate byExampleOnEmbeddable(Path<E> embeddablePath, E embeddableValue, SearchParameters sp, CriteriaBuilder builder) { if (embeddableValue == null) { return null; } Class<E> type = embeddablePath.getModel().getBindableJavaType(); ManagedType<E> mt = em.getMetamodel().embeddable(type); // note: calling .managedType() does not work return jpaUtil.orPredicate(builder, byExample(mt, embeddablePath, embeddableValue, sp, builder)); }
/** * Correlates a join object of the enclosing query to a join object of the * subquery and returns the subquery join object. * * @param parentJoin * join target of the containing query * @return subquery join */ public <X, Y> Join<X, Y> correlate(Join<X, Y> parentJoin){ this.correlatedJoins.add(parentJoin); JoinImpl join = new JoinImpl(parentJoin.getParentPath(), metamodel.managedType(parentJoin.getModel().getBindableJavaType()), metamodel, parentJoin.getJavaType(), internalCorrelate((FromImpl) parentJoin), parentJoin.getModel(), parentJoin.getJoinType(), (FromImpl) parentJoin); return join; } /**
/** * {@inheritDoc} * */ @Override public Expression<Class<? extends X>> type() { if ((this.entity != null) && (this.entity.getRootType().getInheritanceType() != null)) { return new EntityTypeExpression<X>(this, this.entity.getRootType().getDiscriminatorColumn()); } if (this.entity != null) { return new StaticTypeExpression<X>(this, this.entity.getJavaType()); } return new StaticTypeExpression<X>(this, this.getModel().getBindableJavaType()); } }
/** * {@inheritDoc} * */ @Override public Expression<Class<? extends X>> type() { if ((this.entity != null) && (this.entity.getRootType().getInheritanceType() != null)) { return new EntityTypeExpression<X>(this, this.entity.getRootType().getDiscriminatorColumn()); } if (this.entity != null) { return new StaticTypeExpression<X>(this, this.entity.getJavaType()); } return new StaticTypeExpression<X>(this, this.getModel().getBindableJavaType()); } }
/** * @param parent * the parent mapping * @param attribute * the attribute * @param javaType * the java type * @param name * the name of the mapping * * @since 2.0.0 */ @SuppressWarnings("unchecked") public AbstractMapping(AbstractParentMapping<?, Z> parent, AttributeImpl<? super Z, X> attribute, Class<X> javaType, String name) { super(); this.javaType = attribute instanceof Bindable ? ((Bindable<X>) attribute).getBindableJavaType() : javaType; this.parent = parent; this.attribute = attribute; this.name = name; this.metamodel = attribute != null ? attribute.getMetamodel() : null; this.path = (parent != null) && (parent.getPath() != null) ? parent.getPath() + "." + name : name; this.root = parent instanceof RootMapping; this.entity = (EntityTypeImpl<?>) (this.getRoot().isEntity() ? this.getRoot().getType() : null); this.inherited = (this.entity != null) && (this.entity.getRootType() != this.entity); }
/** * @param parent * the parent mapping * @param attribute * the attribute * @param javaType * the java type * @param name * the name of the mapping * * @since 2.0.0 */ @SuppressWarnings("unchecked") public AbstractMapping(AbstractParentMapping<?, Z> parent, AttributeImpl<? super Z, X> attribute, Class<X> javaType, String name) { super(); this.javaType = attribute instanceof Bindable ? ((Bindable<X>) attribute).getBindableJavaType() : javaType; this.parent = parent; this.attribute = attribute; this.name = name; this.metamodel = attribute != null ? attribute.getMetamodel() : null; this.path = (parent != null) && (parent.getPath() != null) ? parent.getPath() + "." + name : name; this.root = parent instanceof RootMapping; this.entity = (EntityTypeImpl<?>) (this.getRoot().isEntity() ? this.getRoot().getType() : null); this.inherited = (this.entity != null) && (this.entity.getRootType() != this.entity); }
return this.getMetamodel().getType(((Bindable)anAttribute).getBindableJavaType()); // all Attributes are Bindable