Commit bc5848e99b5a84db7afa8af78a5614bc51b1688d
1 parent
82894c34
Exists in
master
and in
2 other branches
optimized some code info
Showing
2 changed files
with
44 additions
and
22 deletions
Show diff stats
src/test/java/com/taover/repository/test/TestAutoconfigure.java
| ... | ... | @@ -8,23 +8,46 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 8 | 8 | import org.springframework.context.ConfigurableApplicationContext; |
| 9 | 9 | import org.springframework.scheduling.annotation.EnableScheduling; |
| 10 | 10 | |
| 11 | +import com.taover.repository.jdbctemplate.JdbcTemplateBroadcast; | |
| 11 | 12 | import com.taover.repository.jdbctemplate.JdbcTemplateWrapperTenant; |
| 12 | 13 | |
| 13 | 14 | @SpringBootApplication |
| 14 | 15 | @EnableScheduling |
| 15 | 16 | public class TestAutoconfigure { |
| 17 | + private static JdbcTemplateBroadcast jdbcTemplateBroadcast; | |
| 18 | + private static JdbcTemplateWrapperTenant jdbcTemplateWrapperTenant; | |
| 19 | + | |
| 20 | + | |
| 16 | 21 | public static void main(String args[]) { |
| 17 | 22 | ConfigurableApplicationContext context = SpringApplication.run(TestAutoconfigure.class, args); |
| 23 | + jdbcTemplateBroadcast = context.getBean(JdbcTemplateBroadcast.class); | |
| 24 | + jdbcTemplateWrapperTenant = context.getBean(JdbcTemplateWrapperTenant.class); | |
| 18 | 25 | |
| 19 | -// JdbcTemplateBroadcast jdbcTemplateB = context.getBean(JdbcTemplateBroadcast.class); | |
| 20 | -// System.out.println(jdbcTemplateB.queryForObject("select id from wxorder_order order by id desc limit 5 ", String.class, new String[]{"wxorder_order"})); | |
| 21 | - | |
| 22 | -// JdbcTemplateWrapperTenant jdbcTemplate = context.getBean(JdbcTemplateWrapperTenant.class); | |
| 23 | -// System.out.println(jdbcTemplate.queryForObject("select id from wxorder_order limit 1", Long.class, 1L)); | |
| 24 | -// System.out.println(jdbcTemplate.queryForList("select * from wxorder_order limit 1", 1L)); | |
| 25 | -// System.out.println(jdbcTemplate.queryForList("select * from wxorder_order limit 1", 2L)); | |
| 26 | -// System.out.println(jdbcTemplate.queryForList("select * from wxorder_order_express limit 1", 1L)); | |
| 26 | +// testBroadCast(); | |
| 27 | +// testSelectSubQuery(); | |
| 28 | + //select子查询包含分片表 | |
| 29 | + testSelectShardingSubQuery(); | |
| 30 | + //where中包含子查询 | |
| 31 | + testWhereSubquery(); | |
| 32 | + } | |
| 33 | + | |
| 34 | + private static void testSelectShardingSubQuery() { | |
| 35 | + String sql = " select wc.name,(select count(*) from wxorder_order where) as 'sumOrderNum' from wxorder_channel wc limit 3; "; | |
| 36 | + } | |
| 27 | 37 | |
| 38 | + public static void testWhereSubquery() { | |
| 39 | + | |
| 40 | + } | |
| 41 | + | |
| 42 | + public static void testBroadCast() { | |
| 43 | + System.out.println(jdbcTemplateBroadcast.queryForObject("select id from wxorder_order order by id desc limit 5 ", String.class, new String[]{"wxorder_order"})); | |
| 44 | + System.out.println(jdbcTemplateWrapperTenant.queryForObject("select id from wxorder_order limit 1", Long.class, 1L)); | |
| 45 | + System.out.println(jdbcTemplateWrapperTenant.queryForList("select * from wxorder_order limit 1", 1L)); | |
| 46 | + System.out.println(jdbcTemplateWrapperTenant.queryForList("select * from wxorder_order limit 1", 2L)); | |
| 47 | + System.out.println(jdbcTemplateWrapperTenant.queryForList("select * from wxorder_order_express limit 1", 1L)); | |
| 48 | + } | |
| 49 | + | |
| 50 | + public static void testSelectSubQuery() { | |
| 28 | 51 | String sql = " SELECT " |
| 29 | 52 | + " wog.`goods_number` AS saleNumber," |
| 30 | 53 | + " (SELECT sum(woe.`goods_number`) from `wxorder_order_express` as woe WHERE woe.order_goods_id = wog.id and woe.tenant_id=16) as deliveryGoodsNumber, " |
| ... | ... | @@ -48,8 +71,7 @@ public class TestAutoconfigure { |
| 48 | 71 | + " INNER JOIN wxorder_ware as ww on ww.id=wo.ware_id " |
| 49 | 72 | + " INNER JOIN wxorder_channel_goods as wcg on wcg.id = wog.channel_goods_id" |
| 50 | 73 | + " limit 10 "; |
| 51 | - JdbcTemplateWrapperTenant jdbcTemplate = context.getBean(JdbcTemplateWrapperTenant.class); | |
| 52 | - List<Map<String, Object>> data = jdbcTemplate.queryForList(sql, 16L); | |
| 74 | + List<Map<String, Object>> data = jdbcTemplateWrapperTenant.queryForList(sql, 16L); | |
| 53 | 75 | System.out.println(data); |
| 54 | 76 | } |
| 55 | 77 | } | ... | ... |
src/test/resources/application.properties
| ... | ... | @@ -13,7 +13,7 @@ spring.gson.serialize-nulls=true |
| 13 | 13 | spring.mvc.dispatch-options-request=true |
| 14 | 14 | |
| 15 | 15 | # shardingspere |
| 16 | -spring.shardingsphere.datasource.names=ds0 | |
| 16 | +spring.shardingsphere.datasource.names=ds1 | |
| 17 | 17 | spring.shardingsphere.datasource.common.type=com.alibaba.druid.pool.DruidDataSource |
| 18 | 18 | spring.shardingsphere.datasource.common.driver-class-name=com.mysql.cj.jdbc.Driver |
| 19 | 19 | spring.shardingsphere.datasource.ds0.url=jdbc:mysql://rdsifmezqifmezqo.mysql.rds.aliyuncs.com:3306/bzyun_wxorder?characterEncoding=UTF-8 |
| ... | ... | @@ -32,17 +32,17 @@ spring.shardingsphere.datasource.ds1.max-active=20 |
| 32 | 32 | spring.shardingsphere.datasource.ds1.min-idle=5 |
| 33 | 33 | spring.shardingsphere.datasource.ds1.max-wait=60000 |
| 34 | 34 | |
| 35 | -#spring.shardingsphere.rules.sharding.tables.wxorder_order.actual-data-nodes=ds0.wxorder_order | |
| 36 | -#spring.shardingsphere.rules.sharding.tables.wxorder_order.database-strategy.hint.algorithm-class-name=com.taover.repository.shardingsphere.ShardingDatabaseAlgorithmHint | |
| 37 | -#spring.shardingsphere.rules.sharding.tables.wxorder_order.table-strategy.hint.algorithm-class-name=com.taover.repository.shardingsphere.ShardingTableAlgorithmHint | |
| 38 | -#spring.shardingsphere.rules.sharding.tables.wxorder_order.key-generate-strategy.column=id | |
| 39 | -#spring.shardingsphere.rules.sharding.tables.wxorder_order.key-generate-strategy.key-generator-name=SNOWFLAKE-SELF | |
| 40 | - | |
| 41 | -#spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.type=INLINE | |
| 42 | -#spring.shardingsphere.rules.sharding.sharding-algorithms.database_inline.props.algorithm-expression=ds_0 | |
| 43 | -#spring.shardingsphere.rules.sharding.sharding-algorithms.table_inline.type=INLINE | |
| 44 | -#spring.shardingsphere.rules.sharding.sharding-algorithms.table_inline.props.algorithm-expression=wxorder_order | |
| 45 | -sql-show=true | |
| 35 | +spring.shardingsphere.rules.sharding.tables.wxorder_order.actual-data-nodes=ds0.wxorder_order | |
| 36 | +spring.shardingsphere.rules.sharding.tables.wxorder_order.database-strategy.hint.database_hint.sharding-algorithm-name=database_hint | |
| 37 | +spring.shardingsphere.rules.sharding.tables.wxorder_order.table-strategy.hint.table_hint.sharding-algorithm-name=table_hint | |
| 38 | +spring.shardingsphere.rules.sharding.tables.wxorder_order.key-generate-strategy.column=id | |
| 39 | +spring.shardingsphere.rules.sharding.tables.wxorder_order.key-generate-strategy.key-generator-name=SNOWFLAKE-SELF | |
| 40 | + | |
| 41 | +spring.shardingsphere.rules.sharding.sharding-algorithms.database_hint.type=HINT | |
| 42 | +spring.shardingsphere.rules.sharding.sharding-algorithms.database_hint.algorithm-class-name=com.taover.repository.shardingsphere.ShardingDatabaseAlgorithmHint | |
| 43 | +spring.shardingsphere.rules.sharding.sharding-algorithms.table_hint.type=HINT | |
| 44 | +spring.shardingsphere.rules.sharding.sharding-algorithms.table_hint.algorithm-class-name=com.taover.repository.shardingsphere.ShardingTableAlgorithmHint | |
| 45 | + | |
| 46 | 46 | taover.sharding.workerId=1 |
| 47 | 47 | taover.sharding.maxVibrationOffset=3 |
| 48 | 48 | taover.sharding.maxTolerateTimeDifferenceMilliseconds=1000 | ... | ... |