Skip to content

Commit b03b719

Browse files
committed
Merge pull request #505 from kazuki43zoo/issues/503_improve-defaultStatementTimeout
Improve handling of defaultStatementTimeout #503
2 parents f3f6cb6 + 2b929b5 commit b03b719

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ public MappedStatement addMappedStatement(
282282
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType);
283283
statementBuilder.resource(resource);
284284
statementBuilder.fetchSize(fetchSize);
285+
statementBuilder.timeout(timeout);
285286
statementBuilder.statementType(statementType);
286287
statementBuilder.keyGenerator(keyGenerator);
287288
statementBuilder.keyProperty(keyProperty);
@@ -290,7 +291,6 @@ public MappedStatement addMappedStatement(
290291
statementBuilder.lang(lang);
291292
statementBuilder.resultOrdered(resultOrdered);
292293
statementBuilder.resulSets(resultSets);
293-
setStatementTimeout(timeout, statementBuilder);
294294

295295
setStatementParameterMap(parameterMap, parameterType, statementBuilder);
296296
setStatementResultMap(resultMap, resultType, resultSetType, statementBuilder);
@@ -372,13 +372,6 @@ private void setStatementResultMap(
372372
statementBuilder.resultSetType(resultSetType);
373373
}
374374

375-
private void setStatementTimeout(Integer timeout, MappedStatement.Builder statementBuilder) {
376-
if (timeout == null) {
377-
timeout = configuration.getDefaultStatementTimeout();
378-
}
379-
statementBuilder.timeout(timeout);
380-
}
381-
382375
public ResultMapping buildResultMapping(
383376
Class<?> resultType,
384377
String property,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ public Statement prepare(Connection connection) throws SQLException {
102102

103103
protected void setStatementTimeout(Statement stmt) throws SQLException {
104104
Integer timeout = mappedStatement.getTimeout();
105-
Integer defaultTimeout = configuration.getDefaultStatementTimeout();
106105
if (timeout != null) {
107106
stmt.setQueryTimeout(timeout);
108-
} else if (defaultTimeout != null) {
107+
return;
108+
}
109+
Integer defaultTimeout = configuration.getDefaultStatementTimeout();
110+
if (defaultTimeout != null) {
109111
stmt.setQueryTimeout(defaultTimeout);
110112
}
111113
}

src/main/java/org/apache/ibatis/mapping/MappedStatement.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public Builder(Configuration configuration, String id, SqlSource sqlSource, SqlC
7171
mappedStatement.statementType = StatementType.PREPARED;
7272
mappedStatement.parameterMap = new ParameterMap.Builder(configuration, "defaultParameterMap", null, new ArrayList<ParameterMapping>()).build();
7373
mappedStatement.resultMaps = new ArrayList<ResultMap>();
74-
mappedStatement.timeout = configuration.getDefaultStatementTimeout();
7574
mappedStatement.sqlCommandType = sqlCommandType;
7675
mappedStatement.keyGenerator = configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType) ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
7776
String logId = id;

src/test/java/org/apache/ibatis/executor/ExecutorTestHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public static MappedStatement prepareSelectAllAuthorsAutoMappedStatement(final C
197197
}
198198
}).build());
199199
}
200-
}).fetchSize(1000).build();
200+
}).fetchSize(1000).timeout(2000).build();
201201
}
202202

203203
public static MappedStatement prepareSelectOneAuthorMappedStatementWithConstructorResults(final Configuration config) {

0 commit comments

Comments
 (0)