public static boolean containsRelation(Object expr) { if (expr instanceof Join) { return true; } else if (expr instanceof SingularAttribute) { SingularAttribute<?, ?> attr = (SingularAttribute<?, ?>) expr; return attr.isAssociation(); } else if (expr instanceof Path) { Path<?> attrPath = (Path<?>) expr; Bindable<?> model = attrPath.getModel(); Path<?> parent = attrPath.getParentPath(); return containsRelation(parent) || containsRelation(model); } else { // we may can do better here... return false; } }
public static Type toType(Bindable bindable) { switch ( bindable.getBindableType() ) { case ENTITY_TYPE: { return (EntityType) bindable; } case SINGULAR_ATTRIBUTE: { return ( (SingularAttribute) bindable ).getType(); } case PLURAL_ATTRIBUTE: { return ( (PluralAttribute) bindable ).getElementType(); } default: { throw new ParsingException( "Unexpected Bindable type : " + bindable ); } } }
@SuppressWarnings("unchecked") public <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) { Path<?> path = root; for (Attribute<?, ?> attribute : attributes) { boolean found = false; if (path instanceof FetchParent) { for (Fetch<E, ?> fetch : ((FetchParent<?, E>) path).getFetches()) { if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) { path = (Join<E, ?>) fetch; found = true; break; } } } if (!found) { if ((attributes.indexOf(attribute) != (attributes.size() - 1)) && (attribute instanceof Bindable) && Identifiable.class.isAssignableFrom(((Bindable<?>) attribute).getBindableJavaType()) && (path instanceof From)) { path = ((From<?, ?>) path).join(attribute.getName(), JoinType.LEFT); } else { path = path.get(attribute.getName()); } } } return (Path<F>) path; }
@Test public void hibernatePluralPathTest() { CriteriaBuilder build = em.getCriteriaBuilder(); CriteriaQuery<OneToManyInstance> critQ = build.createQuery(OneToManyInstance.class); Root<OneToManyInstance> resultRoot = critQ.from(OneToManyInstance.class); Path pluralPath = resultRoot.get("many"); Bindable shouldBePluralAttribute = pluralPath.getModel(); assertNotNull(shouldBePluralAttribute); assertTrue(shouldBePluralAttribute instanceof PluralAttribute); }
private String getName(Bindable<?> bindable) { if (bindable.getBindableType() == BindableType.ENTITY_TYPE) { EntityType<?> entityType = (EntityType<?>)bindable; return entityType.getName(); } else { Attribute<?, ?> attribute = (Attribute<?, ?>)bindable; return attribute.getName(); } }
/** * Get the Breeze name of the entity type. For collections, Breeze expects the name of the * element type. * * @param propType * @return */ Class getEntityType(Attribute attr) { if (attr instanceof Bindable) { return ((Bindable)attr).getBindableJavaType(); } else { throw new RuntimeException("Not Bindable: " + attr); } }
static boolean isDistinctable(MetaJpaConstructor<?, ?, ?> projection, int columnIndex) { logger.debug("isDistinctable({},{})", projection, columnIndex); boolean ret = Bindable.class.isAssignableFrom(projection.getConstructorParameterTypes().get(columnIndex)) && !NotDistinctable.class.isAssignableFrom(((Bindable<?>)projection.getParameters().get(columnIndex)).getBindableJavaType()) || !Bindable.class.isAssignableFrom(projection.getConstructorParameterTypes().get(columnIndex)) && NotDistinctable.class.isAssignableFrom(projection.getParameters().get(columnIndex).getJavaType()); logger.debug("isDistinctable -> {}", ret); return ret; }
static Object collectEmbeddableFromParts(Metamodel metamodel, Bindable<?> attr, Iterable<Object> columns) { logger.debug("collectEmbeddableFromParts({},{},{})", new Object[] {metamodel, attr, columns}); List<Object> cols = newList(columns); List<? extends Attribute<?, ?>> embeddableAttributes = getEmbeddableAttributes(attr, metamodel); if (embeddableAttributes.size() != cols.size()) { throw new IllegalStateException("Expected same size for: " + embeddableAttributes + ", " + cols); } Class<?> embeddableClass = getEmbeddableType(attr, metamodel).getJavaType(); try { Object ret = instantiate(embeddableClass); for (Tuple2<? extends Attribute<?, ?>, Object> a: zip(embeddableAttributes, cols)) { Member member = a._1.getJavaMember(); if (member instanceof Field) { Field f = (Field)member; f.setAccessible(true); f.set(ret, a._2); } else { Method m = (Method)member; if (m.getParameterTypes().length == 1 && head(m.getParameterTypes()).isAssignableFrom(a._1.getJavaType())) { m.setAccessible(true); m.invoke(ret, a._2); } else { throw new UnsupportedOperationException("not implemented. Run, Forrest, run!"); } } } logger.debug("collectEmbeddableFromParts -> {}", ret); return ret; } catch (Exception e) { throw new RuntimeException(e); } }
public static <E, T> SingularAttribute<E, Option<T>> optionalSubtype(SingularAttribute<? extends E, T> attribute) throws IllegalArgumentException { if (attribute instanceof PseudoAttribute) { throw new IllegalArgumentException("No reason to wrap a PseudoAttribute. Right?"); } if (attribute instanceof Bindable && Option.class.isAssignableFrom(((Bindable<?>) attribute).getBindableJavaType())) { throw new IllegalArgumentException("No reason to wrap an Option<?> type. Right?"); } if (attribute instanceof AdditionalQueryPerformingAttribute) { List<Attribute<?,?>> parameters = ((AdditionalQueryPerformingAttribute) attribute).getConstructor().getParameters(); if (parameters.size() == 1 && Option.class.isAssignableFrom(head(parameters).getJavaType())) { throw new IllegalArgumentException("No reason to wrap an Option<?> type. Right?"); } } return OptionalAttribute.Constructors.optional(attribute); }
public static boolean isRequiredByQueryAttribute(Attribute<?,?> param) { if (param == null) { return true; } if (unwrap(PseudoAttribute.class, param).isDefined()) { return true; } if (param instanceof AdditionalQueryPerformingAttribute && ((AdditionalQueryPerformingAttribute) param).getConstructor() instanceof TransparentProjection) { return isRequiredByQueryAttribute(((TransparentProjection)((AdditionalQueryPerformingAttribute) param).getConstructor()).getWrapped()); } if (param instanceof JoiningAttribute && param instanceof SingularAttribute) { return forall(QueryUtils_.isRequiredByQueryAttribute, ((JoiningAttribute) param).getAttributes()); } else if (param instanceof JoiningAttribute) { return true; } if (unwrap(OptionalAttribute.class, param).isDefined()) { return false; } if (param instanceof Bindable && Option.class.isAssignableFrom(((Bindable<?>) param).getBindableJavaType())) { return false; } return true; }
/** * Modifies existing query! */ public <E, T1, A1 extends Attribute<? super E, ?> & Bindable<T1>> CriteriaQuery<E> innerJoin(A1 attribute, CriteriaQuery<E> query) { @SuppressWarnings("unchecked") From<?, E> from = (From<?, E>) resolveSelection(query); join(from, attribute, JoinType.INNER); return query; }
/** * Modifies existing query! */ public <E, T1, T2, T3, T4, T5, A1 extends Attribute<? super E, ?> & Bindable<T1>, A2 extends Attribute<? super T1, ?> & Bindable<T2>, A3 extends Attribute<? super T2, ?> & Bindable<T3>, A4 extends Attribute<? super T3, ?> & Bindable<T4>, A5 extends Attribute<? super T4, ?> & Bindable<T5>> CriteriaQuery<E> innerJoin(A1 attribute1, A2 attribute2, A3 attribute3, A4 attribute4, A5 attribute5, CriteriaQuery<E> query) { @SuppressWarnings("unchecked") From<?, E> from = (From<?, E>) resolveSelection(query); join(join(join(join(join(from, attribute1, JoinType.INNER), attribute2, JoinType.INNER), attribute3, JoinType.INNER), attribute4, JoinType.INNER), attribute5, JoinType.INNER); return query; }
/** * Modifies existing query! */ public <E, T1, T2, T3, T4, T5, T6, T7, A1 extends Attribute<? super E, ?> & Bindable<T1>, A2 extends Attribute<? super T1, ?> & Bindable<T2>, A3 extends Attribute<? super T2, ?> & Bindable<T3>, A4 extends Attribute<? super T3, ?> & Bindable<T4>, A5 extends Attribute<? super T4, ?> & Bindable<T5>, A6 extends Attribute<? super T5, ?> & Bindable<T6>, A7 extends Attribute<? super T6, ?> & Bindable<T7>> CriteriaQuery<E> innerJoin(A1 attribute1, A2 attribute2, A3 attribute3, A4 attribute4, A5 attribute5, A6 attribute6, A7 attribute7, CriteriaQuery<E> query) { @SuppressWarnings("unchecked") From<?, E> from = (From<?, E>) resolveSelection(query); join(join(join(join(join(join(join(from, attribute1, JoinType.INNER), attribute2, JoinType.INNER), attribute3, JoinType.INNER), attribute4, JoinType.INNER), attribute5, JoinType.INNER), attribute6, JoinType.INNER), attribute7, JoinType.INNER); return query; }
@Override public Bindable<X> getModel() { // TODO Auto-generated method stub return null; }
public static <E,Y,Y2,Y3,Y4,Y5,A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>, A5 extends Attribute<? super Y4,?> & Bindable<Y5>> SetAttribute<E,Y5> set(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { return new JoiningSetAttribute<E,Y5,SetAttribute<E,Y5>>(newList((Attribute<?,?>)a1, (Attribute<?,?>)a2, (Attribute<?,?>)a3, (Attribute<?,?>)a4, (Attribute<?,?>)a5)); }
public static <E,Y,R, A1 extends Attribute<E,?> & Bindable<Y>> CollectionAttribute<E, R> collection(A1 a1, CollectionAttribute<? super Y,R> a2) { return JoiningAttribute.Constructors.collection(a1, a2); }
public static <E,Y,Y2,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>> CollectionAttribute<E, R> collection(A1 a1, A2 a2, CollectionAttribute<? super Y2,R> a3) { return JoiningAttribute.Constructors.collection(a1, a2, a3); }
public static <E,Y,Y2,Y3,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>> CollectionAttribute<E, R> collection(A1 a1, A2 a2, A3 a3, CollectionAttribute<? super Y3,R> a4) { return JoiningAttribute.Constructors.collection(a1, a2, a3, a4); }
public static <E,Y,Y2,Y3,Y4,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>> CollectionAttribute<E, R> collection(A1 a1, A2 a2, A3 a3, A4 a4, CollectionAttribute<? super Y4,R> a5) { return JoiningAttribute.Constructors.collection(a1, a2, a3, a4, a5); }
public static <E,Y,Y2,Y3,A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>> ListAttribute<E,Y3> list(A1 a1, A2 a2, A3 a3) { return new JoiningListAttribute<E,Y3,ListAttribute<E,Y3>>(newList((Attribute<?,?>)a1, (Attribute<?,?>)a2, (Attribute<?,?>)a3)); }
public static <E,Y,Y2,Y3,Y4,Y5,Y6,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>, A5 extends Attribute<? super Y4,?> & Bindable<Y5>, A6 extends Attribute<? super Y5,?> & Bindable<Y6>> CollectionAttribute<E, R> collection(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, CollectionAttribute<? super Y6,R> a7) { return JoiningAttribute.Constructors.collection(a1, a2, a3, a4, a5, a6, a7); }
public static <E,Y,R, A extends Attribute<E,?> & Bindable<Y>> SetAttribute<E, R> set(A a1, SetAttribute<? super Y, R> a2) { return JoiningAttribute.Constructors.set(a1, a2); }
public static <E,Y,Y2,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>> SetAttribute<E, R> set(A1 a1, A2 a2, SetAttribute<? super Y2,R> a3) { return JoiningAttribute.Constructors.set(a1, a2, a3); }
public static <E,Y,Y2,Y3,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>> SetAttribute<E,R> set(A1 a1, A2 a2, A3 a3, SetAttribute<? super Y3,R> a4) { return JoiningAttribute.Constructors.set(a1, a2, a3, a4); }
public static <E,Y,Y2,Y3,Y4,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>> SetAttribute<E,R> set(A1 a1, A2 a2, A3 a3, A4 a4, SetAttribute<? super Y4,R> a5) { return JoiningAttribute.Constructors.set(a1, a2, a3, a4, a5); }
public static <E,Y,Y2,Y3,Y4,Y5,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>, A5 extends Attribute<? super Y4,?> & Bindable<Y5>> SetAttribute<E,R> set(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, SetAttribute<? super Y5,R> a6) { return JoiningAttribute.Constructors.set(a1, a2, a3, a4, a5, a6); }
public static <E,Y,Y2,Y3,Y4,Y5,Y6,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>, A5 extends Attribute<? super Y4,?> & Bindable<Y5>, A6 extends Attribute<? super Y5,?> & Bindable<Y6>> SetAttribute<E,R> set(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, SetAttribute<? super Y6,R> a7) { return JoiningAttribute.Constructors.set(a1, a2, a3, a4, a5, a6, a7); }
public static <E,Y,R, A extends Attribute<E,?> & Bindable<Y>> ListAttribute<E, R> list(A a1, ListAttribute<? super Y,R> a2) { return JoiningAttribute.Constructors.list(a1, a2); }
public <E extends Identifiable<?>, R1, R2, R3, A1 extends Attribute<? super E, ?> & Bindable<R1>, A2 extends Attribute<? super R1, ?> & Bindable<R2>, A3 extends Attribute<? super R2, ?> & Bindable<R3>> CriteriaQuery<R3> related(A1 r1, A2 r2, A3 r3, CriteriaQuery<E> query) { return doRelated(query, r1, r2, r3); }
public static <E,Y,Y2,Y3,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>> ListAttribute<E, R> list(A1 a1, A2 a2, A3 a3, ListAttribute<? super Y3,R> a4) { return JoiningAttribute.Constructors.list(a1, a2, a3, a4); }
public static <E,Y,Y2,Y3,Y4,Y5,A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>, A5 extends Attribute<? super Y4,?> & Bindable<Y5>> ListAttribute<E,Y5> list(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { return new JoiningListAttribute<E,Y5,ListAttribute<E,Y5>>(newList((Attribute<?,?>)a1, (Attribute<?,?>)a2, (Attribute<?,?>)a3, (Attribute<?,?>)a4, (Attribute<?,?>)a5)); }
public static <E,Y,Y2,Y3,Y4,Y5,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>, A5 extends Attribute<? super Y4,?> & Bindable<Y5>> ListAttribute<E, R> list(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, ListAttribute<? super Y5,R> a6) { return JoiningAttribute.Constructors.list(a1, a2, a3, a4, a5, a6); }
public static <E,Y,Y2,Y3,Y4,Y5,Y6,R, A1 extends Attribute<E,?> & Bindable<Y>, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>, A5 extends Attribute<? super Y4,?> & Bindable<Y5>, A6 extends Attribute<? super Y5,?> & Bindable<Y6>> ListAttribute<E, R> list(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, ListAttribute<? super Y6,R> a7) { return JoiningAttribute.Constructors.list(a1, a2, a3, a4, a5, a6, a7); }
public <E extends IEntity<?> & Identifiable<?>, R1, R2, R3, R4, R5, R6, R7, R8, A1 extends Attribute<? super E, ?> & Bindable<R1>, A2 extends Attribute<? super R1, ?> & Bindable<R2>, A3 extends Attribute<? super R2, ?> & Bindable<R3>, A4 extends Attribute<? super R3, ?> & Bindable<R4>, A5 extends Attribute<? super R4, ?> & Bindable<R5>, A6 extends Attribute<? super R5, ?> & Bindable<R6>, A7 extends Attribute<? super R6, ?> & Bindable<R7>, A8 extends Attribute<? super R7, ?> & Bindable<R8>> CriteriaQuery<R8> related(E entity, A1 r1, A2 r2, A3 r3, A4 r4, A5 r5, A6 r6, A7 r7, A8 r8) { return doRelated(entity, r1, r2, r3, r4, r5, r6, r7, r8); }
public static <E,Y,Y2,Y3, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>> CollectionAttribute<E, Y3> collection(CollectionAttribute<E, Y> a1, A2 a2, A3 a3) { return JoiningAttribute.Constructors.collection(a1, a2, a3); }
public static <E,Y,Y2,Y3,Y4, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>> CollectionAttribute<E, Y4> collection(CollectionAttribute<E, Y> a1, A2 a2, A3 a3, A4 a4) { return JoiningAttribute.Constructors.collection(a1, a2, a3, a4); }
public static <E,Y,Y2,Y3,Y4,Y5, A2 extends Attribute<? super Y,?> & Bindable<Y2>, A3 extends Attribute<? super Y2,?> & Bindable<Y3>, A4 extends Attribute<? super Y3,?> & Bindable<Y4>, A5 extends Attribute<? super Y4,?> & Bindable<Y5>> CollectionAttribute<E, Y5> collection(CollectionAttribute<E, Y> a1, A2 a2, A3 a3, A4 a4, A5 a5) { return JoiningAttribute.Constructors.collection(a1, a2, a3, a4, a5); }
public <E extends Identifiable<?>, R1, R2, R3, R4, R5, A1 extends Attribute<? super E, ?> & Bindable<R1>, A2 extends Attribute<? super R1, ?> & Bindable<R2>, A3 extends Attribute<? super R2, ?> & Bindable<R3>, A4 extends Attribute<? super R3, ?> & Bindable<R4>, A5 extends Attribute<? super R4, ?> & Bindable<R5>> CriteriaQuery<R5> related(A1 r1, A2 r2, A3 r3, A4 r4, A5 r5, CriteriaQuery<E> query) { return doRelated(query, r1, r2, r3, r4, r5); }