/** * Create a Bean populating projection for the given type and expressions * * @param <T> * @param type type of the projection * @param exprs arguments for the projection * @return */ public static <T> QBean<T> bean(Path<T> type, Expression<?>... exprs) { return new QBean<T>(type, exprs); }
/** * Create a field access based Bean populating projection for the given type and expressions * * @param <T> * @param type type of the projection * @param exprs arguments for the projection * @return */ public static <T> QBean<T> fields(Path<T> type, Expression<?>... exprs) { return new QBean<T>(type, true, exprs); }
/** * Create a Bean populating projection for the given type and expressions * * <p>Example</p> * <pre> * UserDTO dto = query.singleResult( * Projections.bean(UserDTO.class, user.firstName, user.lastName)); * </pre> * * @param <T> * @param type type of the projection * @param exprs arguments for the projection * @return */ public static <T> QBean<T> bean(Class<T> type, Expression<?>... exprs) { return new QBean<T>(type, exprs); }
/** * Create a field access based Bean populating projection for the given type and expressions * * <p>Example</p> * <pre> * UserDTO dto = query.singleResult( * Projections.fields(UserDTO.class, user.firstName, user.lastName)); * </pre> * * @param <T> * @param type type of the projection * @param exprs arguments for the projection * @return */ public static <T> QBean<T> fields(Class<T> type, Expression<?>... exprs) { return new QBean<T>(type, true, exprs); }
@SuppressWarnings("unchecked") public QBeans(RelationalPath<?>... beanPaths) { super(Beans.class); try { final ImmutableList.Builder<Expression<?>> listBuilder = ImmutableList.builder(); final ImmutableMap.Builder<RelationalPath<?>, QBean<?>> mapBuilder = ImmutableMap.builder(); for (RelationalPath<?> path : beanPaths) { Map<String, Expression<?>> bindings = new LinkedHashMap<String, Expression<?>>(); for (Path<?> column : path.getColumns()) { bindings.put(column.getMetadata().getName(), column); listBuilder.add(column); } mapBuilder.put(path, new QBean<Object>((Class)path.getType(), bindings)); } expressions = listBuilder.build(); qBeans = mapBuilder.build(); } catch (Exception e) { throw new IllegalStateException(e); } }
private static <T> FactoryExpression<T> createBeanProjection(RelationalPath<T> path) { Map<String,Expression<?>> bindings = new LinkedHashMap<String,Expression<?>>(); for (Path<?> column : path.getColumns()) { bindings.put(column.getMetadata().getName(), column); } if (bindings.isEmpty()) { throw new IllegalArgumentException("No bindings could be derived from " + path); } return new QBean<T>((Class)path.getType(), true, bindings); }