/** * Creates a ColumnSelect that will fetch multiple columns of a given {@link ObjEntity} * * @param entityType base persistent class that will be used as a root for this query * @param firstColumn column to select * @param otherColumns columns to select */ public static ColumnSelect<Object[]> columnQuery(Class<?> entityType, Property<?> firstColumn, Property<?>... otherColumns) { return new ColumnSelect<Object[]>().entityType(entityType).columns(firstColumn, otherColumns); }
/** * Appends a having qualifier expression of this query. An equivalent to * {@link #and(Expression...)} that can be used a syntactic sugar. * * @return this object */ public ColumnSelect<T> having(Expression expression) { havingExpressionIsActive = true; return and(expression); }
public ColumnSelect<T> cacheStrategy(QueryCacheStrategy strategy, String cacheGroup) { return cacheStrategy(strategy).cacheGroup(cacheGroup); }
/** * Creates a ColumnSelect that will fetch single property that can be resolved * against a given {@link ObjEntity} class. * * @param entityType base persistent class that will be used as a root for this query * @param column single column to select */ public static <E> ColumnSelect<E> columnQuery(Class<?> entityType, Property<E> column) { return new ColumnSelect<>().entityType(entityType).column(column); }
/** * <p>Quick way to select count of records</p> * <p>Usage: * <pre> * {@code * long count = ObjectSelect.query(Artist.class) * .where(Artist.ARTIST_NAME.like("a%")) * .selectCount(context); * } * </pre> * </p> * @param context to perform query * @return count of rows */ public long selectCount(ObjectContext context) { return count().selectOne(context); }
/** * AND's provided expressions to the existing WHERE or HAVING clause expression. * * @return this object */ public ColumnSelect<T> and(Collection<Expression> expressions) { if (expressions == null || expressions.isEmpty()) { return this; } Collection<Expression> all; Expression activeExpression = getActiveExpression(); if (activeExpression != null) { all = new ArrayList<>(expressions.size() + 1); all.add(activeExpression); all.addAll(expressions); } else { all = expressions; } setActiveExpression(ExpressionFactory.and(all)); return this; }
/** * <p>Select only specific properties.</p> * <p>Can be any properties that can be resolved against root entity type * (root entity's properties, function call expressions, properties of relationships, etc).</p> * <p> * <pre> * {@code * List<Object[]> columns = ObjectSelect.query(Artist.class) * .columns(Artist.ARTIST_NAME, Artist.DATE_OF_BIRTH) * .select(context); * } * </pre> * * @param properties array of properties to select * @see ObjectSelect#column(Property) */ public ColumnSelect<Object[]> columns(Property<?> firstProperty, Property<?>... properties) { return new ColumnSelect<>(this).columns(firstProperty, properties); }
/** * <p>Select one specific property.</p> * <p>Can be any property that can be resolved against root entity type * (root entity's property, function call expression, property of relationships, etc)</p> * <p>If you need several columns use {@link ObjectSelect#columns(Property, Property[])} method.</p> * <p> * <pre> * {@code * List<String> names = ObjectSelect.query(Artist.class) * .column(Artist.ARTIST_NAME) * .select(context); * } * </pre> * </p> * @param property single property to select * @see ObjectSelect#columns(Property, Property[]) */ public <E> ColumnSelect<E> column(Property<E> property) { return new ColumnSelect<>(this).column(property); }
/** * <p>Shortcut for {@link #columns(Property, Property[])} columns}(Property.COUNT)</p> */ public ColumnSelect<Object[]> count() { return columns(Property.COUNT); }
/** * Instructs Cayenne to look for query results in the "local" cache when * running the query. This is a short-hand notation for: * <p> * <pre> * query.cacheStrategy(QueryCacheStrategy.LOCAL_CACHE); * </pre> */ public ColumnSelect<T> localCache() { return cacheStrategy(QueryCacheStrategy.LOCAL_CACHE); }
/** * Creates a new IncrementalFaultList using a given DataContext and query. * * @param dataContext DataContext used by IncrementalFaultList to fill itself with * objects. * @param query Main query used to retrieve data. Must have "pageSize" * property set to a value greater than zero. */ MixedResultIncrementalFaultList(DataContext dataContext, Query query, int maxFetchSize) { super(dataContext, query, maxFetchSize); // this should generally be true, and may be it worth to do something if it's not if(query instanceof ColumnSelect) { this.internalQuery.setColumns(((ColumnSelect<?>) query).getColumns()); } }
protected long countRows(Class<?> entity) { return ObjectSelect.columnQuery(entity, Property.COUNT).selectOne(newContext()); }
/** * OR's provided expressions to the existing WHERE or HAVING clause expression. * * @return this object */ public ColumnSelect<T> or(Collection<Expression> expressions) { if (expressions == null || expressions.isEmpty()) { return this; } Collection<Expression> all; Expression activeExpression = getActiveExpression(); if (activeExpression != null) { all = new ArrayList<>(expressions.size() + 1); all.add(activeExpression); all.addAll(expressions); } else { all = expressions; } setActiveExpression(ExpressionFactory.or(all)); return this; }
/** * <p>Select COUNT(property)</p> * <p>Can return different result than COUNT(*) as it will count only non null values</p> * @see ColumnSelect#count() */ public ColumnSelect<Object[]> count(Property<?> property) { return columns(property.count()); }
/** * Instructs Cayenne to look for query results in the "shared" cache when * running the query. This is a short-hand notation for: * <p> * <pre> * query.cacheStrategy(QueryCacheStrategy.SHARED_CACHE, cacheGroup); * </pre> */ public ColumnSelect<T> sharedCache(String cacheGroup) { return cacheStrategy(QueryCacheStrategy.SHARED_CACHE, cacheGroup); }
/** * <p>Select maximum value of property</p> * @see ColumnSelect#columns(Property, Property[]) */ public ColumnSelect<Object[]> max(Property<?> property) { return columns(property.max()); }
/** * Appends a qualifier expression of this query. An equivalent to * {@link #and(Expression...)} that can be used a syntactic sugar. * * @return this object */ public ColumnSelect<T> where(Expression expression) { return and(expression); }
/** * Instructs Cayenne to look for query results in the "local" cache when * running the query. This is a short-hand notation for: * <p> * <pre> * query.cacheStrategy(QueryCacheStrategy.LOCAL_CACHE, cacheGroup); * </pre> */ public ColumnSelect<T> localCache(String cacheGroup) { return cacheStrategy(QueryCacheStrategy.LOCAL_CACHE, cacheGroup); }
/** * <p>Select average value of property</p> * @see ColumnSelect#columns(Property, Property[]) */ public ColumnSelect<Object[]> avg(Property<?> property) { return columns(property.avg()); }