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); }
public QueryListResult queryListByIds(Set<Object> ids, QueryOptions options) { String idFieldName = em.getKeyFieldNames()[0]; if (remoteRest) { String filter = idFieldName + " in (" + joinInIds(new ArrayList<>(ids)) + ")"; if (Strings.isEmpty(options.getFilters())) { options.setFilters(filter); } else { options.setFilters("(" + options.getFilters() + ") and (" + filter + ")"); } RestResource restResource = restResourceFactory.createResource(dao.getOrmContext(), em); RestQueryListResult<Record> result = restResource.queryList(options); return new QueryListResult(result.getList(), result.getCount()); } else { CriteriaQuery<Record> query = createCriteriaQuery().where(idFieldName + " in ?", ids); return doQueryListResult(query, new HashMap<>(), options, null, null); } } }
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; }
@Override public QueryListResult queryList(Object id, QueryOptions options) { RelationExecutionContext context = new DefaultRelationExecutionContext(DefaultRelationQueryExecutor.this.context); ex.preRelateQueryList(context, id, options); QueryListResult result; if (remoteRest) { result = queryListRemoteSource(id, options); }else if (rm.isEmbedded()) { result = queryListEmbedded(id, options); }else if (tem.isRemoteRest()) { result = queryListRemoteTarget(id, options); }else { result = iqe.queryListByRelation(id, options); } ex.postRelateQueryList(context, id, result.getList()); ex.completeRelateQueryList(context, id, result); return result; }
public QueryListResult queryListByRelation(Object relatedId, QueryOptions options) { CriteriaQuery<Record> query = createCriteriaQuery().joinById(rm.getTargetEntityName(), rm.getName(), "j", relatedId); Map<String, ModelAndMapping> joinedModels = New.hashMap("j", new ModelAndMapping(am, em)); return doQueryListResult(query, joinedModels, options, null, null); }
public DefaultRelationQueryExecutor(RelationExecutorContext context, RelationQueryExtension ex) { super(context); this.ex = ex; this.tem = context.getInverseEntityMapping(); this.rm = context.getRelation(); this.rp = !Strings.isEmpty(context.getRelationPath()) ? context.getRelationPath() : Strings.lowerUnderscore(rm.getName()); this.irm = context.getInverseRelation(); this.iqe = new InverseQueryExecutor(context.newInverseExecutorContext(), irm); }
public Record queryOneByRelation(Object relatedId, QueryOptionsBase options) { CriteriaQuery<Record> query = createCriteriaQuery().joinById(rm.getTargetEntityName(), rm.getName(), "j", relatedId); Map<String, ModelAndMapping> joinedModels = New.hashMap("j", new ModelAndMapping(am, em)); applySelect(query, options, joinedModels); Record record = query.firstOrNull(); expandOne(record, options); return record; }