Skip to content

Commit

Permalink
1.4.25 优化toPageResult
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejmnet committed Sep 20, 2023
1 parent 8d318e5 commit d17ae34
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.easy.query.core.api.pagination;

import com.easy.query.core.sharding.manager.SequenceCountLine;
import com.easy.query.core.util.EasyCollectionUtil;

import java.util.List;

Expand All @@ -18,7 +17,6 @@ public class DefaultShardingPageResult<T> implements EasyShardingPageResult<T> {

public DefaultShardingPageResult(long total, List<T> data,SequenceCountLine sequenceCountLine) {
this.total = total;

this.data = data;
this.sequenceCountLine = sequenceCountLine;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import com.easy.query.core.basic.api.select.Query;

import java.util.List;

/**
* create time 2023/9/19 21:57
* 文件说明
*
* @author xuejiaming
*/
public interface Pager<TEntity,TPageResult> {
TPageResult toResult(Query<TEntity> query,long pageIndex,long pageSize, long pageTotal);
TPageResult toResult(Query<TEntity> query,long pageIndex,long pageSize, List<Long> totalLines);
TPageResult toResult(Query<TEntity> query);

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.easy.query.core.basic.api.select;

import com.easy.query.core.api.pagination.EasyPageResult;
import com.easy.query.core.api.pagination.Pagination;
import com.easy.query.core.api.pagination.ShardingPagination;
import com.easy.query.core.api.pagination.Pager;
import com.easy.query.core.basic.jdbc.executor.internal.enumerable.JdbcStreamResult;
import com.easy.query.core.basic.jdbc.parameter.DefaultToSQLContext;
import com.easy.query.core.basic.jdbc.parameter.ToSQLContext;
Expand Down Expand Up @@ -299,26 +298,8 @@ default EasyPageResult<T> toPageResult(long pageIndex, long pageSize) {
* @return 分页结果
*/
EasyPageResult<T> toPageResult(long pageIndex, long pageSize, long pageTotal);

/**
* 进行用户自定义分页结果
* @param pageIndex
* @param pageSize
* @param pageTotal
* @return
*/
default Pagination<T> toPage(long pageIndex, long pageSize, long pageTotal) {
return new Pagination<>(this, pageIndex, pageSize, pageTotal);
}

/**
* 进行用户自定义分页结果
* @param pageIndex
* @param pageSize
* @return
*/
default Pagination<T> toPage(long pageIndex, long pageSize) {
return toPage(pageIndex, pageSize, -1);
default <TPageResult> TPageResult toPageResult(Pager<T,TPageResult> pager){
return pager.toResult(this);
}

/**
Expand All @@ -342,27 +323,6 @@ default EasyPageResult<T> toShardingPageResult(long pageIndex, long pageSize) {
*/
EasyPageResult<T> toShardingPageResult(long pageIndex, long pageSize, List<Long> totalLines);


/**
* 进行用户自定义分页结果
* @param pageIndex
* @param pageSize
* @param totalLines
* @return
*/
default ShardingPagination<T> toShardingPage(long pageIndex, long pageSize, List<Long> totalLines) {
return new ShardingPagination<>(this, pageIndex, pageSize, totalLines);
}

/**
* 进行用户自定义分页结果
* @param pageIndex
* @param pageSize
* @return
*/
default ShardingPagination<T> toShardingPage(long pageIndex, long pageSize) {
return toShardingPage(pageIndex, pageSize, null);
}
/**
* 去重
* eg. SELECT DISTINCT projects FROM table t [WHERE t.`columns` = ?]
Expand Down
8 changes: 4 additions & 4 deletions sql-test/src/main/java/com/easy/query/test/QueryTest3.java
Original file line number Diff line number Diff line change
Expand Up @@ -2085,12 +2085,12 @@ public void testGenericKey1(){
}
@Test
public void testGenericKey2(){
PageResult<TopicGenericKey> result = easyQuery
PageResult<TopicGenericKey> pageResult = easyQuery
.queryable(TopicGenericKey.class)
.whereById("1")
.toPage(1, 2)
.toResult(new MyPager<>());
Assert.assertEquals(1,result.getTotalCount());
.toPageResult(new MyPager<>(1, 2));
Assert.assertEquals(1,pageResult.getTotalCount());
Assert.assertEquals("1",pageResult.getList().get(0).getId());
}

}
19 changes: 13 additions & 6 deletions sql-test/src/main/java/com/easy/query/test/common/MyPager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@
* @author xuejiaming
*/
public class MyPager<TEntity> implements Pager<TEntity,PageResult<TEntity>> {
@Override
public PageResult<TEntity> toResult(Query<TEntity> query, long pageIndex, long pageSize, long pageTotal) {
EasyPageResult<TEntity> pageResult = query.toPageResult(pageIndex, pageSize,pageTotal);
return new MyPageResult<>(pageResult.getTotal(),pageResult.getData());
private final long pageIndex;
private final long pageSize;
private final long pageTotal;

public MyPager(long pageIndex, long pageSize){
this(pageIndex,pageSize,-1);
}
public MyPager(long pageIndex, long pageSize, long pageTotal){

this.pageIndex = pageIndex;
this.pageSize = pageSize;
this.pageTotal = pageTotal;
}
@Override
public PageResult<TEntity> toResult(Query<TEntity> query, long pageIndex, long pageSize, List<Long> totalLines) {
EasyPageResult<TEntity> pageResult = query.toShardingPageResult(pageIndex, pageSize,totalLines);
public PageResult<TEntity> toResult(Query<TEntity> query) {
EasyPageResult<TEntity> pageResult = query.toPageResult(pageIndex, pageSize,pageTotal);
return new MyPageResult<>(pageResult.getTotal(),pageResult.getData());
}
}

0 comments on commit d17ae34

Please sign in to comment.