use of org.sagacity.sqltoy.model.PaginationModel in project sagacity-sqltoy by chenrenfei.
the class LinkDaoTest method findESPage.
@Test
public void findESPage() throws Exception {
OrganInfoVO organInfoVO = new OrganInfoVO();
// organInfoVO.setStaffName("李");
PaginationModel pageModel = staffInfoDao.findESPage(new PaginationModel(), organInfoVO);
System.err.println(pageModel.getRecordCount());
for (OrganInfoVO organ : (List<OrganInfoVO>) pageModel.getRows()) {
System.err.println(organ.getOrganId() + " organName:=" + organ.getOrganName());
}
}
use of org.sagacity.sqltoy.model.PaginationModel in project sagacity-sqltoy by chenrenfei.
the class LinkDaoTest method findESAggs.
@Test
public void findESAggs() throws Exception {
OrganInfoVO organInfoVO = new OrganInfoVO();
// organInfoVO.setStaffName("李");
List<OrganInfoVO> result = staffInfoDao.findESAggs(new PaginationModel(), organInfoVO);
for (OrganInfoVO organ : result) {
System.err.println(organ.getOrganId() + " organName:=" + organ.getOrganName());
}
}
use of org.sagacity.sqltoy.model.PaginationModel in project sagacity-sqltoy by chenrenfei.
the class ElasticSqlPlugin method findPage.
/**
* @todo 基于es的分页查询
* @param sqlToyContext
* @param sqlToyConfig
* @param pageModel
* @param queryExecutor
* @return
* @throws Exception
*/
public static PaginationModel findPage(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, PaginationModel pageModel, QueryExecutor queryExecutor) throws Exception {
String realMql = MongoElasticUtils.wrapES(sqlToyConfig, queryExecutor.getParamsName(sqlToyConfig), queryExecutor.getParamsValue(sqlToyConfig)).trim();
// sql模式
realMql = realMql + " limit " + (pageModel.getPageNo() - 1) * pageModel.getPageSize() + "," + pageModel.getPageSize();
if (sqlToyContext.isDebug()) {
out.println("execute eql={" + realMql + "}");
}
PaginationModel page = new PaginationModel();
page.setPageNo(pageModel.getPageNo());
page.setPageSize(pageModel.getPageSize());
DataSetResult result = ElasticSearchUtils.executeQuery(sqlToyContext, sqlToyConfig, realMql, queryExecutor.getResultTypeName());
page.setRows(result.getRows());
page.setRecordCount(result.getTotalCount());
return page;
}
use of org.sagacity.sqltoy.model.PaginationModel in project sagacity-sqltoy by chenrenfei.
the class ElasticSearchPlugin method findPage.
/**
* @todo 基于es的分页查询
* @param sqlToyContext
* @param sqlToyConfig
* @param pageModel
* @param queryExecutor
* @return
* @throws Exception
*/
public static PaginationModel findPage(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, PaginationModel pageModel, QueryExecutor queryExecutor) throws Exception {
String realMql = MongoElasticUtils.wrapES(sqlToyConfig, queryExecutor.getParamsName(sqlToyConfig), queryExecutor.getParamsValue(sqlToyConfig)).trim();
JSONObject jsonQuery = JSON.parseObject(realMql);
jsonQuery.fluentRemove("from");
jsonQuery.fluentRemove("FROM");
jsonQuery.fluentRemove("size");
jsonQuery.fluentRemove("SIZE");
jsonQuery.fluentPut("from", (pageModel.getPageNo() - 1) * pageModel.getPageSize());
jsonQuery.fluentPut("size", pageModel.getPageSize());
if (sqlToyContext.isDebug()) {
out.println("execute eql={" + jsonQuery.toJSONString() + "}");
}
PaginationModel page = new PaginationModel();
page.setPageNo(pageModel.getPageNo());
page.setPageSize(pageModel.getPageSize());
DataSetResult result = executeQuery(sqlToyContext, sqlToyConfig, jsonQuery, queryExecutor.getResultTypeName());
page.setRows(result.getRows());
page.setRecordCount(result.getTotalCount());
return page;
}
use of org.sagacity.sqltoy.model.PaginationModel in project sagacity-sqltoy by chenrenfei.
the class Mongo method findPage.
/**
* @todo 分页查询
* @param mongoTemplate
* @param sqlToyConfig
* @param pageModel
* @param mql
* @param resultClass
* @return
* @throws Exception
*/
private PaginationModel findPage(MongoTemplate mongoTemplate, SqlToyConfig sqlToyConfig, PaginationModel pageModel, String mql, String resultClass) throws Exception {
PaginationModel result = new PaginationModel();
result.setPageNo(pageModel.getPageNo());
result.setPageSize(pageModel.getPageSize());
BasicQuery query = new BasicQuery(mql);
result.setRecordCount(mongoTemplate.count(query, sqlToyConfig.getNoSqlConfigModel().getCollection()));
// 设置分页
if (result.getPageNo() == -1) {
query.skip(0).limit(new Long(result.getRecordCount()).intValue());
} else
query.skip((pageModel.getPageNo() - 1) * pageModel.getPageSize()).limit(pageModel.getPageSize());
List<Document> rs = mongoTemplate.find(query, Document.class, sqlToyConfig.getNoSqlConfigModel().getCollection());
if (rs == null || rs.isEmpty())
return result;
result.setRows(extractFieldValues(sqlToyConfig, rs.iterator(), resultClass));
return result;
}
Aggregations