@Override public <T> Path<T> createEntityPath(Class<T> type, PathMetadata<?> metadata) { if (Comparable.class.isAssignableFrom(type)) { return new ComparableEntityPath(type, metadata); } else { return new EntityPathBase<T>(type, metadata); } }
/** * Get a PArray instance for the given property and the given array type * * @param <A> * @param <E> * @param property property name * @param type * @return */ public <A, E> ArrayPath<A, E> getArray(String property, Class<A> type) { validate(property, Array.newInstance(type, 0).getClass()); return super.createArray(property, type); }
/** * Get a new Boolean typed path * * @param propertyName property name * @return */ public BooleanPath getBoolean(String propertyName) { validate(propertyName, Boolean.class); return super.createBoolean(propertyName); }
/** * Get a new List typed path * * @param <A> * @param property property name * @param type * @return */ public <A> ListPath<A, PathBuilder<A>> getList(String property, Class<A> type) { validate(property, List.class); return super.<A, PathBuilder<A>>createList(property, type, PathBuilder.class, PathInits.DIRECT); }
/** * Get a new Collection typed path * * @param <A> * @param property property name * @param type * @return */ public <A> CollectionPath<A, PathBuilder<A>> getCollection(String property, Class<A> type) { validate(property, Collection.class); return super.<A, PathBuilder<A>>createCollection(property, type, PathBuilder.class, PathInits.DIRECT); }
/** * Get a new Map typed path * * @param <K> * @param <V> * @param property property name * @param key * @param value * @return */ public <K, V> MapPath<K, V, PathBuilder<V>> getMap(String property, Class<K> key, Class<V> value) { validate(property, Map.class); return super.<K,V,PathBuilder<V>>createMap(property, key, value, PathBuilder.class); }
/** * Get a new DateTime path * * @param <A> * @param property property name * @param type * @return */ public <A extends Comparable<?>> DateTimePath<A> getDateTime(String property, Class<A> type) { Class<? extends A> vtype = validate(property, type); return super.createDateTime(property, (Class)vtype); }
/** * Get a new Enum path * * @param <A> * @param property property name * @param type * @return */ public <A extends Enum<A>> EnumPath<A> getEnum(String property, Class<A> type) { validate(property, type); return super.createEnum(property, type); }
/** * Get a new Comparable typed path * * @param <A> * @param property property name * @param type * @return */ public <A extends Comparable<?>> ComparablePath<A> getComparable(String property, Class<A> type) { Class<? extends A> vtype = validate(property, type); return super.createComparable(property, (Class)vtype); }
/** * Get a new Date path * * @param <A> * @param property property name * @param type * @return */ public <A extends Comparable<?>> DatePath<A> getDate(String property, Class<A> type) { Class<? extends A> vtype = validate(property, type); return super.createDate(property, (Class)vtype); }
/** * Get a new List typed path * * @param <A> * @param <E> * @param property property name * @param type * @param queryType * @return */ public <A, E extends SimpleExpression<A>> ListPath<A, E> getList(String property, Class<A> type, Class<E> queryType) { validate(property, List.class); return super.<A, E>createList(property, type, queryType, PathInits.DIRECT); }
/** * Get a new Collection typed path * * @param <A> * @param <E> * @param property property name * @param type * @param queryType * @return */ public <A, E extends SimpleExpression<A>> CollectionPath<A, E> getCollection(String property, Class<A> type, Class<E> queryType) { validate(property, Collection.class); return super.<A, E>createCollection(property, type, queryType, PathInits.DIRECT); }
/** * Get a new Map typed path * * @param <K> * @param <V> * @param <E> * @param property property name * @param key * @param value * @param queryType * @return */ public <K, V, E extends SimpleExpression<V>> MapPath<K, V, E> getMap(String property, Class<K> key, Class<V> value, Class<E> queryType) { validate(property, Map.class); return super.<K,V,E>createMap(property, key, value, queryType); }
public static <T> List<T> findCustom(EntityManager em, Class<T> entityClass,Map<String,?> filters, String sort) { EntityPath<T> entityPath = new EntityPathBase<T>(entityClass, "entity"); BooleanBuilder builder = new BooleanBuilder(); for (Map.Entry<String, ?> entry : filters.entrySet()) { SimplePath<Object> property = new SimplePath<Object>(entry.getValue().getClass(), entityPath, entry.getKey()); builder.and(property.eq(entry.getValue())); } ComparablePath<?> sortProperty = new ComparablePath(Comparable.class, entityPath, sort); return new JPAQuery(em).from(entityPath).where(builder.getValue()).orderBy(sortProperty.asc()).list(entityPath); }
@SuppressWarnings("unchecked") @Override public Expression<?> visit(Path<?> expr, Context context) { final PathType pathType = expr.getMetadata().getPathType(); if (pathType == PathType.LISTVALUE_CONSTANT || pathType == PathType.LISTVALUE) { final String variable = expr.accept(ToStringVisitor.DEFAULT, TEMPLATE).replace('.', '_'); final EntityPath<?> replacement = new EntityPathBase(expr.getType(), variable); context.add(expr, replacement); return replacement; } else if (expr.getMetadata().getParent() != null) { Context c = new Context(); final Path<?> parent = (Path<?>) expr.getMetadata().getParent().accept(this, c); if (c.replace) { context.add(c); return replaceParent(expr, parent); } } return expr; }
@Test public void FromWithCustomEntityName() { JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT); EntityPath<Location> entityPath = new EntityPathBase<Location>(Location.class, "entity"); QueryMetadata md = new DefaultQueryMetadata(); md.addJoin(JoinType.DEFAULT, entityPath); serializer.serialize(md, false, null); assertEquals("select entity\nfrom Location2 entity", serializer.toString()); }
@Override public Expression<?> visit(Path<?> expr, Context context) { if (expr.getMetadata().getPathType() == PathType.COLLECTION_ANY) { Path<?> parent = (Path<?>) expr.getMetadata().getParent().accept(this, context); expr = new PathImpl<Object>(expr.getType(), PathMetadataFactory.forCollectionAny(parent)); EntityPath<?> replacement = new EntityPathBase<Object>(expr.getType(), ExpressionUtils.createRootVariable(expr)); context.add(expr, replacement); return replacement; } else if (expr.getMetadata().getParent() != null) { Context c = new Context(); Path<?> parent = (Path<?>) expr.getMetadata().getParent().accept(this, c); if (c.replace) { context.add(c); return replaceParent(expr, parent); } } return expr; }