Skip to content

Commit 13cf7ba

Browse files
author
chenl
committed
test
1 parent 0eaf3ff commit 13cf7ba

File tree

8 files changed

+21
-20
lines changed

8 files changed

+21
-20
lines changed

spring-boot-mybatis-rw/spring-boot-mybatis-rw-sample/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<attribute name="maven.pomderived" value="true"/>
1818
</attributes>
1919
</classpathentry>
20-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
20+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
2121
<attributes>
2222
<attribute name="maven.pomderived" value="true"/>
2323
</attributes>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4-
org.eclipse.jdt.core.compiler.compliance=1.7
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
55
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
66
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
77
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8-
org.eclipse.jdt.core.compiler.source=1.7
8+
org.eclipse.jdt.core.compiler.source=1.8

spring-boot-mybatis-rw/spring-boot-mybatis-rw-sample/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<url>http://maven.apache.org</url>
1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<java.version>1.8</java.version>
1617
</properties>
1718
<dependencies>
1819
<dependency>

spring-boot-mybatis-rw/spring-boot-mybatis-rw-sample/sql/students.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ CREATE TABLE `students` (
2424
`id` bigint(20) NOT NULL,
2525
`name` varchar(20) DEFAULT NULL,
2626
PRIMARY KEY (`id`)
27-
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
27+
) ENGINE=InnoDB DEFAULT CHARSET=UTF-8;
2828

2929
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3030
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

spring-boot-mybatis-rw/spring-boot-mybatis-rw-sample/src/main/java/org/spring/boot/mybatis/rw/sample/service/impl/StrudentsServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public class StrudentsServiceImpl implements StrudentsService {
1313
private StudentsMapper studentsMapper;
1414
@Autowired
1515
private SqlSessionTemplate sqlSessionTemplate;
16-
@Transactional
16+
// @Transactional
1717
public void rw() {
1818

1919
Students students = (Students)sqlSessionTemplate.selectOne("selectByPrimaryKey", 1L);
2020
System.out.println(students.getName());
2121
students.setName("rw");
2222
sqlSessionTemplate.update("updateByPrimaryKeySelective", students);
23-
//studentsMapper.updateByPrimaryKeySelective(students);
23+
studentsMapper.updateByPrimaryKeySelective(students);
2424
students.setId(2L);
2525
studentsMapper.updateByPrimaryKeySelective(students);
2626
students = studentsMapper.selectByPrimaryKey(2L);

spring-boot-mybatis-rw/spring-boot-mybatis-rw-sample/src/main/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ spring.data.mybatis.typeAliasesPackage=org.spring.boot.mybatis.rw.sample.mapper
55
spring.mybatis.rw.readDataSources[0].url=jdbc:MySql://localhost:3306/test?characterEncoding=UTF-8
66
spring.mybatis.rw.readDataSources[0].driverClassName=com.mysql.jdbc.Driver
77
spring.mybatis.rw.readDataSources[0].username=root
8-
spring.mybatis.rw.readDataSources[0].password=123456
8+
spring.mybatis.rw.readDataSources[0].password=root
99

1010
spring.mybatis.rw.writeDataSource.url=jdbc:MySql://localhost:3306/chenlei?characterEncoding=UTF-8
1111
spring.mybatis.rw.writeDataSource.driverClassName=com.mysql.jdbc.Driver
1212
spring.mybatis.rw.writeDataSource.username=root
13-
spring.mybatis.rw.writeDataSource.password=123456
13+
spring.mybatis.rw.writeDataSource.password=root
1414

1515
server.servletPath=/user
1616

spring-boot-mybatis-rw/spring-boot-mybatis-rw-starter/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<url>http://maven.apache.org</url>
1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<java.version>1.8</java.version>
1617
</properties>
1718
<dependencies>
1819
<dependency>

spring-boot-mybatis-rw/spring-boot-mybatis-rw-starter/src/main/java/org/spring/boot/mybatis/rw/starter/datasource/DataSourceProxy.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public class DataSourceProxy implements DataSource {
3030

3131
private static final Log logger = LogFactory.getLog(DataSourceProxy.class);
3232

33-
private Boolean defaultAutoCommit;
33+
private Boolean defaultAutoCommit = Boolean.TRUE;
3434

35-
private Integer defaultTransactionIsolation;
35+
private Integer defaultTransactionIsolation = 2;
3636

3737
private DataSourceRout dataSourceRout;
3838

@@ -275,7 +275,11 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
275275
}
276276
if (method.getName().equals("close")) {
277277
Map<String, Connection> connectionMap = ConnectionHold.CONNECTION_CONTEXT.get();
278-
Connection writeCon = connectionMap.get(ConnectionHold.WRITE);
278+
Connection readCon = connectionMap.remove(ConnectionHold.READ);
279+
if (readCon != null) {
280+
readCon.close();
281+
}
282+
Connection writeCon = connectionMap.remove(ConnectionHold.WRITE);
279283
if (writeCon != null) {
280284
writeCon.close();
281285
}
@@ -287,16 +291,11 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
287291
// Target Connection already fetched,
288292
// or target Connection necessary for current operation ->
289293
// invoke method on target connection.
294+
290295
try {
291-
if (!hasTargetConnection()) {
292-
Connection conn = getTargetConnection(method);
293-
return method.invoke(conn, args);
294-
295-
} else {
296-
return method.invoke(
297-
ConnectionHold.CONNECTION_CONTEXT.get().get(ConnectionHold.CURRENT_CONNECTION.get()), args);
296+
return method.invoke(
297+
ConnectionHold.CONNECTION_CONTEXT.get().get(ConnectionHold.CURRENT_CONNECTION.get()), args);
298298

299-
}
300299
} catch (InvocationTargetException ex) {
301300
throw ex.getTargetException();
302301
}

0 commit comments

Comments
 (0)