@Override public void setRoot(Object value) { query.setRoot(value); }
private void init(Object root, Expression qualifier) { this.setRoot(root); this.setQualifier(qualifier); }
private void init(Object root, Expression qualifier) { this.setRoot(root); this.setQualifier(qualifier); }
/** * @since 4.0 */ public static SelectQuery<DataRow> dataRowQuery(Class<?> rootClass) { // create a query replica that would fetch DataRows SelectQuery<DataRow> query = new SelectQuery<DataRow>(); query.setRoot(rootClass); query.metaData.setFetchingDataRows(true); return query; }
/** * Creates and returns a select query that can be used to fetch a list of objects * given a list of ObjectIds. All ObjectIds must belong to the same entity. */ public static SelectQuery selectQueryForIds(List oids) { if (oids == null || oids.size() == 0) { throw new IllegalArgumentException("List must contain at least one ObjectId"); } SelectQuery sel = new SelectQuery(); sel.setRoot(((ObjectId) oids.get(0)).getEntityName()); Iterator it = oids.iterator(); ObjectId firstId = (ObjectId) it.next(); Expression exp = ExpressionFactory.matchAllDbExp( firstId.getIdSnapshot(), Expression.EQUAL_TO); while (it.hasNext()) { ObjectId anId = (ObjectId) it.next(); exp = exp.orExp(ExpressionFactory.matchAllDbExp( anId.getIdSnapshot(), Expression.EQUAL_TO)); } sel.setQualifier(exp); return sel; }
/** * Creates a SelectQuery. */ public Query getQuery() { SelectQuery query = new SelectQuery(); query.setRoot(getRoot()); query.setName(name); query.setQualifier(qualifier); if (orderings != null && !orderings.isEmpty()) { query.addOrderings(orderings); } if (prefetches != null && !prefetches.isEmpty()) { Iterator it = prefetches.iterator(); while(it.hasNext()) { query.addPrefetch((String) it.next()); } } // init properties query.initWithProperties(properties); return query; } }
query.setParentObjEntityName(parentObjEntityName); query.setParentQualifier(parentQualifier); query.setRoot(root);
/** * Returns a query built using this query as a prototype, using a set of * parameters to build the qualifier. * * @see org.apache.cayenne.exp.Expression#expWithParameters(java.util.Map, * boolean) parameter substitution. */ public SelectQuery<T> queryWithParameters(Map<String, ?> parameters, boolean pruneMissing) { // create a query replica SelectQuery<T> query = new SelectQuery<T>(); query.setDistinct(distinct); query.metaData.copyFromInfo(this.metaData); query.setRoot(root); if (orderings != null) { query.addOrderings(orderings); } // substitute qualifier parameters if (qualifier != null) { query.setQualifier(qualifier.params(parameters, pruneMissing)); } return query; }
@Override public SelectQuery<?> buildQuery() { SelectQuery<Object> selectQuery = new SelectQuery<>(); selectQuery.setRoot(this.getRoot()); selectQuery.setName(this.getName()); selectQuery.setDataMap(dataMap); selectQuery.setQualifier(this.getQualifier()); List<Ordering> orderings = this.getOrderings(); if (orderings != null && !orderings.isEmpty()) { selectQuery.addOrderings(orderings); } List<String> prefetches = this.getPrefetches(); if (prefetches != null && !prefetches.isEmpty()) { for (String prefetch : prefetches) { selectQuery.addPrefetch(prefetch); } } // init properties selectQuery.initWithProperties(this.getProperties()); return selectQuery; }
@SuppressWarnings("deprecation") @Override protected Query createReplacementQuery(EntityResolver resolver) { ObjEntity entity = resolveEntity(resolver); Map<String, ?> id = resolveId(entity); SelectQuery<Object> query = new SelectQuery<>(); query.setRoot(entity); query.setFetchingDataRows(fetchingDataRows); query.setQualifier(matchAllDbExp(id, Expression.EQUAL_TO)); // note on caching... this hits query cache instead of object cache... // until we merge the two this may result in not using the cache // optimally - object cache may have an object, but query cache will not query.setCacheGroup(cacheGroup); query.setCacheStrategy(cacheStrategy); query.setPrefetchTree(prefetches); return query; }