Browse Source

修改包名

yufeng 3 years ago
parent
commit
9b02441d58

+ 3 - 3
README.md

@@ -3,12 +3,12 @@
3 3
 sharding-jdbc-test
4 4
 
5 5
 #### order分片规则
6
-1. order_code
7
-2. gmt_create
6
+1. order_code 取余
7
+2. gmt_create 按年分
8 8
 
9 9
 #### order_item分片规则同order
10 10
 
11
-#### 绑定 sharding.jdbc.config.sharding.binding-tables[0]
11
+#### 绑定 sharding.jdbc.config.sharding.binding-tables[0]
12 12
 可以使两个表join不需要进行笛卡尔积
13 13
 
14 14
 #### 详细配置

+ 4 - 0
src/main/java/com/huojutech/sharding/repository/OrderRepository.java

@@ -17,6 +17,8 @@
17 17
 
18 18
 package com.huojutech.sharding.repository;
19 19
 
20
+import java.util.List;
21
+
20 22
 import org.apache.ibatis.annotations.Mapper;
21 23
 
22 24
 import com.huojutech.sharding.entity.Order;
@@ -33,4 +35,6 @@ public interface OrderRepository {
33 35
     void delete(Long orderId);
34 36
     
35 37
     void dropTable();
38
+    
39
+    List<Order> queryByGmtCreate();
36 40
 }

+ 1 - 1
src/main/java/com/huojutech/sharding/service/DemoService.java

@@ -64,7 +64,7 @@ public class DemoService {
64 64
 //            item.setUserId(i);
65 65
 //            orderItemRepository.insert(item);
66 66
         }
67
-        System.out.println(orderItemRepository.selectAll());
67
+        System.out.println(orderRepository.queryByGmtCreate());
68 68
         System.out.println("2.Delete--------------");
69 69
 //        for (Long each : orderIds) {
70 70
 //            orderRepository.delete(each);

+ 2 - 2
src/main/resources/META-INF/mappers/OrderItemMapper.xml

@@ -1,7 +1,7 @@
1 1
 <?xml version="1.0" encoding="UTF-8" ?>
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
-<mapper namespace="io.shardingsphere.example.spring.boot.mybatis.repository.OrderItemRepository">
4
-    <resultMap id="baseResultMap" type="io.shardingsphere.example.spring.boot.mybatis.entity.OrderItem">
3
+<mapper namespace="com.huojutech.sharding.repository.OrderItemRepository">
4
+    <resultMap id="baseResultMap" type="com.huojutech.sharding.entity.OrderItem">
5 5
         <result column="order_item_id" property="orderItemId" jdbcType="INTEGER" />
6 6
         <result column="order_id" property="orderId" jdbcType="INTEGER" />
7 7
         <result column="user_id" property="userId" jdbcType="INTEGER" />

+ 10 - 1
src/main/resources/META-INF/mappers/OrderMapper.xml

@@ -1,6 +1,11 @@
1 1
 <?xml version="1.0" encoding="UTF-8" ?>
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
-<mapper namespace="io.shardingsphere.example.spring.boot.mybatis.repository.OrderRepository">
3
+<mapper namespace="com.huojutech.sharding.repository.OrderRepository">
4
+    <resultMap id="baseResultMap" type="com.huojutech.sharding.entity.Order">
5
+        <result column="order_id" property="orderId" jdbcType="INTEGER" />
6
+        <result column="user_id" property="userId" jdbcType="INTEGER" />
7
+    </resultMap>
8
+    
4 9
     <update id="createIfNotExistsTable">
5 10
         CREATE TABLE IF NOT EXISTS t_order 
6 11
         (order_id BIGINT AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50),
@@ -32,4 +37,8 @@
32 37
     <delete id="delete">
33 38
         DELETE FROM t_order WHERE order_id = #{orderId,jdbcType=INTEGER}
34 39
     </delete>
40
+    
41
+    <select id="queryByGmtCreate" resultMap="baseResultMap">
42
+        SELECT * FROM t_order where gmt_create > '2018-09-12 00:00:00'
43
+    </select>
35 44
 </mapper>

+ 1 - 1
src/main/resources/META-INF/mybatis-config.xml

@@ -7,7 +7,7 @@
7 7
         <!--<setting name="logImpl" value="STDOUT_LOGGING" />-->
8 8
     <!--</settings>-->
9 9
     <typeAliases>
10
-        <package name="io.shardingsphere.example.spring.boot.mybatis.entity"/>
10
+        <package name="com.huojutech.sharding.entity"/>
11 11
     </typeAliases>
12 12
     <mappers>
13 13
         <mapper resource="META-INF/mappers/OrderMapper.xml"/>

+ 4 - 4
src/main/resources/application-sharding.properties

@@ -12,11 +12,11 @@ sharding.jdbc.datasource.ds_0.password=123456
12 12
 #sharding.jdbc.config.sharding.default-key-generator-class-name= io.shardingsphere.example.spring.boot.mybatis.service.IDGenerator
13 13
 
14 14
 sharding.jdbc.config.sharding.tables.t_order.database-strategy.complex.sharding-columns=order_code,gmt_create
15
-sharding.jdbc.config.sharding.tables.t_order.database-strategy.complex.algorithm-class-name=io.shardingsphere.example.spring.boot.mybatis.algorithm.DatabaseShardingAlgorithm
15
+sharding.jdbc.config.sharding.tables.t_order.database-strategy.complex.algorithm-class-name=com.huojutech.sharding.algorithm.DatabaseShardingAlgorithm
16 16
 sharding.jdbc.config.sharding.tables.t_order.actual-data-nodes=ds_0.t_order_$->{2018..2019}_$->{0..1}
17 17
 sharding.jdbc.config.sharding.tables.t_order.table-strategy.complex.sharding-columns=order_code,gmt_create
18 18
 sharding.jdbc.config.sharding.tables.t_order.key-generator-column-name=order_id
19
-sharding.jdbc.config.sharding.tables.t_order.table-strategy.complex.algorithm-class-name=io.shardingsphere.example.spring.boot.mybatis.algorithm.MyPreciseShardingAlgorithm
19
+sharding.jdbc.config.sharding.tables.t_order.table-strategy.complex.algorithm-class-name=com.huojutech.sharding.algorithm.MyPreciseShardingAlgorithm
20 20
 
21 21
 #sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds_$->{0..1}.t_order_item_$->{0..1}
22 22
 #sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.inline.sharding-column=order_id
@@ -24,11 +24,11 @@ sharding.jdbc.config.sharding.tables.t_order.table-strategy.complex.algorithm-cl
24 24
 #sharding.jdbc.config.sharding.tables.t_order_item.key-generator-column-name=order_item_id
25 25
 
26 26
 sharding.jdbc.config.sharding.tables.t_order_item.database-strategy.complex.sharding-columns=order_code,gmt_create
27
-sharding.jdbc.config.sharding.tables.t_order_item.database-strategy.complex.algorithm-class-name=io.shardingsphere.example.spring.boot.mybatis.algorithm.DatabaseShardingAlgorithm
27
+sharding.jdbc.config.sharding.tables.t_order_item.database-strategy.complex.algorithm-class-name=com.huojutech.sharding.algorithm.DatabaseShardingAlgorithm
28 28
 sharding.jdbc.config.sharding.tables.t_order_item.actual-data-nodes=ds_0.t_order_item_$->{2018..2019}_$->{0..1}
29 29
 sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.complex.sharding-columns=order_code,gmt_create
30 30
 sharding.jdbc.config.sharding.tables.t_order_item.key-generator-column-name=order_item_id
31
-sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.complex.algorithm-class-name=io.shardingsphere.example.spring.boot.mybatis.algorithm.MyPreciseShardingAlgorithm
31
+sharding.jdbc.config.sharding.tables.t_order_item.table-strategy.complex.algorithm-class-name=com.huojutech.sharding.algorithm.MyPreciseShardingAlgorithm
32 32
 
33 33
 sharding.jdbc.config.sharding.binding-tables[0]= t_order,t_order_item
34 34