Example #1
0
  /**
   * 获取单表数据列表(暂不支持多表)
   *
   * @param params
   * @return
   */
  public String listIds(Map<String, Object> params) {
    Class domainClass = (Class<? extends BaseDomain>) params.get("domain");
    Criteria criteria = (Criteria) params.get("criteria");
    String tableName = getTable(domainClass);
    String sqlString;
    SQL sql = new SQL().SELECT("id").FROM(tableName);

    if (Objects.nonNull(criteria) && criteria.nonEmpty()) {
      sql.WHERE(criteria.toSqlString());
    }
    sqlString = sql.toString();
    if (Objects.nonNull(criteria) && criteria.isSorted()) {
      sqlString += criteria.toOrderSqlString();
    }
    if (Objects.nonNull(criteria) && criteria.isLimited()) {
      sqlString += criteria.toLimitSqlString();
    }
    logger.debug("{} : {}", logger.getName(), sqlString);
    return sqlString;
  }
Example #2
0
  public String delete(Map<String, Object> params) {
    String sqlString;
    SQL sql = new SQL();
    String tableName = getTable((Class<? extends BaseDomain>) params.get("domain"));
    Long[] ids = (Long[]) Objects.getDefault(params.get("ids"), new Long[] {});
    final StringBuilder idsCondition = new StringBuilder("(-1");

    Iterators.forEach(
        Arrays.asList(ids).iterator(),
        new Iterators.CustomerHandler<Long>() {
          @Override
          public void handle(Long id) {
            idsCondition.append(",").append(id);
          }
        });
    idsCondition.append(")");

    sql.DELETE_FROM(tableName).WHERE("id in " + idsCondition.toString());

    sqlString = sql.toString();
    logger.debug("{} : {}", logger.getName(), sqlString);
    return sqlString;
  }