You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Test {
public static void main(final String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("META-INF/mybatisContext.xml");
OrderRepository orderRepository = applicationContext.getBean(OrderRepository.class);
List ls = orderRepository.selectAll();
System.out.println(ls);
}
}
调试代码发现,shardingJDBC在包装结果集时,根据mergeContext判断是不是要聚合,ResultSetFactory.getResultSet方法中
ShardingResultSets shardingResultSets = new ShardingResultSets(resultSets);
传入的resultSets有4个rs,获取到的shardingResultSets 只有一个,因为只有一个rs有数据,
ShardingResultSets.filterResultSets方法会过滤掉没有记录的rs
`
private List filterResultSets(final List resultSets) throws SQLException {
List result = new ArrayList<>(resultSets.size());
for (ResultSet each : resultSets) {
if (each.next()) {
result.add(new WrapperResultSet(each));
}
}
return result;
}
`
这样的话在shardingResultSets.getType()返回的是SINGLE
`
switch (shardingResultSets.getType()) {
case EMPTY:
return buildEmpty(resultSets);
case SINGLE:
return buildSingle(shardingResultSets);
case MULTIPLE:
return buildMultiple(shardingResultSets, mergeContext);
default:
throw new UnsupportedOperationException(shardingResultSets.getType().toString());
}
`
这样就不会去做合并结果集操作了
Please provide the reproduce example codes (such as github link) if possible.
The text was updated successfully, but these errors were encountered:
Please answer these questions before submitting your issue. Thanks!
Which version of Sharding-Jdbc do you using?
1.4.2
Expected behavior
分页查询,select * from t_order limit 2,2 路由多个分片,只有一个分片有数据,查询4条记录
Actual behavior
应该只返回2条记录
Steps to reproduce the behavior
sharding-jdbc-example-mybatis这个demo工程中,增加测试类
`
package com.dangdang.ddframe.rdb.sharding.example.jdbc;
import com.dangdang.ddframe.rdb.sharding.example.jdbc.entity.Order;
import com.dangdang.ddframe.rdb.sharding.example.jdbc.repository.OrderRepository;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.List;
public class Test {
public static void main(final String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("META-INF/mybatisContext.xml");
OrderRepository orderRepository = applicationContext.getBean(OrderRepository.class);
List ls = orderRepository.selectAll();
System.out.println(ls);
}
}
`
修改OrderMapper.xml最后一个查询,增加limit
`
修改数据库数据:
delete from ds_0.t_order_0;
delete from ds_0.t_order_1;
delete from ds_1.t_order_0;
delete from ds_1.t_order_1;
INSERT INTO
ds_0
.t_order_0
VALUES (1000, 10, 'INIT');INSERT INTO
ds_0
.t_order_0
VALUES (1002, 10, 'INIT');INSERT INTO
ds_0
.t_order_0
VALUES (1004, 10, 'INIT');INSERT INTO
ds_0
.t_order_0
VALUES (1006, 10, 'INIT');INSERT INTO
ds_0
.t_order_0
VALUES (1008, 10, 'INIT');`
执行打印结果有4条记录:
[order_id: 1000, user_id: 10, status: INIT, order_id: 1002, user_id: 10, status: INIT, order_id: 1004, user_id: 10, status: INIT, order_id: 1006, user_id: 10, status: INIT]
调试代码发现,shardingJDBC在包装结果集时,根据mergeContext判断是不是要聚合,ResultSetFactory.getResultSet方法中
ShardingResultSets shardingResultSets = new ShardingResultSets(resultSets);
传入的resultSets有4个rs,获取到的shardingResultSets 只有一个,因为只有一个rs有数据,
ShardingResultSets.filterResultSets方法会过滤掉没有记录的rs
`
private List filterResultSets(final List resultSets) throws SQLException {
List result = new ArrayList<>(resultSets.size());
for (ResultSet each : resultSets) {
if (each.next()) {
result.add(new WrapperResultSet(each));
}
}
return result;
}
`
这样的话在shardingResultSets.getType()返回的是SINGLE
`
switch (shardingResultSets.getType()) {
case EMPTY:
return buildEmpty(resultSets);
case SINGLE:
return buildSingle(shardingResultSets);
case MULTIPLE:
return buildMultiple(shardingResultSets, mergeContext);
default:
throw new UnsupportedOperationException(shardingResultSets.getType().toString());
}
`
这样就不会去做合并结果集操作了
Please provide the reproduce example codes (such as github link) if possible.
The text was updated successfully, but these errors were encountered: