Search in sources :

Example 1 with OrderBy

use of com.mendmix.common.model.OrderBy in project jeesuite-libs by vakinge.

the class SqlRewriteHandler method handleTableOrderBy.

private void handleTableOrderBy(PlainSelect selectBody, Table table, InvocationVals invocation) {
    PageParams pageParam = invocation.getPageParam();
    if (pageParam == null || pageParam.getOrderBys() == null || pageParam.getOrderBys().isEmpty()) {
        return;
    }
    List<OrderByElement> orderByElements = new ArrayList<>(pageParam.getOrderBys().size());
    OrderByElement orderByElement;
    for (OrderBy orderBy : pageParam.getOrderBys()) {
        if (orderBy == null)
            continue;
        MapperMetadata mapperMeta = MybatisMapperParser.getMapperMetadata(invocation.getMapperNameSpace());
        String columnName = mapperMeta.getEntityMetadata().getProp2ColumnMappings().get(orderBy.getField());
        if (columnName == null)
            columnName = orderBy.getField();
        orderByElement = new OrderByElement();
        orderByElement.setAsc(OrderType.ASC.name().equals(orderBy.getSortType()));
        orderByElement.setExpression(new Column(table, columnName));
        orderByElements.add(orderByElement);
    }
    selectBody.setOrderByElements(orderByElements);
}
Also used : OrderBy(com.mendmix.common.model.OrderBy) Column(net.sf.jsqlparser.schema.Column) ArrayList(java.util.ArrayList) PageParams(com.mendmix.common.model.PageParams) OrderByElement(net.sf.jsqlparser.statement.select.OrderByElement) MapperMetadata(com.mendmix.mybatis.metadata.MapperMetadata)

Example 2 with OrderBy

use of com.mendmix.common.model.OrderBy in project jeesuite-libs by vakinge.

the class BaseMybatisTest method testPage.

@Test
public void testPage() {
    Page<UserEntity> pageInfo;
    UserEntity example = new UserEntity();
    example.setType((short) 1);
    PageParams pageParams = new PageParams(1, 10, new OrderBy("name"));
    pageInfo = PageExecutor.pagination(pageParams, new PageDataLoader<UserEntity>() {

        @Override
        public List<UserEntity> load() {
            return userMapper.selectByExample(example);
        }
    });
    System.out.println(pageInfo);
}
Also used : OrderBy(com.mendmix.common.model.OrderBy) PageParams(com.mendmix.common.model.PageParams) PageDataLoader(com.mendmix.mybatis.plugin.pagination.PageExecutor.PageDataLoader) UserEntity(com.mendmix.mybatis.test.entity.UserEntity) Test(org.junit.Test)

Aggregations

OrderBy (com.mendmix.common.model.OrderBy)2 PageParams (com.mendmix.common.model.PageParams)2 MapperMetadata (com.mendmix.mybatis.metadata.MapperMetadata)1 PageDataLoader (com.mendmix.mybatis.plugin.pagination.PageExecutor.PageDataLoader)1 UserEntity (com.mendmix.mybatis.test.entity.UserEntity)1 ArrayList (java.util.ArrayList)1 Column (net.sf.jsqlparser.schema.Column)1 OrderByElement (net.sf.jsqlparser.statement.select.OrderByElement)1 Test (org.junit.Test)1