/** * Returns a qualifier expression for an unresolved id object. * * @since 3.0 */ Expression buildIdQualifier(Object id) { Map<String, ?> map = (Map<String, ?>) id; if (map.isEmpty()) { throw new CayenneRuntimeException("Empty id map"); } return ExpressionFactory.matchAllDbExp(map, Expression.EQUAL_TO); }
Expression buildIdQualifier(int index, Object[] data) { Map<String, Object> map; if(data[index] instanceof Map) { map = (Map<String, Object>)data[index]; } else { map = new HashMap<>(); int i = 0; for (ObjAttribute attribute : indexToEntity.get(index).getPrimaryKeys()) { map.put(attribute.getDbAttributeName(), data[index + i++]); } } return ExpressionFactory.matchAllDbExp(map, Expression.EQUAL_TO); }
/** * Creates an expression that matches the primary key of object in * <code>ObjectId</code>'s <code>IdSnapshot</code> for the argument * <code>object</code>. */ public static Expression matchExp(Persistent object) { return matchAllDbExp(object.getObjectId().getIdSnapshot(), Expression.EQUAL_TO); }
/** * 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 and returns a select query that can be used to fetch an object given an * ObjectId. */ public static SelectQuery selectObjectForId(ObjectId oid) { return new SelectQuery(oid.getEntityName(), ExpressionFactory.matchAllDbExp(oid .getIdSnapshot(), Expression.EQUAL_TO)); }
protected Map<String, SelectQuery> getIdQueriesByEntity(EntityResolver resolver) { if (this.idQueriesByEntity == null) { Map<String, SelectQuery> idQueriesByEntity = new HashMap<>(); Map<String, EntityIdCoder> codersByEntity = new HashMap<>(); for (String id : stringIds) { String entityName = EntityIdCoder.getEntityName(id); EntityIdCoder coder = codersByEntity.get(entityName); SelectQuery query; if (coder == null) { coder = new EntityIdCoder(resolver.getObjEntity(entityName)); query = new SelectQuery(entityName); codersByEntity.put(entityName, coder); idQueriesByEntity.put(entityName, query); } else { query = idQueriesByEntity.get(entityName); } Expression idExp = ExpressionFactory.matchAllDbExp(coder .toObjectId(id) .getIdSnapshot(), Expression.EQUAL_TO); query.orQualifier(idExp); } this.idQueriesByEntity = idQueriesByEntity; } return this.idQueriesByEntity; }
SelectQuery query = new SelectQuery(joinEntity, ExpressionFactory.matchAllDbExp( snapshot, Expression.EQUAL_TO));
quals.add(ExpressionFactory.matchAllDbExp(map, Expression.EQUAL_TO));
Expression idExp = ExpressionFactory.matchAllDbExp(id.getIdSnapshot(), Expression.EQUAL_TO); query.orQualifier(idExp);
@Override protected Query createReplacementQuery(EntityResolver resolver) { if (objectId == null) { throw new CayenneRuntimeException("Can't resolve query - objectId is null."); } if (objectId.isTemporary() && !objectId.isReplacementIdAttached()) { throw new CayenneRuntimeException("Can't build a query for temporary id: %s", objectId); } SelectQuery<Object> query = new SelectQuery<>(objectId.getEntityName(), ExpressionFactory .matchAllDbExp(objectId.getIdSnapshot(), Expression.EQUAL_TO)); // if we got to the point of fetch, always force refresh.... query.setFetchingDataRows(fetchingDataRows); return query; }
protected Query createReplacementQuery(EntityResolver resolver) { if (objectId == null) { throw new CayenneRuntimeException("Can't resolve query - objectId is null."); } if (objectId.isTemporary() && !objectId.isReplacementIdAttached()) { throw new CayenneRuntimeException("Can't build a query for temporary id: " + objectId); } SelectQuery query = new SelectQuery(objectId.getEntityName(), ExpressionFactory .matchAllDbExp(objectId.getIdSnapshot(), Expression.EQUAL_TO)); // if we got to the point of fetch, always force refresh.... query.setRefreshingObjects(true); query.setFetchingDataRows(fetchingDataRows); return query; }
@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; }