Search in sources :

Example 1 with PaginationModel

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());
    }
}
Also used : PaginationModel(org.sagacity.sqltoy.model.PaginationModel) OrganInfoVO(sqltoy.showcase.system.vo.OrganInfoVO) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with PaginationModel

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());
    }
}
Also used : PaginationModel(org.sagacity.sqltoy.model.PaginationModel) OrganInfoVO(sqltoy.showcase.system.vo.OrganInfoVO) Test(org.junit.Test)

Example 3 with PaginationModel

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;
}
Also used : PaginationModel(org.sagacity.sqltoy.model.PaginationModel) DataSetResult(org.sagacity.sqltoy.model.DataSetResult)

Example 4 with PaginationModel

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;
}
Also used : PaginationModel(org.sagacity.sqltoy.model.PaginationModel) JSONObject(com.alibaba.fastjson.JSONObject) DataSetResult(org.sagacity.sqltoy.model.DataSetResult)

Example 5 with PaginationModel

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;
}
Also used : PaginationModel(org.sagacity.sqltoy.model.PaginationModel) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) Document(org.bson.Document)

Aggregations

PaginationModel (org.sagacity.sqltoy.model.PaginationModel)10 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 List (java.util.List)2 DataSetResult (org.sagacity.sqltoy.model.DataSetResult)2 OrganInfoVO (sqltoy.showcase.system.vo.OrganInfoVO)2 StaffInfoVO (sqltoy.showcase.system.vo.StaffInfoVO)2 JSONObject (com.alibaba.fastjson.JSONObject)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 Document (org.bson.Document)1 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)1 Goods (sqltoy.showcase.system.vo.Goods)1 GoodsParam (sqltoy.showcase.system.vo.GoodsParam)1 ShardingHisVO (sqltoy.showcase.system.vo.ShardingHisVO)1 ShardingRealVO (sqltoy.showcase.system.vo.ShardingRealVO)1