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]);
}
Aggregations