/*
*
* **
* 分库分表每个库都有一张user_login_log_0,user_login_log_1
* @return
* @throws SQLException
*
private DataSource buildDataSource() throws SQLException {
//设置分库映射
Map<String,DataSource> dataSourceMap = Collections.synchronizedMap(new HashMap<>());
//添加数据库
dataSourceMap.put("dbs_0",createDataSource("dbs_0"));
dataSourceMap.put("dbs_1",createDataSource("dbs_1"));
//设置默认数据库
DataSourceRule rule = new DataSourceRule(dataSourceMap,"dbs_0");
Map<String,DataSource> dataSourceMap0 = Collections.synchronizedMap(new HashMap<>());
dataSourceMap0.put("dbs_0",createDataSource("dbs_0"));
DataSourceRule rule0 = new DataSourceRule(dataSourceMap0);
Map<String,DataSource> dataSourceMap1 = Collections.synchronizedMap(new HashMap<>());
dataSourceMap1.put("dbs_1",createDataSource("dbs_1"));
DataSourceRule rule1 = new DataSourceRule(dataSourceMap1);
TableRule orderTableRule0 = TableRule.builder("user_login_log")
.actualTables(Arrays.asList("user_login_log_0"))
.dataSourceRule(rule0)
.generateKeyColumn("id")
.build();
TableRule orderTableRule1 = TableRule.builder("user_login_log")
.actualTables(Arrays.asList("user_login_log_1"))
.dataSourceRule(rule1)
.generateKeyColumn("id")
.build();
TableRule orderTableRuleAll = TableRule.builder("user_login_log")
.actualTables(Arrays.asList("user_login_log_0","user_login_log_1"))
.dataSourceRule(rule)
.generateKeyColumn("id")
.build();
ShardingRule shardingRule = ShardingRule.builder()
.dataSourceRule(rule)
.tableRules(Arrays.asList(orderTableRuleAll))
.databaseShardingStrategy(new DatabaseShardingStrategy("user_id",new ModuloDatabaseShardingAlgorithm()))
.tableShardingStrategy(new TableShardingStrategy("id",new ModuloTableShardingAlgorithm()))
.build();
Properties props=new Properties();
props.put("sql.show", "true");
DataSource dataSource = ShardingDataSourceFactory.createDataSource(shardingRule, props);
return dataSource;
}
---------------分库分表---------------------------
1. insert SQL 日志
2018-06-07 16:23:17.247 INFO 8928 --- [ main] Sharding-JDBC-SQL : Logic SQL: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log userloginl0_ where userloginl0_.id=?
2018-06-07 16:23:17.247 INFO 8928 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.of(userloginl0_))]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=EQUAL, positionValueMap={}, positionIndexMap={0=0})}), sqlTokens=[TableToken(beginPosition=281, originalLiterals=user_login_log)], parametersIndex=1)), containStar=false, selectListLastPosition=276, groupByLastPosition=0, items=[CommonSelectItem(expression=userloginl0_.login_sorece, alias=Optional.of(login_so5_1_0_)), CommonSelectItem(expression=userloginl0_.login_time, alias=Optional.of(login_ti6_1_0_)), CommonSelectItem(expression=userloginl0_.ip, alias=Optional.of(ip4_1_0_)), CommonSelectItem(expression=userloginl0_.id, alias=Optional.of(id1_1_0_)), CommonSelectItem(expression=userloginl0_.user_id, alias=Optional.of(user_id7_1_0_)), CommonSelectItem(expression=userloginl0_.device_mac, alias=Optional.of(device_m2_1_0_)), CommonSelectItem(expression=userloginl0_.device_os, alias=Optional.of(device_o3_1_0_))], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 16:23:17.247 INFO 8928 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log_1 userloginl0_ where userloginl0_.id=? ::: [10019]
2018-06-07 16:23:17.247 INFO 8928 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log_1 userloginl0_ where userloginl0_.id=? ::: [10019]
Hibernate: insert into user_login_log (device_mac, device_os, ip, login_sorece, login_time, user_id, id) values (?, ?, ?, ?, ?, ?, ?)
2018-06-07 16:23:17.252 INFO 8928 --- [ main] Sharding-JDBC-SQL : Logic SQL: insert into user_login_log (device_mac, device_os, ip, login_sorece, login_time, user_id, id) values (?, ?, ?, ?, ?, ?, ?)
2018-06-07 16:23:17.252 INFO 8928 --- [ main] Sharding-JDBC-SQL : SQLStatement: InsertStatement(columns=[Column(name=device_mac, tableName=user_login_log), Column(name=device_os, tableName=user_login_log), Column(name=ip, tableName=user_login_log), Column(name=login_sorece, tableName=user_login_log), Column(name=login_time, tableName=user_login_log), Column(name=user_id, tableName=user_login_log), Column(name=id, tableName=user_login_log)], multipleConditions=[], columnsListLastPosition=92, generateKeyColumnIndex=6, afterValuesPosition=101, valuesListLastPosition=121, generatedKey=GeneratedKey(column=id, index=6, value=null))
2018-06-07 16:23:17.252 INFO 8928 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: insert into user_login_log_1 (device_mac, device_os, ip, login_sorece, login_time, user_id, id) values (?, ?, ?, ?, ?, ?, ?) ::: [null, null, null, null, null, 10019, 10019]
add
2. repository.findOne(10010L);
2018-06-07 16:41:26.307 INFO 3760 --- [ main] Sharding-JDBC-SQL : Logic SQL: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log userloginl0_ where userloginl0_.id=?
2018-06-07 16:41:26.307 INFO 3760 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.of(userloginl0_))]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=EQUAL, positionValueMap={}, positionIndexMap={0=0})}), sqlTokens=[TableToken(beginPosition=281, originalLiterals=user_login_log)], parametersIndex=1)), containStar=false, selectListLastPosition=276, groupByLastPosition=0, items=[CommonSelectItem(expression=userloginl0_.login_time, alias=Optional.of(login_ti6_1_0_)), CommonSelectItem(expression=userloginl0_.user_id, alias=Optional.of(user_id7_1_0_)), CommonSelectItem(expression=userloginl0_.id, alias=Optional.of(id1_1_0_)), CommonSelectItem(expression=userloginl0_.device_os, alias=Optional.of(device_o3_1_0_)), CommonSelectItem(expression=userloginl0_.ip, alias=Optional.of(ip4_1_0_)), CommonSelectItem(expression=userloginl0_.login_sorece, alias=Optional.of(login_so5_1_0_)), CommonSelectItem(expression=userloginl0_.device_mac, alias=Optional.of(device_m2_1_0_))], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 16:41:26.308 INFO 3760 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log_0 userloginl0_ where userloginl0_.id=? ::: [10010]
2018-06-07 16:41:26.308 INFO 3760 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log_0 userloginl0_ where userloginl0_.id=? ::: [10010]
3. repository.delete(10010L);
2018-06-07 16:43:04.687 INFO 1892 --- [ main] Sharding-JDBC-SQL : Logic SQL: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log userloginl0_ where userloginl0_.id=?
2018-06-07 16:43:04.688 INFO 1892 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.of(userloginl0_))]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=EQUAL, positionValueMap={}, positionIndexMap={0=0})}), sqlTokens=[TableToken(beginPosition=281, originalLiterals=user_login_log)], parametersIndex=1)), containStar=false, selectListLastPosition=276, groupByLastPosition=0, items=[CommonSelectItem(expression=userloginl0_.login_time, alias=Optional.of(login_ti6_1_0_)), CommonSelectItem(expression=userloginl0_.user_id, alias=Optional.of(user_id7_1_0_)), CommonSelectItem(expression=userloginl0_.device_mac, alias=Optional.of(device_m2_1_0_)), CommonSelectItem(expression=userloginl0_.id, alias=Optional.of(id1_1_0_)), CommonSelectItem(expression=userloginl0_.device_os, alias=Optional.of(device_o3_1_0_)), CommonSelectItem(expression=userloginl0_.ip, alias=Optional.of(ip4_1_0_)), CommonSelectItem(expression=userloginl0_.login_sorece, alias=Optional.of(login_so5_1_0_))], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 16:43:04.688 INFO 1892 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log_0 userloginl0_ where userloginl0_.id=? ::: [10010]
2018-06-07 16:43:04.688 INFO 1892 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log_0 userloginl0_ where userloginl0_.id=? ::: [10010]
Hibernate: delete from user_login_log where id=?
2018-06-07 16:43:04.806 INFO 1892 --- [ main] Sharding-JDBC-SQL : Logic SQL: delete from user_login_log where id=?
2018-06-07 16:43:04.806 INFO 1892 --- [ main] Sharding-JDBC-SQL : SQLStatement: DMLStatement(super=AbstractSQLStatement(type=DML, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.absent())]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=EQUAL, positionValueMap={}, positionIndexMap={0=0})}), sqlTokens=[TableToken(beginPosition=12, originalLiterals=user_login_log)], parametersIndex=1))
2018-06-07 16:43:04.806 INFO 1892 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: delete from user_login_log_0 where id=? ::: [10010]
2018-06-07 16:43:04.806 INFO 1892 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: delete from user_login_log_0 where id=? ::: [10010]
4.repository.count(*);
2018-06-07 16:44:34.506 INFO 15108 --- [ main] Sharding-JDBC-SQL : Logic SQL: select count(*) as col_0_0_ from user_login_log userloginl0_
2018-06-07 16:44:34.506 INFO 15108 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.of(userloginl0_))]), conditions=Conditions(conditions={}), sqlTokens=[TableToken(beginPosition=33, originalLiterals=user_login_log)], parametersIndex=0)), containStar=false, selectListLastPosition=28, groupByLastPosition=0, items=[AggregationSelectItem(type=COUNT, innerExpression=(*), alias=Optional.of(col_0_0_), derivedAggregationSelectItems=[], index=-1)], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 16:44:34.507 INFO 15108 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select count(*) as col_0_0_ from user_login_log_0 userloginl0_
2018-06-07 16:44:34.507 INFO 15108 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select count(*) as col_0_0_ from user_login_log_1 userloginl0_
2018-06-07 16:44:34.508 INFO 15108 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: select count(*) as col_0_0_ from user_login_log_0 userloginl0_
2018-06-07 16:44:34.508 INFO 15108 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: select count(*) as col_0_0_ from user_login_log_1 userloginl0_
/**
* 只分库每个库只有一张user_login_log
* @return
* @throws SQLException
*/
private DataSource buildDataSource() throws SQLException {
//设置分库映射
Map<String,DataSource> dataSourceMap = Collections.synchronizedMap(new HashMap<>());
//添加数据库
dataSourceMap.put("dbs_0",createDataSource("dbs_0"));
dataSourceMap.put("dbs_1",createDataSource("dbs_1"));
//设置默认数据库
DataSourceRule rule = new DataSourceRule(dataSourceMap,"dbs_1");
TableRule orderTableRuleAll = TableRule.builder("user_login_log")
.actualTables(Arrays.asList("user_login_log"))
.dataSourceRule(rule)
.generateKeyColumn("id")
.build();
ShardingRule shardingRule = ShardingRule.builder()
.dataSourceRule(rule)
.tableRules(Arrays.asList(orderTableRuleAll))
.databaseShardingStrategy(new DatabaseShardingStrategy("id",new ModuloDatabaseShardingAlgorithm()))
.build();
Properties props=new Properties();
props.put("sql.show", "true");
DataSource dataSource = ShardingDataSourceFactory.createDataSource(shardingRule, props);
return dataSource;
}
---------------只分库---------------------------
repository.findOne(10010L);
2018-06-07 17:21:51.758 INFO 13600 --- [ main] Sharding-JDBC-SQL : Logic SQL: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log userloginl0_ where userloginl0_.id=?
2018-06-07 17:21:51.758 INFO 13600 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.of(userloginl0_))]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=EQUAL, positionValueMap={}, positionIndexMap={0=0})}), sqlTokens=[TableToken(beginPosition=281, originalLiterals=user_login_log)], parametersIndex=1)), containStar=false, selectListLastPosition=276, groupByLastPosition=0, items=[CommonSelectItem(expression=userloginl0_.login_sorece, alias=Optional.of(login_so5_1_0_)), CommonSelectItem(expression=userloginl0_.id, alias=Optional.of(id1_1_0_)), CommonSelectItem(expression=userloginl0_.ip, alias=Optional.of(ip4_1_0_)), CommonSelectItem(expression=userloginl0_.user_id, alias=Optional.of(user_id7_1_0_)), CommonSelectItem(expression=userloginl0_.device_os, alias=Optional.of(device_o3_1_0_)), CommonSelectItem(expression=userloginl0_.device_mac, alias=Optional.of(device_m2_1_0_)), CommonSelectItem(expression=userloginl0_.login_time, alias=Optional.of(login_ti6_1_0_))], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 17:21:51.759 INFO 13600 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log userloginl0_ where userloginl0_.id=? ::: [10010]
repository.getCount();
2018-06-07 17:23:23.785 INFO 15040 --- [ main] Sharding-JDBC-SQL : Logic SQL: select count(*) from user_login_log
2018-06-07 17:23:23.785 INFO 15040 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.absent())]), conditions=Conditions(conditions={}), sqlTokens=[TableToken(beginPosition=21, originalLiterals=user_login_log)], parametersIndex=0)), containStar=false, selectListLastPosition=16, groupByLastPosition=0, items=[AggregationSelectItem(type=COUNT, innerExpression=(*), alias=Optional.absent(), derivedAggregationSelectItems=[], index=-1)], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 17:23:23.785 INFO 15040 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select count(*) from user_login_log
2018-06-07 17:23:23.785 INFO 15040 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: select count(*) from user_login_log
repository.findAll(Lists.newArrayList(10010L,10011L));
2018-06-07 17:24:02.834 INFO 11508 --- [ main] Sharding-JDBC-SQL : Logic SQL: select userloginl0_.id as id1_1_, userloginl0_.device_mac as device_m2_1_, userloginl0_.device_os as device_o3_1_, userloginl0_.ip as ip4_1_, userloginl0_.login_sorece as login_so5_1_, userloginl0_.login_time as login_ti6_1_, userloginl0_.user_id as user_id7_1_ from user_login_log userloginl0_ where userloginl0_.id in (? , ?)
2018-06-07 17:24:02.834 INFO 11508 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.of(userloginl0_))]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=IN, positionValueMap={}, positionIndexMap={0=0, 1=1})}), sqlTokens=[TableToken(beginPosition=267, originalLiterals=user_login_log)], parametersIndex=2)), containStar=false, selectListLastPosition=262, groupByLastPosition=0, items=[CommonSelectItem(expression=userloginl0_.device_mac, alias=Optional.of(device_m2_1_)), CommonSelectItem(expression=userloginl0_.id, alias=Optional.of(id1_1_)), CommonSelectItem(expression=userloginl0_.device_os, alias=Optional.of(device_o3_1_)), CommonSelectItem(expression=userloginl0_.login_time, alias=Optional.of(login_ti6_1_)), CommonSelectItem(expression=userloginl0_.user_id, alias=Optional.of(user_id7_1_)), CommonSelectItem(expression=userloginl0_.login_sorece, alias=Optional.of(login_so5_1_)), CommonSelectItem(expression=userloginl0_.ip, alias=Optional.of(ip4_1_))], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 17:24:02.835 INFO 11508 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select userloginl0_.id as id1_1_, userloginl0_.device_mac as device_m2_1_, userloginl0_.device_os as device_o3_1_, userloginl0_.ip as ip4_1_, userloginl0_.login_sorece as login_so5_1_, userloginl0_.login_time as login_ti6_1_, userloginl0_.user_id as user_id7_1_ from user_login_log userloginl0_ where userloginl0_.id in (? , ?) ::: [10010, 10011]
2018-06-07 17:24:02.835 INFO 11508 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: select userloginl0_.id as id1_1_, userloginl0_.device_mac as device_m2_1_, userloginl0_.device_os as device_o3_1_, userloginl0_.ip as ip4_1_, userloginl0_.login_sorece as login_so5_1_, userloginl0_.login_time as login_ti6_1_, userloginl0_.user_id as user_id7_1_ from user_login_log userloginl0_ where userloginl0_.id in (? , ?) ::: [10010, 10011]
2018-06-
repository.findAll(Lists.newArrayList(10010L,10012L));
2018-06-07 17:38:27.843 INFO 8708 --- [ main] Sharding-JDBC-SQL : Logic SQL: select userloginl0_.id as id1_1_, userloginl0_.device_mac as device_m2_1_, userloginl0_.device_os as device_o3_1_, userloginl0_.ip as ip4_1_, userloginl0_.login_sorece as login_so5_1_, userloginl0_.login_time as login_ti6_1_, userloginl0_.user_id as user_id7_1_ from user_login_log userloginl0_ where userloginl0_.id in (? , ?)
2018-06-07 17:38:27.843 INFO 8708 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.of(userloginl0_))]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=IN, positionValueMap={}, positionIndexMap={0=0, 1=1})}), sqlTokens=[TableToken(beginPosition=267, originalLiterals=user_login_log)], parametersIndex=2)), containStar=false, selectListLastPosition=262, groupByLastPosition=0, items=[CommonSelectItem(expression=userloginl0_.id, alias=Optional.of(id1_1_)), CommonSelectItem(expression=userloginl0_.login_time, alias=Optional.of(login_ti6_1_)), CommonSelectItem(expression=userloginl0_.device_mac, alias=Optional.of(device_m2_1_)), CommonSelectItem(expression=userloginl0_.login_sorece, alias=Optional.of(login_so5_1_)), CommonSelectItem(expression=userloginl0_.device_os, alias=Optional.of(device_o3_1_)), CommonSelectItem(expression=userloginl0_.ip, alias=Optional.of(ip4_1_)), CommonSelectItem(expression=userloginl0_.user_id, alias=Optional.of(user_id7_1_))], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 17:38:27.843 INFO 8708 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select userloginl0_.id as id1_1_, userloginl0_.device_mac as device_m2_1_, userloginl0_.device_os as device_o3_1_, userloginl0_.ip as ip4_1_, userloginl0_.login_sorece as login_so5_1_, userloginl0_.login_time as login_ti6_1_, userloginl0_.user_id as user_id7_1_ from user_login_log userloginl0_ where userloginl0_.id in (? , ?) ::: [10010, 100112]
201
repository.delete(10010L);
2018-06-07 17:24:26.418 INFO 9284 --- [ main] Sharding-JDBC-SQL : Logic SQL: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log userloginl0_ where userloginl0_.id=?
2018-06-07 17:24:26.418 INFO 9284 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.of(userloginl0_))]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=EQUAL, positionValueMap={}, positionIndexMap={0=0})}), sqlTokens=[TableToken(beginPosition=281, originalLiterals=user_login_log)], parametersIndex=1)), containStar=false, selectListLastPosition=276, groupByLastPosition=0, items=[CommonSelectItem(expression=userloginl0_.id, alias=Optional.of(id1_1_0_)), CommonSelectItem(expression=userloginl0_.login_sorece, alias=Optional.of(login_so5_1_0_)), CommonSelectItem(expression=userloginl0_.user_id, alias=Optional.of(user_id7_1_0_)), CommonSelectItem(expression=userloginl0_.device_os, alias=Optional.of(device_o3_1_0_)), CommonSelectItem(expression=userloginl0_.login_time, alias=Optional.of(login_ti6_1_0_)), CommonSelectItem(expression=userloginl0_.ip, alias=Optional.of(ip4_1_0_)), CommonSelectItem(expression=userloginl0_.device_mac, alias=Optional.of(device_m2_1_0_))], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 17:24:26.418 INFO 9284 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select userloginl0_.id as id1_1_0_, userloginl0_.device_mac as device_m2_1_0_, userloginl0_.device_os as device_o3_1_0_, userloginl0_.ip as ip4_1_0_, userloginl0_.login_sorece as login_so5_1_0_, userloginl0_.login_time as login_ti6_1_0_, userloginl0_.user_id as user_id7_1_0_ from user_login_log userloginl0_ where userloginl0_.id=? ::: [10010]
Hibernate: delete from user_login_log where id=?
2018-06-07 17:24:26.565 INFO 9284 --- [ main] Sharding-JDBC-SQL : Logic SQL: delete from user_login_log where id=?
2018-06-07 17:24:26.566 INFO 9284 --- [ main] Sharding-JDBC-SQL : SQLStatement: DMLStatement(super=AbstractSQLStatement(type=DML, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.absent())]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=EQUAL, positionValueMap={}, positionIndexMap={0=0})}), sqlTokens=[TableToken(beginPosition=12, originalLiterals=user_login_log)], parametersIndex=1))
2018-06-07 17:24:26.566 INFO 9284 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: delete from user_login_log where id=? ::: [10010]
2018-06-07 17:24:26.
---------查询没有分片的字段---------
select id from user_login_log where user_id=5
2018-06-07 17:27:37.480 INFO 14300 --- [ main] Sharding-JDBC-SQL : Logic SQL: select id from user_login_log where user_id=5
2018-06-07 17:27:37.481 INFO 14300 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.absent())]), conditions=Conditions(conditions={}), sqlTokens=[TableToken(beginPosition=15, originalLiterals=user_login_log)], parametersIndex=0)), containStar=false, selectListLastPosition=10, groupByLastPosition=0, items=[CommonSelectItem(expression=id, alias=Optional.absent())], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 17:27:37.481 INFO 14300 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_0 ::: select id from user_login_log where user_id=5
2018-06-07 17:27:37.481 INFO 14300 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: select id from user_login_log where user_id=5
---------查询有分片字段和没有分片字段----------
2018-06-07 17:37:16.820 INFO 14164 --- [ main] Sharding-JDBC-SQL : Logic SQL: select id from user_login_log where user_id=5 and id = ?
2018-06-07 17:37:16.820 INFO 14164 --- [ main] Sharding-JDBC-SQL : SQLStatement: SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, tables=Tables(tables=[Table(name=user_login_log, alias=Optional.absent())]), conditions=Conditions(conditions={Column(name=id, tableName=user_login_log)=Condition(column=Column(name=id, tableName=user_login_log), operator=EQUAL, positionValueMap={}, positionIndexMap={0=0})}), sqlTokens=[TableToken(beginPosition=15, originalLiterals=user_login_log)], parametersIndex=1)), containStar=false, selectListLastPosition=10, groupByLastPosition=0, items=[CommonSelectItem(expression=id, alias=Optional.absent())], groupByItems=[], orderByItems=[], limit=null, subQueryStatement=null)
2018-06-07 17:37:16.821 INFO 14164 --- [ main] Sharding-JDBC-SQL : Actual SQL: dbs_1 ::: select id from user_login_log where user_id=5 and id = ? ::: [10011]