Skip to content

Commit fd5058c

Browse files
authored
Merge pull request #1 from mybatis/master
Merge pull request
2 parents 0698dcf + 9eeb15a commit fd5058c

File tree

24 files changed

+343
-124
lines changed

24 files changed

+343
-124
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jdk:
55
- openjdk13
66
- openjdk12
77
- openjdk11
8-
- oraclejdk8
8+
- openjdk8
99

1010
services:
1111
- docker

pom.xml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</parent>
2828

2929
<artifactId>mybatis</artifactId>
30-
<version>3.5.3-SNAPSHOT</version>
30+
<version>3.5.4-SNAPSHOT</version>
3131
<packaging>jar</packaging>
3232

3333
<name>mybatis</name>
@@ -252,6 +252,12 @@
252252
<version>42.2.5</version>
253253
<scope>test</scope>
254254
</dependency>
255+
<dependency>
256+
<groupId>mysql</groupId>
257+
<artifactId>mysql-connector-java</artifactId>
258+
<version>8.0.17</version>
259+
<scope>test</scope>
260+
</dependency>
255261
<dependency>
256262
<groupId>org.assertj</groupId>
257263
<artifactId>assertj-core</artifactId>
@@ -267,13 +273,19 @@
267273
<dependency>
268274
<groupId>org.testcontainers</groupId>
269275
<artifactId>junit-jupiter</artifactId>
270-
<version>1.11.2</version>
276+
<version>1.12.1</version>
271277
<scope>test</scope>
272278
</dependency>
273279
<dependency>
274280
<groupId>org.testcontainers</groupId>
275281
<artifactId>postgresql</artifactId>
276-
<version>1.11.2</version>
282+
<version>1.12.1</version>
283+
<scope>test</scope>
284+
</dependency>
285+
<dependency>
286+
<groupId>org.testcontainers</groupId>
287+
<artifactId>mysql</artifactId>
288+
<version>1.12.1</version>
277289
<scope>test</scope>
278290
</dependency>
279291
</dependencies>

src/main/java/org/apache/ibatis/cache/CacheKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void updateAll(Object[] objects) {
4040
}
4141
};
4242

43-
private static final int DEFAULT_MULTIPLYER = 37;
43+
private static final int DEFAULT_MULTIPLIER = 37;
4444
private static final int DEFAULT_HASHCODE = 17;
4545

4646
private final int multiplier;
@@ -52,7 +52,7 @@ public void updateAll(Object[] objects) {
5252

5353
public CacheKey() {
5454
this.hashcode = DEFAULT_HASHCODE;
55-
this.multiplier = DEFAULT_MULTIPLYER;
55+
this.multiplier = DEFAULT_MULTIPLIER;
5656
this.count = 0;
5757
this.updateList = new ArrayList<>();
5858
}

src/main/java/org/apache/ibatis/cache/decorators/ScheduledCache.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import org.apache.ibatis.cache.Cache;
1919

20+
import java.util.concurrent.TimeUnit;
21+
2022
/**
2123
* @author Clinton Begin
2224
*/
@@ -28,7 +30,7 @@ public class ScheduledCache implements Cache {
2830

2931
public ScheduledCache(Cache delegate) {
3032
this.delegate = delegate;
31-
this.clearInterval = 60 * 60 * 1000; // 1 hour
33+
this.clearInterval = TimeUnit.HOURS.toMillis(1);
3234
this.lastClear = System.currentTimeMillis();
3335
}
3436

src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void setDriverProperties(Properties driverProperties) {
136136
this.driverProperties = driverProperties;
137137
}
138138

139-
public String getDriver() {
139+
public synchronized String getDriver() {
140140
return driver;
141141
}
142142

src/main/java/org/apache/ibatis/executor/BatchExecutor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ protected <E> Cursor<E> doQueryCursor(MappedStatement ms, Object parameter, RowB
102102
StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, null, boundSql);
103103
Connection connection = getConnection(ms.getStatementLog());
104104
Statement stmt = handler.prepare(connection, transaction.getTimeout());
105-
stmt.closeOnCompletion();
106105
handler.parameterize(stmt);
107-
return handler.queryCursor(stmt);
106+
Cursor<E> cursor = handler.queryCursor(stmt);
107+
stmt.closeOnCompletion();
108+
return cursor;
108109
}
109110

110111
@Override

src/main/java/org/apache/ibatis/executor/ErrorContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2018 the original author or authors.
2+
* Copyright 2009-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -131,7 +131,7 @@ public String toString() {
131131
description.append(activity);
132132
}
133133

134-
// activity
134+
// sql
135135
if (sql != null) {
136136
description.append(LINE_SEPARATOR);
137137
description.append("### SQL: ");

src/main/java/org/apache/ibatis/executor/SimpleExecutor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ protected <E> Cursor<E> doQueryCursor(MappedStatement ms, Object parameter, RowB
7171
Configuration configuration = ms.getConfiguration();
7272
StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, null, boundSql);
7373
Statement stmt = prepareStatement(handler, ms.getStatementLog());
74+
Cursor<E> cursor = handler.queryCursor(stmt);
7475
stmt.closeOnCompletion();
75-
return handler.queryCursor(stmt);
76+
return cursor;
7677
}
7778

7879
@Override

src/main/java/org/apache/ibatis/executor/keygen/SelectKeyGenerator.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,26 @@ private void processGeneratedKeys(Executor executor, MappedStatement ms, Object
6161
String[] keyProperties = keyStatement.getKeyProperties();
6262
final Configuration configuration = ms.getConfiguration();
6363
final MetaObject metaParam = configuration.newMetaObject(parameter);
64-
if (keyProperties != null) {
65-
// Do not close keyExecutor.
66-
// The transaction will be closed by parent executor.
67-
Executor keyExecutor = configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE);
68-
List<Object> values = keyExecutor.query(keyStatement, parameter, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
69-
if (values.size() == 0) {
70-
throw new ExecutorException("SelectKey returned no data.");
71-
} else if (values.size() > 1) {
72-
throw new ExecutorException("SelectKey returned more than one value.");
73-
} else {
74-
MetaObject metaResult = configuration.newMetaObject(values.get(0));
75-
if (keyProperties.length == 1) {
76-
if (metaResult.hasGetter(keyProperties[0])) {
77-
setValue(metaParam, keyProperties[0], metaResult.getValue(keyProperties[0]));
78-
} else {
79-
// no getter for the property - maybe just a single value object
80-
// so try that
81-
setValue(metaParam, keyProperties[0], values.get(0));
82-
}
64+
// Do not close keyExecutor.
65+
// The transaction will be closed by parent executor.
66+
Executor keyExecutor = configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE);
67+
List<Object> values = keyExecutor.query(keyStatement, parameter, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
68+
if (values.size() == 0) {
69+
throw new ExecutorException("SelectKey returned no data.");
70+
} else if (values.size() > 1) {
71+
throw new ExecutorException("SelectKey returned more than one value.");
72+
} else {
73+
MetaObject metaResult = configuration.newMetaObject(values.get(0));
74+
if (keyProperties.length == 1) {
75+
if (metaResult.hasGetter(keyProperties[0])) {
76+
setValue(metaParam, keyProperties[0], metaResult.getValue(keyProperties[0]));
8377
} else {
84-
handleMultipleProperties(keyProperties, metaParam, metaResult);
78+
// no getter for the property - maybe just a single value object
79+
// so try that
80+
setValue(metaParam, keyProperties[0], values.get(0));
8581
}
82+
} else {
83+
handleMultipleProperties(keyProperties, metaParam, metaResult);
8684
}
8785
}
8886
}

src/main/java/org/apache/ibatis/executor/statement/StatementUtil.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,17 +41,11 @@ private StatementUtil() {
4141
* @throws SQLException if a database access error occurs, this method is called on a closed <code>Statement</code>
4242
*/
4343
public static void applyTransactionTimeout(Statement statement, Integer queryTimeout, Integer transactionTimeout) throws SQLException {
44-
if (transactionTimeout == null){
44+
if (transactionTimeout == null) {
4545
return;
4646
}
47-
Integer timeToLiveOfQuery = null;
48-
if (queryTimeout == null || queryTimeout == 0) {
49-
timeToLiveOfQuery = transactionTimeout;
50-
} else if (transactionTimeout < queryTimeout) {
51-
timeToLiveOfQuery = transactionTimeout;
52-
}
53-
if (timeToLiveOfQuery != null) {
54-
statement.setQueryTimeout(timeToLiveOfQuery);
47+
if (queryTimeout == null || queryTimeout == 0 || transactionTimeout < queryTimeout) {
48+
statement.setQueryTimeout(transactionTimeout);
5549
}
5650
}
5751

0 commit comments

Comments
 (0)