Skip to content

Commit

Permalink
Merge pull request mybatis#505 from kazuki43zoo/issues/503_improve-de…
Browse files Browse the repository at this point in the history
…faultStatementTimeout

Improve handling of defaultStatementTimeout mybatis#503
  • Loading branch information
emacarron committed Oct 25, 2015
2 parents f3f6cb6 + 2b929b5 commit b03b719
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public MappedStatement addMappedStatement(
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType);
statementBuilder.resource(resource);
statementBuilder.fetchSize(fetchSize);
statementBuilder.timeout(timeout);
statementBuilder.statementType(statementType);
statementBuilder.keyGenerator(keyGenerator);
statementBuilder.keyProperty(keyProperty);
Expand All @@ -290,7 +291,6 @@ public MappedStatement addMappedStatement(
statementBuilder.lang(lang);
statementBuilder.resultOrdered(resultOrdered);
statementBuilder.resulSets(resultSets);
setStatementTimeout(timeout, statementBuilder);

setStatementParameterMap(parameterMap, parameterType, statementBuilder);
setStatementResultMap(resultMap, resultType, resultSetType, statementBuilder);
Expand Down Expand Up @@ -372,13 +372,6 @@ private void setStatementResultMap(
statementBuilder.resultSetType(resultSetType);
}

private void setStatementTimeout(Integer timeout, MappedStatement.Builder statementBuilder) {
if (timeout == null) {
timeout = configuration.getDefaultStatementTimeout();
}
statementBuilder.timeout(timeout);
}

public ResultMapping buildResultMapping(
Class<?> resultType,
String property,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ public Statement prepare(Connection connection) throws SQLException {

protected void setStatementTimeout(Statement stmt) throws SQLException {
Integer timeout = mappedStatement.getTimeout();
Integer defaultTimeout = configuration.getDefaultStatementTimeout();
if (timeout != null) {
stmt.setQueryTimeout(timeout);
} else if (defaultTimeout != null) {
return;
}
Integer defaultTimeout = configuration.getDefaultStatementTimeout();
if (defaultTimeout != null) {
stmt.setQueryTimeout(defaultTimeout);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public Builder(Configuration configuration, String id, SqlSource sqlSource, SqlC
mappedStatement.statementType = StatementType.PREPARED;
mappedStatement.parameterMap = new ParameterMap.Builder(configuration, "defaultParameterMap", null, new ArrayList<ParameterMapping>()).build();
mappedStatement.resultMaps = new ArrayList<ResultMap>();
mappedStatement.timeout = configuration.getDefaultStatementTimeout();
mappedStatement.sqlCommandType = sqlCommandType;
mappedStatement.keyGenerator = configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType) ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
String logId = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static MappedStatement prepareSelectAllAuthorsAutoMappedStatement(final C
}
}).build());
}
}).fetchSize(1000).build();
}).fetchSize(1000).timeout(2000).build();
}

public static MappedStatement prepareSelectOneAuthorMappedStatementWithConstructorResults(final Configuration config) {
Expand Down

0 comments on commit b03b719

Please sign in to comment.