├── README.md
├── src
├── test
│ └── java
│ │ ├── BaseTest.java
│ │ └── com
│ │ └── lc
│ │ └── sharding
│ │ └── util
│ │ └── UniqueIDUtilsTest.java
└── main
│ ├── resources
│ ├── mybatis
│ │ └── mybatis-config.xml
│ ├── config
│ │ ├── jdbc.properties
│ │ └── spring-datasource.xml
│ ├── applicationContext.xml
│ ├── log4j.xml
│ └── xmlmapper
│ │ └── TOrderMapper.xml
│ └── java
│ └── com
│ └── lc
│ └── sharding
│ ├── mybatismapper
│ └── TOrderMapper.java
│ ├── pojo
│ ├── TOrder.java
│ └── TOrderExample.java
│ ├── init
│ └── Inits.java
│ ├── algorithm
│ └── MultipleKeysTableShardingAlgorithmImpl.java
│ └── util
│ └── UniqueIDUtils.java
├── .gitignore
└── pom.xml
/README.md:
--------------------------------------------------------------------------------
1 | # study-sharding
2 | sharding-jdbc学习
3 |
--------------------------------------------------------------------------------
/src/test/java/BaseTest.java:
--------------------------------------------------------------------------------
1 | import org.junit.Assert;
2 | import org.junit.Test;
3 |
4 | import java.time.LocalDate;
5 |
6 | public class BaseTest {
7 | @Test
8 | public void test() {
9 | Assert.assertTrue("这只是一个测试!", LocalDate.now().getYear() < Integer.MAX_VALUE);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/resources/mybatis/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/main/resources/config/jdbc.properties:
--------------------------------------------------------------------------------
1 | # jdbc
2 | jdbc.url.112=jdbc:mysql://x.x.x.x:3306/database_112?useSSL=false
3 | jdbc.url.103=jdbc:mysql://x.x.x.x:3306/database_103?useSSL=false
4 | jdbc.url.slave.112=jdbc:mysql://x.x.x.x:3306/database_slave_112?useSSL=false
5 | jdbc.url.slave.103=jdbc:mysql://x.x.x.x:3306/database_slave_103?useSSL=false
6 |
7 | jdbc.username=root
8 | jdbc.password=Root@37-18-28
9 | jdbc.maxActive=100
10 | jdbc.maxWait=60000
11 | jdbc.minIdle=5
12 | jdbc.initial.size=5
--------------------------------------------------------------------------------
/src/main/java/com/lc/sharding/mybatismapper/TOrderMapper.java:
--------------------------------------------------------------------------------
1 | package com.lc.sharding.mybatismapper;
2 |
3 | import com.lc.sharding.pojo.TOrder;
4 | import com.lc.sharding.pojo.TOrderExample;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import java.util.List;
8 |
9 | public interface TOrderMapper {
10 | int countByExample(TOrderExample example);
11 |
12 | int deleteByExample(TOrderExample example);
13 |
14 | int insert(TOrder record);
15 |
16 | int insertSelective(TOrder record);
17 |
18 | List selectByExample(TOrderExample example);
19 |
20 | int updateByExampleSelective(@Param("record") TOrder record, @Param("example") TOrderExample example);
21 |
22 | int updateByExample(@Param("record") TOrder record, @Param("example") TOrderExample example);
23 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # maven ignore
2 | target/
3 | *.jar
4 | *.war
5 | *.zip
6 | *.tar
7 | *.tar.gz
8 |
9 | # eclipse ignore
10 | .settings/
11 | .project
12 | .classpath
13 |
14 | # idea ignore
15 | .idea/
16 | *.ipr
17 | *.iml
18 | *.iws
19 |
20 | # package files ignore
21 | *.jar
22 | *.war
23 | *.ear
24 | *.zip
25 | *.tar.gz
26 | *.rar
27 |
28 | # mobile tools for java (J2ME) ignore
29 | .mtj.tmp/
30 |
31 | # compiled class file ignore
32 | *.class
33 |
34 | # log file ignore
35 | *.log
36 |
37 | # blueJ files ignore
38 | *.ctxt
39 |
40 | # other ignore
41 | *.log
42 | *.cache
43 | *.diff
44 | *.patch
45 | *.tmp
46 | *.java~
47 | *.properties~
48 | *.xml~
49 |
50 | # system ignore
51 | .DS_Store
52 | Thumbs.db
53 |
54 | # virtual machine crash logs ignore, see http://www.java.com/en/download/help/error_hotspot.xml
55 | hs_err_pid*
56 |
--------------------------------------------------------------------------------
/src/main/java/com/lc/sharding/pojo/TOrder.java:
--------------------------------------------------------------------------------
1 | package com.lc.sharding.pojo;
2 |
3 | public class TOrder {
4 | private Long id;
5 |
6 | private Long orderId;
7 |
8 | private Long userId;
9 |
10 | private Long businessId;
11 |
12 | public Long getId() {
13 | return id;
14 | }
15 |
16 | public void setId(Long id) {
17 | this.id = id;
18 | }
19 |
20 | public Long getOrderId() {
21 | return orderId;
22 | }
23 |
24 | public void setOrderId(Long orderId) {
25 | this.orderId = orderId;
26 | }
27 |
28 | public Long getUserId() {
29 | return userId;
30 | }
31 |
32 | public void setUserId(Long userId) {
33 | this.userId = userId;
34 | }
35 |
36 | public Long getBusinessId() {
37 | return businessId;
38 | }
39 |
40 | public void setBusinessId(Long businessId) {
41 | this.businessId = businessId;
42 | }
43 | }
--------------------------------------------------------------------------------
/src/main/java/com/lc/sharding/init/Inits.java:
--------------------------------------------------------------------------------
1 | package com.lc.sharding.init;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.ClassPathXmlApplicationContext;
5 |
6 | /**
7 | * @author zhangguoping
8 | * @version V1.0
9 | * @date 2017-04-09 16:51
10 | */
11 | public class Inits {
12 |
13 |
14 | private static volatile ApplicationContext beanFactory = null;
15 |
16 | public void init() throws Exception {
17 | initSpring();
18 | }
19 |
20 | /**
21 | * 初始化Spring
22 | */
23 | public static void initSpring() {
24 | if (null == beanFactory) {
25 | synchronized (Inits.class) {
26 | if (null == beanFactory) {
27 | try {
28 | beanFactory = new ClassPathXmlApplicationContext("applicationContext.xml");
29 | } catch (Exception e) {
30 |
31 | }
32 | }
33 | }
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/lc/sharding/algorithm/MultipleKeysTableShardingAlgorithmImpl.java:
--------------------------------------------------------------------------------
1 | package com.lc.sharding.algorithm;
2 |
3 | import com.dangdang.ddframe.rdb.sharding.api.ShardingValue;
4 | import com.dangdang.ddframe.rdb.sharding.api.strategy.table.MultipleKeysTableShardingAlgorithm;
5 |
6 | import java.util.ArrayList;
7 | import java.util.Collection;
8 | import java.util.List;
9 |
10 | /**
11 | * Created by wanghh on 2018-7-26.
12 | */
13 | public class MultipleKeysTableShardingAlgorithmImpl implements MultipleKeysTableShardingAlgorithm {
14 | public Collection doSharding(Collection tableNames, Collection> shardingValues) {
15 | List shardingSuffix = new ArrayList();
16 | long partId = 0;
17 | for (ShardingValue value : shardingValues) {
18 | if (value.getColumnName().equals("user_id")) {
19 | partId = ((Long) value.getValue()) % 4;
20 | break;
21 | } else if (value.getColumnName().equals("order_id")) {
22 | partId = ((Long) value.getValue()) % 4;
23 | break;
24 | }
25 | }
26 | for (String name : tableNames) {
27 | if (name.endsWith(partId + "")) {
28 | shardingSuffix.add(name);
29 | return shardingSuffix;
30 | }
31 | }
32 | return shardingSuffix;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
13 |
14 |
15 |
16 | classpath:/config/jdbc.properties
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/test/java/com/lc/sharding/util/UniqueIDUtilsTest.java:
--------------------------------------------------------------------------------
1 | package com.lc.sharding.util;
2 |
3 |
4 | import com.lc.sharding.init.Inits;
5 | import com.lc.sharding.mybatismapper.TOrderMapper;
6 | import com.lc.sharding.pojo.TOrder;
7 | import com.lc.sharding.pojo.TOrderExample;
8 | import org.apache.commons.collections4.CollectionUtils;
9 | import org.junit.Before;
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.test.context.ContextConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 | import java.util.List;
17 |
18 |
19 | /**
20 | * Created by wanghh on 2018-7-25.
21 | */
22 | @RunWith(SpringJUnit4ClassRunner.class) // 使用junit4进行测试
23 | @ContextConfiguration({"classpath:applicationContext.xml"}) // 加载配置文件*/
24 | public class UniqueIDUtilsTest {
25 | @Autowired
26 | private TOrderMapper tOrderMapper;
27 |
28 | @Before
29 | public void init() throws Exception {
30 | new Inits().init();
31 | }
32 |
33 | @Test
34 | public void bulidOrderIdTest() {
35 |
36 | UniqueIDUtils uniqueIDUtils = new UniqueIDUtils();
37 | TOrder tOrder = new TOrder();
38 | tOrder.setBusinessId(112L);
39 | long userId = 10000001;
40 | for (int i = 0; i < 64; i++) {
41 | tOrder.setUserId(userId + i);
42 | long orderId = uniqueIDUtils.bulidOrderId(tOrder.getUserId());
43 | System.out.println("第" + (i + 1) + "次userId=" + Long.toBinaryString(tOrder.getUserId()));
44 | System.out.println("第" + (i + 1) + "次orderId=" + Long.toBinaryString(orderId));
45 | tOrder.setOrderId(orderId);
46 | tOrder.setId(orderId);
47 | int result = tOrderMapper.insert(tOrder);
48 | }
49 |
50 | }
51 |
52 | @Test
53 | public void selectTest() {
54 | TOrderExample example = new TOrderExample();
55 | example.createCriteria().andOrderIdEqualTo(149917559837785907L);//存在从库中
56 | List list = tOrderMapper.selectByExample(example);
57 | System.out.println("订单id:" + (list.size() > 0 ? true : false));
58 |
59 | TOrderExample tOrderExampleUserId = new TOrderExample();
60 | tOrderExampleUserId.createCriteria().andUserIdEqualTo(9000019L);//存在主库中
61 | list = tOrderMapper.selectByExample(tOrderExampleUserId);
62 | System.out.println("user_id:" + (list.size() > 0? true : false));
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/src/main/java/com/lc/sharding/util/UniqueIDUtils.java:
--------------------------------------------------------------------------------
1 | package com.lc.sharding.util;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import java.net.InetAddress;
7 |
8 | public final class UniqueIDUtils {
9 | private static final Logger logger = LoggerFactory.getLogger(UniqueIDUtils.class);
10 | // 取IP地址最后一段作为多机分隔段
11 | private static long SERVER_ID = 255L;
12 |
13 | /**
14 | * 数据库id
15 | */
16 | private static long DB_ID = 63;
17 |
18 | /**
19 | * 序列号
20 | */
21 | private long sequence;
22 |
23 | /**
24 | * 开始时间戳
25 | */
26 | private final long beginTime = 1514736000000L;
27 |
28 | /**
29 | * 服务器个数比特位个数
30 | */
31 | private final long serverBits = 8L;
32 |
33 | /**
34 | * 数据库个数比特位个数
35 | */
36 | private final long dbBits = 6L;
37 | /**
38 | * 序列号比特位个数
39 | */
40 | private final long sequenceBits = 5L;
41 |
42 | /**
43 | * 服务器最大个数
44 | */
45 | private final long maxServerCount = -1L ^ (-1L << serverBits);
46 | /**
47 | * 数据库最大个数
48 | */
49 | private final long maxDbCount = -1L ^ (-1L << dbBits);
50 |
51 |
52 | private final long sequenceMask = -1 ^ (-1L << sequenceBits);
53 |
54 | /**
55 | * 数据库位移量
56 | */
57 | private final long dbShift = sequenceBits;
58 |
59 | /**
60 | * 服务器位移量
61 | */
62 | private final long serverShift = dbShift + dbBits;
63 |
64 | /**
65 | * 时间戳位移量
66 | */
67 | private final long timeStampLeftShift = serverShift + serverBits;
68 |
69 | /**
70 | * 上次生成id的时间戳
71 | */
72 | private long lastTimeStamp = -1L;
73 |
74 | static {
75 | try {
76 | String hostAddress = InetAddress.getLocalHost().getHostAddress();
77 | String[] nums = hostAddress.split("\\.");
78 | SERVER_ID = Long.parseLong(nums[3]);
79 | } catch (Exception ex) {
80 | logger.error("UniqueIDUtils init Exception, Default SERVER_ID = " + SERVER_ID, ex);
81 | }
82 | }
83 |
84 |
85 | public synchronized long nextId() {
86 | long timeStamp = timeGen();
87 | //当前时间小于上次生成id的时间戳,说明系统时钟回退,更新当前时间,保证id生成器可用
88 | if (timeStamp < lastTimeStamp) {
89 | timeStamp = tilNextMills(lastTimeStamp);
90 | }
91 | //序号与当前时间戳无关,每次递增
92 | sequence = (sequence + 1) & sequenceMask;
93 | //当同一时间戳内的并发量大于序号的最大值,则时间戳向后增加
94 | if (sequence == 0L && timeStamp == lastTimeStamp) {
95 | timeStamp = tilNextMills(timeStamp);
96 | }
97 | return (timeStamp - beginTime) << timeStampLeftShift | SERVER_ID << serverShift | DB_ID << dbShift | sequence;
98 | }
99 |
100 | protected long tilNextMills(long lastTimeStamp) {
101 | long timeStamp = timeGen();
102 | while (timeStamp < lastTimeStamp) {
103 | timeStamp = timeGen();
104 | }
105 | return timeStamp;
106 | }
107 |
108 | /**
109 | * 返回当前时间,单位毫秒
110 | *
111 | * @return 当前时间(毫秒)
112 | */
113 | protected long timeGen() {
114 | return System.currentTimeMillis();
115 | }
116 |
117 |
118 | public long bulidOrderId(long userId) {
119 | //取用户id后4位
120 | userId = userId & 15;
121 | //先取60位唯一id
122 | long uniqueId = this.nextId();
123 | //唯一id左移4位、拼接userId后4位
124 | return (uniqueId << 4) | userId;
125 | }
126 | }
127 |
128 |
129 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.lc
8 | study-sharding
9 | 1.0.0-SNAPSHOT
10 |
11 | 3.4.2
12 | 1.3.1
13 | 4.3.18.RELEASE
14 | 5.1.40
15 | 1.0.12
16 |
17 |
18 |
19 |
20 | com.dangdang
21 | sharding-jdbc-core
22 | 1.4.2
23 |
24 |
25 | com.dangdang
26 | sharding-jdbc-config-spring
27 | 1.4.0
28 |
29 |
30 |
31 | junit
32 | junit
33 | 4.12
34 | test
35 |
36 |
37 |
38 | org.aspectj
39 | aspectjweaver
40 | 1.8.4
41 |
42 |
43 | org.springframework
44 | spring-context
45 | ${spring.version}
46 |
47 |
48 | org.springframework
49 | spring-context-support
50 | ${spring.version}
51 |
52 |
53 | org.springframework
54 | spring-tx
55 | ${spring.version}
56 |
57 |
58 | org.springframework
59 | spring-test
60 | ${spring.version}
61 | test
62 |
63 |
64 |
65 | org.mybatis
66 | mybatis
67 | ${mybatis.version}
68 |
69 |
70 | org.mybatis
71 | mybatis-spring
72 | ${mybatis-spring.version}
73 |
74 |
75 |
76 | mysql
77 | mysql-connector-java
78 | ${mysql-connector-java.version}
79 |
80 |
81 | com.alibaba
82 | druid
83 | ${druid.version}
84 |
85 |
86 |
87 | log4j
88 | log4j
89 | 1.2.16
90 |
91 |
92 |
93 | org.slf4j
94 | slf4j-log4j12
95 | 1.7.2
96 |
97 |
98 |
99 | dianshangwuxian_dsf_salary_server
100 |
101 |
102 | org.mybatis.generator
103 | mybatis-generator-maven-plugin
104 | 1.3.2
105 |
106 |
107 |
108 | mysql
109 | mysql-connector-java
110 | 5.1.13
111 |
112 |
113 |
114 | true
115 | true
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/src/main/resources/config/spring-datasource.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
80 |
81 |
82 |
83 |
84 |
85 |
87 |
89 |
90 |
92 |
93 |
95 |
96 |
97 |
98 |
99 |
101 |
102 |
103 |
104 | true
105 | true
106 |
107 |
108 |
--------------------------------------------------------------------------------
/src/main/resources/xmlmapper/TOrderMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | and ${criterion.condition}
19 |
20 |
21 | and ${criterion.condition} #{criterion.value}
22 |
23 |
24 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
25 |
26 |
27 | and ${criterion.condition}
28 |
29 | #{listItem}
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | and ${criterion.condition}
48 |
49 |
50 | and ${criterion.condition} #{criterion.value}
51 |
52 |
53 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
54 |
55 |
56 | and ${criterion.condition}
57 |
58 | #{listItem}
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | id, order_id, user_id, business_id
70 |
71 |
85 |
86 | delete from t_order
87 |
88 |
89 |
90 |
91 |
92 | insert into t_order (id, order_id, user_id,
93 | business_id)
94 | values (#{id,jdbcType=BIGINT}, #{orderId,jdbcType=BIGINT}, #{userId,jdbcType=BIGINT},
95 | #{businessId,jdbcType=BIGINT})
96 |
97 |
98 | insert into t_order
99 |
100 |
101 | id,
102 |
103 |
104 | order_id,
105 |
106 |
107 | user_id,
108 |
109 |
110 | business_id,
111 |
112 |
113 |
114 |
115 | #{id,jdbcType=BIGINT},
116 |
117 |
118 | #{orderId,jdbcType=BIGINT},
119 |
120 |
121 | #{userId,jdbcType=BIGINT},
122 |
123 |
124 | #{businessId,jdbcType=BIGINT},
125 |
126 |
127 |
128 |
134 |
135 | update t_order
136 |
137 |
138 | id = #{record.id,jdbcType=BIGINT},
139 |
140 |
141 | order_id = #{record.orderId,jdbcType=BIGINT},
142 |
143 |
144 | user_id = #{record.userId,jdbcType=BIGINT},
145 |
146 |
147 | business_id = #{record.businessId,jdbcType=BIGINT},
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 | update t_order
156 | set id = #{record.id,jdbcType=BIGINT},
157 | order_id = #{record.orderId,jdbcType=BIGINT},
158 | user_id = #{record.userId,jdbcType=BIGINT},
159 | business_id = #{record.businessId,jdbcType=BIGINT}
160 |
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/src/main/java/com/lc/sharding/pojo/TOrderExample.java:
--------------------------------------------------------------------------------
1 | package com.lc.sharding.pojo;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class TOrderExample {
7 | protected String orderByClause;
8 |
9 | protected boolean distinct;
10 |
11 | protected List oredCriteria;
12 |
13 | public TOrderExample() {
14 | oredCriteria = new ArrayList();
15 | }
16 |
17 | public void setOrderByClause(String orderByClause) {
18 | this.orderByClause = orderByClause;
19 | }
20 |
21 | public String getOrderByClause() {
22 | return orderByClause;
23 | }
24 |
25 | public void setDistinct(boolean distinct) {
26 | this.distinct = distinct;
27 | }
28 |
29 | public boolean isDistinct() {
30 | return distinct;
31 | }
32 |
33 | public List getOredCriteria() {
34 | return oredCriteria;
35 | }
36 |
37 | public void or(Criteria criteria) {
38 | oredCriteria.add(criteria);
39 | }
40 |
41 | public Criteria or() {
42 | Criteria criteria = createCriteriaInternal();
43 | oredCriteria.add(criteria);
44 | return criteria;
45 | }
46 |
47 | public Criteria createCriteria() {
48 | Criteria criteria = createCriteriaInternal();
49 | if (oredCriteria.size() == 0) {
50 | oredCriteria.add(criteria);
51 | }
52 | return criteria;
53 | }
54 |
55 | protected Criteria createCriteriaInternal() {
56 | Criteria criteria = new Criteria();
57 | return criteria;
58 | }
59 |
60 | public void clear() {
61 | oredCriteria.clear();
62 | orderByClause = null;
63 | distinct = false;
64 | }
65 |
66 | protected abstract static class GeneratedCriteria {
67 | protected List criteria;
68 |
69 | protected GeneratedCriteria() {
70 | super();
71 | criteria = new ArrayList();
72 | }
73 |
74 | public boolean isValid() {
75 | return criteria.size() > 0;
76 | }
77 |
78 | public List getAllCriteria() {
79 | return criteria;
80 | }
81 |
82 | public List getCriteria() {
83 | return criteria;
84 | }
85 |
86 | protected void addCriterion(String condition) {
87 | if (condition == null) {
88 | throw new RuntimeException("Value for condition cannot be null");
89 | }
90 | criteria.add(new Criterion(condition));
91 | }
92 |
93 | protected void addCriterion(String condition, Object value, String property) {
94 | if (value == null) {
95 | throw new RuntimeException("Value for " + property + " cannot be null");
96 | }
97 | criteria.add(new Criterion(condition, value));
98 | }
99 |
100 | protected void addCriterion(String condition, Object value1, Object value2, String property) {
101 | if (value1 == null || value2 == null) {
102 | throw new RuntimeException("Between values for " + property + " cannot be null");
103 | }
104 | criteria.add(new Criterion(condition, value1, value2));
105 | }
106 |
107 | public Criteria andIdIsNull() {
108 | addCriterion("id is null");
109 | return (Criteria) this;
110 | }
111 |
112 | public Criteria andIdIsNotNull() {
113 | addCriterion("id is not null");
114 | return (Criteria) this;
115 | }
116 |
117 | public Criteria andIdEqualTo(Long value) {
118 | addCriterion("id =", value, "id");
119 | return (Criteria) this;
120 | }
121 |
122 | public Criteria andIdNotEqualTo(Long value) {
123 | addCriterion("id <>", value, "id");
124 | return (Criteria) this;
125 | }
126 |
127 | public Criteria andIdGreaterThan(Long value) {
128 | addCriterion("id >", value, "id");
129 | return (Criteria) this;
130 | }
131 |
132 | public Criteria andIdGreaterThanOrEqualTo(Long value) {
133 | addCriterion("id >=", value, "id");
134 | return (Criteria) this;
135 | }
136 |
137 | public Criteria andIdLessThan(Long value) {
138 | addCriterion("id <", value, "id");
139 | return (Criteria) this;
140 | }
141 |
142 | public Criteria andIdLessThanOrEqualTo(Long value) {
143 | addCriterion("id <=", value, "id");
144 | return (Criteria) this;
145 | }
146 |
147 | public Criteria andIdIn(List values) {
148 | addCriterion("id in", values, "id");
149 | return (Criteria) this;
150 | }
151 |
152 | public Criteria andIdNotIn(List values) {
153 | addCriterion("id not in", values, "id");
154 | return (Criteria) this;
155 | }
156 |
157 | public Criteria andIdBetween(Long value1, Long value2) {
158 | addCriterion("id between", value1, value2, "id");
159 | return (Criteria) this;
160 | }
161 |
162 | public Criteria andIdNotBetween(Long value1, Long value2) {
163 | addCriterion("id not between", value1, value2, "id");
164 | return (Criteria) this;
165 | }
166 |
167 | public Criteria andOrderIdIsNull() {
168 | addCriterion("order_id is null");
169 | return (Criteria) this;
170 | }
171 |
172 | public Criteria andOrderIdIsNotNull() {
173 | addCriterion("order_id is not null");
174 | return (Criteria) this;
175 | }
176 |
177 | public Criteria andOrderIdEqualTo(Long value) {
178 | addCriterion("order_id =", value, "orderId");
179 | return (Criteria) this;
180 | }
181 |
182 | public Criteria andOrderIdNotEqualTo(Long value) {
183 | addCriterion("order_id <>", value, "orderId");
184 | return (Criteria) this;
185 | }
186 |
187 | public Criteria andOrderIdGreaterThan(Long value) {
188 | addCriterion("order_id >", value, "orderId");
189 | return (Criteria) this;
190 | }
191 |
192 | public Criteria andOrderIdGreaterThanOrEqualTo(Long value) {
193 | addCriterion("order_id >=", value, "orderId");
194 | return (Criteria) this;
195 | }
196 |
197 | public Criteria andOrderIdLessThan(Long value) {
198 | addCriterion("order_id <", value, "orderId");
199 | return (Criteria) this;
200 | }
201 |
202 | public Criteria andOrderIdLessThanOrEqualTo(Long value) {
203 | addCriterion("order_id <=", value, "orderId");
204 | return (Criteria) this;
205 | }
206 |
207 | public Criteria andOrderIdIn(List values) {
208 | addCriterion("order_id in", values, "orderId");
209 | return (Criteria) this;
210 | }
211 |
212 | public Criteria andOrderIdNotIn(List values) {
213 | addCriterion("order_id not in", values, "orderId");
214 | return (Criteria) this;
215 | }
216 |
217 | public Criteria andOrderIdBetween(Long value1, Long value2) {
218 | addCriterion("order_id between", value1, value2, "orderId");
219 | return (Criteria) this;
220 | }
221 |
222 | public Criteria andOrderIdNotBetween(Long value1, Long value2) {
223 | addCriterion("order_id not between", value1, value2, "orderId");
224 | return (Criteria) this;
225 | }
226 |
227 | public Criteria andUserIdIsNull() {
228 | addCriterion("user_id is null");
229 | return (Criteria) this;
230 | }
231 |
232 | public Criteria andUserIdIsNotNull() {
233 | addCriterion("user_id is not null");
234 | return (Criteria) this;
235 | }
236 |
237 | public Criteria andUserIdEqualTo(Long value) {
238 | addCriterion("user_id =", value, "userId");
239 | return (Criteria) this;
240 | }
241 |
242 | public Criteria andUserIdNotEqualTo(Long value) {
243 | addCriterion("user_id <>", value, "userId");
244 | return (Criteria) this;
245 | }
246 |
247 | public Criteria andUserIdGreaterThan(Long value) {
248 | addCriterion("user_id >", value, "userId");
249 | return (Criteria) this;
250 | }
251 |
252 | public Criteria andUserIdGreaterThanOrEqualTo(Long value) {
253 | addCriterion("user_id >=", value, "userId");
254 | return (Criteria) this;
255 | }
256 |
257 | public Criteria andUserIdLessThan(Long value) {
258 | addCriterion("user_id <", value, "userId");
259 | return (Criteria) this;
260 | }
261 |
262 | public Criteria andUserIdLessThanOrEqualTo(Long value) {
263 | addCriterion("user_id <=", value, "userId");
264 | return (Criteria) this;
265 | }
266 |
267 | public Criteria andUserIdIn(List values) {
268 | addCriterion("user_id in", values, "userId");
269 | return (Criteria) this;
270 | }
271 |
272 | public Criteria andUserIdNotIn(List values) {
273 | addCriterion("user_id not in", values, "userId");
274 | return (Criteria) this;
275 | }
276 |
277 | public Criteria andUserIdBetween(Long value1, Long value2) {
278 | addCriterion("user_id between", value1, value2, "userId");
279 | return (Criteria) this;
280 | }
281 |
282 | public Criteria andUserIdNotBetween(Long value1, Long value2) {
283 | addCriterion("user_id not between", value1, value2, "userId");
284 | return (Criteria) this;
285 | }
286 |
287 | public Criteria andBusinessIdIsNull() {
288 | addCriterion("business_id is null");
289 | return (Criteria) this;
290 | }
291 |
292 | public Criteria andBusinessIdIsNotNull() {
293 | addCriterion("business_id is not null");
294 | return (Criteria) this;
295 | }
296 |
297 | public Criteria andBusinessIdEqualTo(Long value) {
298 | addCriterion("business_id =", value, "businessId");
299 | return (Criteria) this;
300 | }
301 |
302 | public Criteria andBusinessIdNotEqualTo(Long value) {
303 | addCriterion("business_id <>", value, "businessId");
304 | return (Criteria) this;
305 | }
306 |
307 | public Criteria andBusinessIdGreaterThan(Long value) {
308 | addCriterion("business_id >", value, "businessId");
309 | return (Criteria) this;
310 | }
311 |
312 | public Criteria andBusinessIdGreaterThanOrEqualTo(Long value) {
313 | addCriterion("business_id >=", value, "businessId");
314 | return (Criteria) this;
315 | }
316 |
317 | public Criteria andBusinessIdLessThan(Long value) {
318 | addCriterion("business_id <", value, "businessId");
319 | return (Criteria) this;
320 | }
321 |
322 | public Criteria andBusinessIdLessThanOrEqualTo(Long value) {
323 | addCriterion("business_id <=", value, "businessId");
324 | return (Criteria) this;
325 | }
326 |
327 | public Criteria andBusinessIdIn(List values) {
328 | addCriterion("business_id in", values, "businessId");
329 | return (Criteria) this;
330 | }
331 |
332 | public Criteria andBusinessIdNotIn(List values) {
333 | addCriterion("business_id not in", values, "businessId");
334 | return (Criteria) this;
335 | }
336 |
337 | public Criteria andBusinessIdBetween(Long value1, Long value2) {
338 | addCriterion("business_id between", value1, value2, "businessId");
339 | return (Criteria) this;
340 | }
341 |
342 | public Criteria andBusinessIdNotBetween(Long value1, Long value2) {
343 | addCriterion("business_id not between", value1, value2, "businessId");
344 | return (Criteria) this;
345 | }
346 | }
347 |
348 | public static class Criteria extends GeneratedCriteria {
349 |
350 | protected Criteria() {
351 | super();
352 | }
353 | }
354 |
355 | public static class Criterion {
356 | private String condition;
357 |
358 | private Object value;
359 |
360 | private Object secondValue;
361 |
362 | private boolean noValue;
363 |
364 | private boolean singleValue;
365 |
366 | private boolean betweenValue;
367 |
368 | private boolean listValue;
369 |
370 | private String typeHandler;
371 |
372 | public String getCondition() {
373 | return condition;
374 | }
375 |
376 | public Object getValue() {
377 | return value;
378 | }
379 |
380 | public Object getSecondValue() {
381 | return secondValue;
382 | }
383 |
384 | public boolean isNoValue() {
385 | return noValue;
386 | }
387 |
388 | public boolean isSingleValue() {
389 | return singleValue;
390 | }
391 |
392 | public boolean isBetweenValue() {
393 | return betweenValue;
394 | }
395 |
396 | public boolean isListValue() {
397 | return listValue;
398 | }
399 |
400 | public String getTypeHandler() {
401 | return typeHandler;
402 | }
403 |
404 | protected Criterion(String condition) {
405 | super();
406 | this.condition = condition;
407 | this.typeHandler = null;
408 | this.noValue = true;
409 | }
410 |
411 | protected Criterion(String condition, Object value, String typeHandler) {
412 | super();
413 | this.condition = condition;
414 | this.value = value;
415 | this.typeHandler = typeHandler;
416 | if (value instanceof List>) {
417 | this.listValue = true;
418 | } else {
419 | this.singleValue = true;
420 | }
421 | }
422 |
423 | protected Criterion(String condition, Object value) {
424 | this(condition, value, null);
425 | }
426 |
427 | protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
428 | super();
429 | this.condition = condition;
430 | this.value = value;
431 | this.secondValue = secondValue;
432 | this.typeHandler = typeHandler;
433 | this.betweenValue = true;
434 | }
435 |
436 | protected Criterion(String condition, Object value, Object secondValue) {
437 | this(condition, value, secondValue, null);
438 | }
439 | }
440 | }
--------------------------------------------------------------------------------