protected Record queryOneRemoteTarget(Object id, QueryOptionsBase options) { String[] fields = Arrays.stream(rm.getJoinFields()) .map(joinField -> joinField.getLocalFieldName()) .toArray(String[]::new); Record record = dao.createCriteriaQuery(em).select(fields).whereById(id).firstOrNull(); if (null == record) { throw new BadRequestException("Record " + em.getEntityName() + "(" + id + ") not found"); } Object targetId = CrudUtils.getSingleOrMap(record, fields); if (null == targetId) { return null; } return iqe.queryOne(targetId, options).record; }
protected QueryListResult queryListEmbedded(Object id, QueryOptions options) { Record record = dao.createCriteriaQuery(em).whereById(id).select(rm.getEmbeddedFileName()).firstOrNull(); if (null == record) { throw new BadRequestException("Record " + em.getEntityName() + "(" + id + ") not found"); } Set<Object> embeddedIds = new HashSet<>(); iqe.calcIdsByEmbeddedField(embeddedIds, record, rm.getEmbeddedFileName()); if (embeddedIds.isEmpty()) { return QueryListResult.EMPTY; } return iqe.queryListByIds(embeddedIds, options); }
@Override public QueryOneResult queryOne(Object id, QueryOptionsBase options) { if (remoteRest) { RestResource restResource = restResourceFactory.createResource(dao.getOrmContext(), em); Record record = restResource.find(id, options); return new QueryOneResult(record); } ModelExecutionContext context = new DefaultModelExecutionContext(this.context); if (null != ex.handler) { ex.handler.processQueryOneOptions(context, id, options); } Record record; CriteriaQuery<Record> query = createCriteriaQuery().whereById(id); applySelect(query, options, new HashMap<>()); ex.preQueryOne(context, id, query); if (null != ex.handler) { ex.handler.preQueryOne(context, id, query); } record = query.firstOrNull(); expandOne(record, options); if (null != ex.handler && null != record) { ex.handler.postQueryOne(context, id, record); } Object entity = ex.processQueryOneRecord(context, id, record); return new QueryOneResult(record, entity); }