We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mybatis-plus提供了default-statement-timeout: 60参数用于配置sql查询超时时间,实际开发中有些sql需要超出这个时间,但mybatis-plus没有单独设置的功能 原生mybatis在mapper.xml可以设置timeout,mapper接口可以设置@options,但是mybatis-plus通过代理生成的查询方法没有设置超时时间的功能 mybatis-plus在注入MappedStatement阶段timeout参数为null,这就意味着代理生成的查询方法不能自定义查询超时时间
MappedStatement被final修饰,本身无法修改,而通过MappedStatement提供的Build类重新生成再赋值内存地址变更又存在极大的安全隐患
这是mybatis的代码,在配置的基础上优先获取MappedStatement超时时间 protected void setStatementTimeout(Statement stmt, Integer transactionTimeout) throws SQLException { Integer queryTimeout = null; if (mappedStatement.getTimeout() != null) { queryTimeout = mappedStatement.getTimeout(); } else if (configuration.getDefaultStatementTimeout() != null) { queryTimeout = configuration.getDefaultStatementTimeout(); } if (queryTimeout != null) { stmt.setQueryTimeout(queryTimeout); } StatementUtil.applyTransactionTimeout(stmt, queryTimeout, transactionTimeout); }
这是mybatis-plus的代码,生成 MappedStatement timeout参数为null protected MappedStatement addMappedStatement(Class mapperClass, String id, SqlSource sqlSource, SqlCommandType sqlCommandType, Class parameterType, String resultMap, Class<?> resultType, KeyGenerator keyGenerator, String keyProperty, String keyColumn) { String statementName = mapperClass.getName() + DOT + id; if (hasMappedStatement(statementName)) { logger.warn(LEFT_SQ_BRACKET + statementName + "] Has been loaded by XML or SqlProvider or Mybatis's Annotation, so ignoring this injection for [" + getClass() + RIGHT_SQ_BRACKET); return null; } /* 缓存逻辑处理 */ boolean isSelect = sqlCommandType == SqlCommandType.SELECT; return builderAssistant.addMappedStatement(id, sqlSource, StatementType.PREPARED, sqlCommandType, null, null, null, parameterType, resultMap, resultType, null, !isSelect, isSelect, false, keyGenerator, keyProperty, keyColumn, configuration.getDatabaseId(), languageDriver, null); }
The text was updated successfully, but these errors were encountered:
不是应该更多的去优化sql的效率,很少见去设置 timeout 和 fetchSize ; 不过 看源码 你是可以设置 事务时间
Sorry, something went wrong.
No branches or pull requests
确认
功能改进
mybatis-plus提供了default-statement-timeout: 60参数用于配置sql查询超时时间,实际开发中有些sql需要超出这个时间,但mybatis-plus没有单独设置的功能
原生mybatis在mapper.xml可以设置timeout,mapper接口可以设置@options,但是mybatis-plus通过代理生成的查询方法没有设置超时时间的功能
mybatis-plus在注入MappedStatement阶段timeout参数为null,这就意味着代理生成的查询方法不能自定义查询超时时间
MappedStatement被final修饰,本身无法修改,而通过MappedStatement提供的Build类重新生成再赋值内存地址变更又存在极大的安全隐患
参考资料
这是mybatis的代码,在配置的基础上优先获取MappedStatement超时时间
protected void setStatementTimeout(Statement stmt, Integer transactionTimeout) throws SQLException {
Integer queryTimeout = null;
if (mappedStatement.getTimeout() != null) {
queryTimeout = mappedStatement.getTimeout();
} else if (configuration.getDefaultStatementTimeout() != null) {
queryTimeout = configuration.getDefaultStatementTimeout();
}
if (queryTimeout != null) {
stmt.setQueryTimeout(queryTimeout);
}
StatementUtil.applyTransactionTimeout(stmt, queryTimeout, transactionTimeout);
}
这是mybatis-plus的代码,生成 MappedStatement timeout参数为null
protected MappedStatement addMappedStatement(Class mapperClass, String id, SqlSource sqlSource, SqlCommandType sqlCommandType, Class parameterType,
String resultMap, Class<?> resultType, KeyGenerator keyGenerator,
String keyProperty, String keyColumn) {
String statementName = mapperClass.getName() + DOT + id;
if (hasMappedStatement(statementName)) {
logger.warn(LEFT_SQ_BRACKET + statementName + "] Has been loaded by XML or SqlProvider or Mybatis's Annotation, so ignoring this injection for [" + getClass() + RIGHT_SQ_BRACKET);
return null;
}
/* 缓存逻辑处理 */
boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
return builderAssistant.addMappedStatement(id, sqlSource, StatementType.PREPARED, sqlCommandType,
null, null, null, parameterType, resultMap, resultType,
null, !isSelect, isSelect, false, keyGenerator, keyProperty, keyColumn,
configuration.getDatabaseId(), languageDriver, null);
}
The text was updated successfully, but these errors were encountered: