Skip to content

Commit b890b09

Browse files
committed
[new]update version and readme
1 parent 2945830 commit b890b09

File tree

20 files changed

+70
-270
lines changed

20 files changed

+70
-270
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target/
2+
/*/target/
23
!.mvn/wrapper/maven-wrapper.jar
34

45
### STS ###

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## spring-data-jdbc-mybatis
1+
# spring-data-jdbc-mybatis
22

33
[![](https://img.shields.io/badge/Blog-博客-blue.svg)](http://www.vonchange.com/doc/mini.html)
44
![](https://img.shields.io/maven-central/v/com.vonchange.common/spring-data-jdbc-mybatis.svg?label=Maven%20Central)
@@ -8,7 +8,7 @@
88
](https://gitee.com/vonchange/spring-data-jdbc-mybatis)
99

1010
**spring data jdbc extend mybatis dynamic sql**
11-
### What Is This?
11+
## What Is This?
1212
* It aims at being conceptually easy. In order to achieve this it does NOT offer caching, lazy loading, write behind or many other features of JPA. This makes a simple, limited, opinionated ORM.
1313

1414
* use mybatis dynamic SQL,it is good for complex SQL
@@ -28,8 +28,19 @@ SELECT [@id column] FROM user_base
2828
<if test="null!=createTime"> and create_time < #{createTime} </if>
2929
</where>
3030
```
31-
### see [easy-dynamic-sql.md](easy-dynamic-sql.md)
32-
### Getting Started with JDBC mybatis
31+
## see [easy-dynamic-sql.md](easy-dynamic-sql.md)
32+
## Features
33+
### batch update
34+
> need rewriteBatchedStatements=true&allowMultiQueries=true
35+
```java
36+
public interface UserInfoRepository extends CrudRepository<UserInfoDO, Long> {
37+
@BatchUpdate
38+
int batchUpdate(List<UserInfoDO> list);
39+
}
40+
```
41+
### [multi-datasource.md](multi-datasource.md)
42+
43+
## Getting Started with JDBC mybatis
3344

3445

3546
```java

multi-datasource.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
```java
3+
@Configuration
4+
public class DbConfig {
5+
@Bean(name = "dataSource")
6+
@Primary
7+
@ConfigurationProperties(prefix = "spring.datasource")
8+
public DataSource mainDataSource() {
9+
return DataSourceBuilder.create().build();
10+
}
11+
12+
@Bean(name = "orderDataSource")
13+
@ConfigurationProperties(prefix = "spring.datasource.order")
14+
public DataSource oldDataSource() {
15+
return DataSourceBuilder.create().build();
16+
}
17+
18+
@Bean("dataSourceWrapper")
19+
public DataSourceWrapper dataSourceWrapper(@Qualifier("dataSource")DataSource dataSource) {
20+
return new DataSourceWrapper(dataSource,"dataSource");
21+
}
22+
23+
24+
@Bean("orderDataSourceWrapper")
25+
public DataSourceWrapper oldDataSourceWrapper(@Qualifier("orderDataSource")DataSource dataSource) {
26+
return new DataSourceWrapper(dataSource,"orderDataSource");
27+
}
28+
29+
}
30+
```
31+
32+
```java
33+
@DataSourceKey("orderDataSource")
34+
public interface OrderQueryDao extends QueryRepository {
35+
}
36+
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.vonchange.nine.demo.config;
1+
package com.vonchange.mybatis.dialect;
22

33

44
import com.vonchange.common.util.ConvertUtil;

spring-data-jdbc-mybatis-low-test/src/main/java/com/vonchange/nine/demo/domain/BaseDO.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.vonchange.nine.demo.domain;
22

3-
import com.vonchange.mybatis.tpl.annotation.InsertIfNull;
4-
import com.vonchange.mybatis.tpl.annotation.UpdateDuplicateKeyIgnore;
5-
import com.vonchange.mybatis.tpl.annotation.UpdateIfNull;
3+
64
import com.vonchange.mybatis.tpl.annotation.UpdateNotNull;
75

86
import javax.persistence.Id;
@@ -17,12 +15,8 @@ public class BaseDO {
1715
private Long id;
1816
@UpdateNotNull
1917
private Integer isDelete;
20-
@InsertIfNull(function = "now()")
2118
@UpdateNotNull
2219
private Date createTime;
23-
@UpdateDuplicateKeyIgnore
24-
@InsertIfNull(function = "now()")
25-
@UpdateIfNull(function = "now()")
2620
private Date updateTime;
2721

2822
public BaseDO(){

spring-data-jdbc-mybatis-low-test/src/main/java/com/vonchange/nine/demo/domain/UserBaseDO.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.vonchange.nine.demo.domain;
22

3-
import com.vonchange.mybatis.tpl.annotation.InsertIfNull;
4-
import com.vonchange.mybatis.tpl.annotation.UpdateIfNull;
53
import com.vonchange.mybatis.tpl.annotation.UpdateNotNull;
64

75
import javax.persistence.Column;
@@ -27,12 +25,8 @@ public class UserBaseDO {
2725
//@InsertIfNull("0")
2826
@UpdateNotNull
2927
private Integer isDelete;
30-
@InsertIfNull(function = "now()")
3128
@UpdateNotNull
3229
private LocalDateTime createTime;
33-
//@UpdateDuplicateKeyIgnore
34-
@InsertIfNull(function = "now()")
35-
@UpdateIfNull(function = "now()")
3630
private Date updateTime;
3731
private EnumDelete enumDelete;
3832
private byte[] headImageData;

spring-data-jdbc-mybatis-low-test/src/main/java/com/vonchange/nine/demo/jpa/UserBase.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.vonchange.nine.demo.jpa;
22

3-
import com.vonchange.mybatis.tpl.annotation.InsertIfNull;
4-
import com.vonchange.mybatis.tpl.annotation.UpdateIfNull;
3+
54
import com.vonchange.mybatis.tpl.annotation.UpdateNotNull;
65

76
import javax.persistence.Column;
@@ -29,12 +28,10 @@ public class UserBase {
2928
//@InsertIfNull("0")
3029
@UpdateNotNull
3130
private Integer isDelete;
32-
@InsertIfNull(function = "now()")
31+
3332
@UpdateNotNull
3433
private LocalDateTime createTime;
35-
//@UpdateDuplicateKeyIgnore
36-
@InsertIfNull(function = "now()")
37-
@UpdateIfNull(function = "now()")
34+
3835
private Date updateTime;
3936
private byte[] headImageData;
4037
public UserBase(){

spring-data-jdbc-mybatis-low-test/src/test/java/com/vonchange/nine/demo/dao/UserBaseRepositoryTest.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,6 @@ public void insert() throws IOException {
142142
}
143143

144144

145-
@Test
146-
public void insertDuplicateKey() {
147-
UserBaseDO userBaseDO = new UserBaseDO();
148-
userBaseDO.setUserName("UUUUU");
149-
userBaseDO.setMobilePhone("110");
150-
int result = userBaseRepository.insertDuplicateKey(userBaseDO);
151-
log.info("\nresult {} {}",result,userBaseDO.getId());
152-
153-
}
154145
@Test
155146
//@Transactional
156147
//@Rollback
@@ -196,26 +187,6 @@ public void insertBatch() {
196187

197188

198189

199-
/**
200-
* 批量插入
201-
*/
202-
@Test
203-
@Transactional
204-
public void insertBatchDuplicateKey() {
205-
int result = userBaseRepository.update(new UserBaseDO(1L,"testxx","",1,null,null));
206-
log.info("result {}",result);
207-
long start = System.currentTimeMillis();
208-
List<UserBaseDO> list = new ArrayList<>();
209-
for (int i=0;i<10000;i++) {
210-
list.add(new UserBaseDO(null,"三e"+i,"1100"+i,null, LocalDateTime.now(),null));
211-
}
212-
int resultx = userBaseRepository.insertBatchDuplicateKey(list,5000);
213-
log.info("id {}",list.get(0).getId());
214-
log.info("result {}",resultx);
215-
int resulty = userBaseRepository.insertBatchDuplicateKey(list,5000);
216-
log.info("result {}",resulty);
217-
log.info("time {}",System.currentTimeMillis()-start);//1554
218-
}
219190

220191
@Test
221192
//@Transactional

spring-data-jdbc-mybatis-low/src/main/java/com/vonchange/jdbc/mybatis/core/support/BaseRepository.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@ public interface BaseRepository<T, ID extends Serializable> extends Repository<T
4242

4343
<S extends T> int insertBatch(List<S> entitys,int batchSize);
4444

45-
<S extends T> int insertBatchDuplicateKey(List<S> entitys,int batchSize);
4645

47-
/**
48-
* insert into on duplication key
49-
* @param entity
50-
* @param <S>
51-
*/
52-
<S extends T> int insertDuplicateKey(S entity);
5346

5447
/**
5548
* 默认只更新不为空的字段

spring-data-jdbc-mybatis-low/src/main/java/com/vonchange/jdbc/mybatis/core/support/JdbcRepositoryFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
*/
1616
package com.vonchange.jdbc.mybatis.core.support;
1717

18+
import com.vonchange.common.util.MarkdownUtil;
19+
import com.vonchange.common.util.StringPool;
1820
import com.vonchange.jdbc.abstractjdbc.core.JdbcRepository;
19-
import com.vonchange.jdbc.abstractjdbc.util.markdown.MarkdownUtil;
21+
2022
import com.vonchange.jdbc.mybatis.core.config.ConfigInfo;
2123
import com.vonchange.jdbc.mybatis.core.config.DataSourceWrapperHelper;
2224
import com.vonchange.jdbc.mybatis.core.query.DataSourceKey;
@@ -76,9 +78,7 @@ protected Object getTargetRepository(RepositoryInformation repositoryInformation
7678
String interfaceName =repositoryInformation.getRepositoryInterface().getSimpleName();
7779
SqlPackage sqlPackage= repositoryInformation.getRepositoryInterface().getAnnotation(SqlPackage.class);
7880
String configLoc=null!=sqlPackage?sqlPackage.value():"sql";
79-
if(MarkdownUtil.markdownFileExist(configLoc,interfaceName+".md")){
80-
MarkdownUtil.readMarkdownFile(configLoc,interfaceName+".md",false);
81-
}
81+
MarkdownUtil.readMarkdownFile(configLoc+ StringPool.DOT+interfaceName,false);
8282
DataSourceKey dataSourceKey=repositoryInformation.getRepositoryInterface().getAnnotation(DataSourceKey.class);
8383
String dataSourceKeyValue=null!=dataSourceKey?dataSourceKey.value():null;
8484
ConfigInfo configInfo= new ConfigInfo();

spring-data-jdbc-mybatis-low/src/main/java/com/vonchange/jdbc/mybatis/core/support/JdbcRepositoryQuery.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ private Object executeDo(Object[] objects) {
109109
return operations.insert(dataSourceWrapper, sqlId, parameters.getParameter());
110110
}
111111
if (null != parameters.getAbstractPageWork()) {
112-
operations.queryBigData(dataSourceWrapper, parameters.getAbstractPageWorkClass(), sqlId,
113-
parameters.getAbstractPageWork(), parameters.getParameter());
112+
//@@@
113+
//operations.queryBigData(dataSourceWrapper, parameters.getAbstractPageWorkClass(), sqlId,
114+
// parameters.getAbstractPageWork(), parameters.getParameter());
114115
}
115116
if (queryMethod.isCollectionQuery() || queryMethod.isStreamQuery()) {
116117
return operations.queryList(dataSourceWrapper, queryMethod.getReturnedObjectType(), sqlId,

spring-data-jdbc-mybatis-low/src/main/java/com/vonchange/jdbc/mybatis/core/support/SimpleJdbcRepository.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ public <S extends T> int insertBatch(List<S> entitys, int batchSize) {
5252
return entityOperations.insertBatch(configInfo.getDataSourceWrapper(), entitys, batchSize);
5353
}
5454

55-
@Override
56-
public <S extends T> int insertBatchDuplicateKey(List<S> entitys, int batchSize) {
57-
return entityOperations.insertBatchDuplicateKey(configInfo.getDataSourceWrapper(), entitys, batchSize);
58-
}
59-
60-
@Override
61-
public <S extends T> int insertDuplicateKey(S entity) {
62-
return entityOperations.insertDuplicateKey(configInfo.getDataSourceWrapper(), entity);
63-
}
6455

6556
@Override
6657
public <S extends T> int update(S entity) {

spring-data-jdbc-mybatis-low/src/main/java/com/vonchange/jdbc/mybatis/repository/JdbcRepositorySpringDataImpl.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ protected DataSourceWrapper getDataSourceFromSql(String sql) {
116116
return dataSourceInSql.getDataSourceFromSql(sql);
117117
}
118118

119-
@Override
120-
protected int batchSize() {
121-
return batchSize;
122-
}
123119

124120
@Override
125121
protected boolean logRead() {

spring-data-jdbc-mybatis-test/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.1.3.RELEASE</version>
8+
<version>2.7.18</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>com.vonchange.common</groupId>

spring-data-jdbc-mybatis-test/src/main/java/com/vonchange/nine/demo/config/DBConfig.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
@Configuration
18-
public class DBConfig implements InitializingBean {
18+
public class DBConfig {
1919
@Bean(name = "dataSource")
2020
@Primary
2121
@ConfigurationProperties(prefix = "spring.datasource.hikari")
@@ -46,11 +46,5 @@ public DataSource[] allReadDataSources() {
4646
}
4747
};
4848
}
49-
@Override
50-
public void afterPropertiesSet() throws Exception {
51-
/*DataSource dataSource=mainDataSource();
52-
Connection connection = DataSourceUtils.getConnection(dataSource);
53-
DataSourceUtils.releaseConnection(connection,dataSource);*/
54-
}
5549

5650
}

spring-data-jdbc-mybatis-test/src/main/java/com/vonchange/nine/demo/dao/UserInfoRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ List<UserInfoDO> findListByIds(@Param("userName") String userName,
3434
@BatchUpdate
3535
int batchUpdate(List<UserInfoDO> list);
3636

37-
@BatchUpdate(size = 5000)
37+
@BatchUpdate(size = 1000)
3838
int batchInsert(List<UserInfoDO> list);
3939

4040
List<Long> findLongList();

0 commit comments

Comments
 (0)