예제 #1
0
  private List<Object> getParentIdList(int batchSize) {

    ArrayList<Object> idList = new ArrayList<>(batchSize);

    BeanPropertyAssocMany<?> many = getMany();
    for (BeanCollection<?> bc : batch) {
      idList.add(many.getParentId(bc.getOwnerBean()));
    }
    int extraIds = batchSize - batch.size();
    if (extraIds > 0) {
      Object firstId = idList.get(0);
      for (int i = 0; i < extraIds; i++) {
        idList.add(firstId);
      }
    }

    return idList;
  }
예제 #2
0
  public SpiQuery<?> createQuery(EbeanServer server, int batchSize) {

    BeanPropertyAssocMany<?> many = getMany();

    SpiQuery<?> query = (SpiQuery<?>) server.createQuery(many.getTargetType());
    String orderBy = many.getLazyFetchOrderBy();
    if (orderBy != null) {
      query.orderBy(orderBy);
    }

    String extraWhere = many.getExtraWhere();
    if (extraWhere != null) {
      // replace special ${ta} placeholder with the base table alias
      // which is always t0 and add the extra where clause
      String ew = StringHelper.replaceString(extraWhere, "${ta}", "t0");
      query.where().raw(ew);
    }

    query.setLazyLoadForParents(many);

    List<Object> idList = getParentIdList(batchSize);
    many.addWhereParentIdIn(query, idList, loadContext.isUseDocStore());

    query.setPersistenceContext(loadContext.getPersistenceContext());

    String mode = isLazy() ? "+lazy" : "+query";
    query.setLoadDescription(mode, getDescription());

    if (isLazy()) {
      // cascade the batch size (if set) for further lazy loading
      query.setLazyLoadBatchSize(getBatchSize());
    }

    // potentially changes the joins and selected properties
    loadContext.configureQuery(query);

    if (isOnlyIds()) {
      // override to just select the Id values
      query.select(many.getTargetIdProperty());
    }

    return query;
  }