Search in sources :

Example 1 with FilterParseException

use of com.rebuild.core.service.query.FilterParseException in project rebuild by getrebuild.

the class BulkOperator method prepareRecords.

/**
 * 获取待操作记录
 *
 * @return
 */
protected ID[] prepareRecords() {
    if (this.records != null) {
        return this.records;
    }
    if (context.getRecords() != null) {
        this.records = context.getRecords();
        setTotal(this.records.length);
        return this.records;
    }
    JSONObject asFilterExp = (JSONObject) context.getExtraParams().get("customData");
    AdvFilterParser filterParser = new AdvFilterParser(asFilterExp);
    String sqlWhere = filterParser.toSqlWhere();
    // `(1=1)`.length < 10
    if (sqlWhere.length() < 10) {
        throw new FilterParseException("Must specify items of filter : " + sqlWhere);
    }
    Entity entity = MetadataHelper.getEntity(asFilterExp.getString("entity"));
    String sql = String.format("select %s from %s where (1=1) and %s", entity.getPrimaryField().getName(), entity.getName(), sqlWhere);
    // NOTE 注意没有分页
    Query query = Application.createQuery(sql, context.getOpUser());
    Object[][] array = QueryHelper.readArray(query);
    Set<ID> ids = new HashSet<>();
    for (Object[] o : array) {
        ids.add((ID) o[0]);
    }
    return ids.toArray(new ID[0]);
}
Also used : Entity(cn.devezhao.persist4j.Entity) AdvFilterParser(com.rebuild.core.service.query.AdvFilterParser) JSONObject(com.alibaba.fastjson.JSONObject) FilterParseException(com.rebuild.core.service.query.FilterParseException) Query(cn.devezhao.persist4j.Query) JSONObject(com.alibaba.fastjson.JSONObject) ID(cn.devezhao.persist4j.engine.ID) HashSet(java.util.HashSet)

Aggregations

Entity (cn.devezhao.persist4j.Entity)1 Query (cn.devezhao.persist4j.Query)1 ID (cn.devezhao.persist4j.engine.ID)1 JSONObject (com.alibaba.fastjson.JSONObject)1 AdvFilterParser (com.rebuild.core.service.query.AdvFilterParser)1 FilterParseException (com.rebuild.core.service.query.FilterParseException)1 HashSet (java.util.HashSet)1