Java Code Examples for org.apache.ibatis.mapping.MappedStatement#getStatementType()
The following examples show how to use
org.apache.ibatis.mapping.MappedStatement#getStatementType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseExecutor.java From mybaties with Apache License 2.0 | 6 votes |
private void handleLocallyCachedOutputParameters(MappedStatement ms, CacheKey key, Object parameter, BoundSql boundSql) { //处理存储过程的OUT参数 if (ms.getStatementType() == StatementType.CALLABLE) { final Object cachedParameter = localOutputParameterCache.getObject(key); if (cachedParameter != null && parameter != null) { final MetaObject metaCachedParameter = configuration.newMetaObject(cachedParameter); final MetaObject metaParameter = configuration.newMetaObject(parameter); for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) { if (parameterMapping.getMode() != ParameterMode.IN) { final String parameterName = parameterMapping.getProperty(); final Object cachedValue = metaCachedParameter.getValue(parameterName); metaParameter.setValue(parameterName, cachedValue); } } } } }
Example 2
Source File: BaseExecutor.java From mybaties with Apache License 2.0 | 6 votes |
private <E> List<E> queryFromDatabase(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException { List<E> list; //先向缓存中放入占位符??? localCache.putObject(key, EXECUTION_PLACEHOLDER); try { list = doQuery(ms, parameter, rowBounds, resultHandler, boundSql); } finally { //最后删除占位符 localCache.removeObject(key); } //加入缓存 localCache.putObject(key, list); //如果是存储过程,OUT参数也加入缓存 if (ms.getStatementType() == StatementType.CALLABLE) { localOutputParameterCache.putObject(key, parameter); } return list; }
Example 3
Source File: RoutingStatementHandler.java From mybaties with Apache License 2.0 | 6 votes |
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { //根据语句类型,委派到不同的语句处理器(STATEMENT|PREPARED|CALLABLE) switch (ms.getStatementType()) { case STATEMENT: delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql); break; case PREPARED: delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql); break; case CALLABLE: delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql); break; default: throw new ExecutorException("Unknown statement type: " + ms.getStatementType()); } }
Example 4
Source File: BindingLogPlugin32.java From pinpoint with Apache License 2.0 | 6 votes |
private void bindingLog(Invocation invocation) throws SQLException { Object[] args = invocation.getArgs(); MappedStatement ms = (MappedStatement) args[0]; Object parameterObject = args[1]; StatementType statementType = ms.getStatementType(); if (StatementType.PREPARED == statementType || StatementType.CALLABLE == statementType) { Log statementLog = ms.getStatementLog(); if (isDebugEnable(statementLog)) { BoundSql boundSql = ms.getBoundSql(parameterObject); String sql = boundSql.getSql(); List<String> parameterList = getParameters(ms, parameterObject, boundSql); debug(statementLog, "==> BindingLog: " + bindLogFormatter.format(sql, parameterList)); } } }
Example 5
Source File: BaseExecutor.java From mybatis with Apache License 2.0 | 6 votes |
private void handleLocallyCachedOutputParameters(MappedStatement ms, CacheKey key, Object parameter, BoundSql boundSql) { //处理存储过程的OUT参数 if (ms.getStatementType() == StatementType.CALLABLE) { final Object cachedParameter = localOutputParameterCache.getObject(key); if (cachedParameter != null && parameter != null) { final MetaObject metaCachedParameter = configuration.newMetaObject(cachedParameter); final MetaObject metaParameter = configuration.newMetaObject(parameter); for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) { if (parameterMapping.getMode() != ParameterMode.IN) { final String parameterName = parameterMapping.getProperty(); final Object cachedValue = metaCachedParameter.getValue(parameterName); metaParameter.setValue(parameterName, cachedValue); } } } } }
Example 6
Source File: BaseExecutor.java From mybatis with Apache License 2.0 | 6 votes |
private <E> List<E> queryFromDatabase(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException { List<E> list; //先向缓存中放入占位符??? localCache.putObject(key, EXECUTION_PLACEHOLDER); try { list = doQuery(ms, parameter, rowBounds, resultHandler, boundSql); } finally { //最后删除占位符 localCache.removeObject(key); } //加入缓存 localCache.putObject(key, list); //如果是存储过程,OUT参数也加入缓存 if (ms.getStatementType() == StatementType.CALLABLE) { localOutputParameterCache.putObject(key, parameter); } return list; }
Example 7
Source File: RoutingStatementHandler.java From mybatis with Apache License 2.0 | 6 votes |
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { //根据语句类型,委派到不同的语句处理器(STATEMENT|PREPARED|CALLABLE) switch (ms.getStatementType()) { case STATEMENT: delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql); break; case PREPARED: delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql); break; case CALLABLE: delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql); break; default: throw new ExecutorException("Unknown statement type: " + ms.getStatementType()); } }
Example 8
Source File: CachingExecutor.java From mybaties with Apache License 2.0 | 5 votes |
private void ensureNoOutParams(MappedStatement ms, Object parameter, BoundSql boundSql) { if (ms.getStatementType() == StatementType.CALLABLE) { for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) { if (parameterMapping.getMode() != ParameterMode.IN) { throw new ExecutorException("Caching stored procedures with OUT params is not supported. Please configure useCache=false in " + ms.getId() + " statement."); } } } }
Example 9
Source File: CachingExecutor.java From mybatis with Apache License 2.0 | 5 votes |
private void ensureNoOutParams(MappedStatement ms, Object parameter, BoundSql boundSql) { if (ms.getStatementType() == StatementType.CALLABLE) { for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) { if (parameterMapping.getMode() != ParameterMode.IN) { throw new ExecutorException("Caching stored procedures with OUT params is not supported. Please configure useCache=false in " + ms.getId() + " statement."); } } } }
Example 10
Source File: PaginationInterceptor.java From platform with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public Object intercept(Invocation invocation) throws Throwable { Executor executor = MyBatisUtils.getRealTarget(invocation.getTarget()); Object[] args = invocation.getArgs(); MappedStatement mappedStatement = (MappedStatement) args[MAPPED_STATEMENT_INDEX]; // 查询操作或者存储过程,无需分页 if (SqlCommandType.SELECT != mappedStatement.getSqlCommandType() || StatementType.CALLABLE == mappedStatement.getStatementType()) { return invocation.proceed(); } Object parameterObject = invocation.getArgs()[PARAMETER_INDEX]; // 不包含PageableRequest或者Pageable参数时,无需分页 PageableRequest<?> pageableRequest = MyBatisUtils.findPageableRequest(parameterObject).orElse(null); if (null == pageableRequest || pageableRequest.getPageable() == null || pageableRequest.getPageable().getPageSize() < 0) { return invocation.proceed(); } Connection connection = executor.getTransaction().getConnection(); DbType dbType = this.dbType == null ? JdbcUtils.getDbType(connection) : this.dbType; DbDialect dialect = Optional.ofNullable(this.dbDialect).orElseGet(() -> JdbcUtils.getDialect(dbType)); // 针对定义了rowBounds,做为mapper接口方法的参数 BoundSql boundSql = mappedStatement.getBoundSql(parameterObject); String originalSql = boundSql.getSql(); // 查询总记录数 long total = 0; if (pageableRequest.isQueryTotalCount()) { String countSql = dialect.buildCountSql(boundSql.getSql()); total = this.queryTotal(countSql, mappedStatement, boundSql, connection); if (total <= 0) { return null; } } Pageable pageable = pageableRequest.getPageable(); String buildSql = concatOrderBy(originalSql, pageable); String paginationSql = dialect.buildPaginationSql(buildSql, pageable.getOffset(), pageable.getPageSize()); BoundSql newBs = MyBatisUtils.copyFromBoundSql(mappedStatement, boundSql, paginationSql, parameterObject); MappedStatement newMs = MyBatisUtils.copyFromMappedStatement(mappedStatement, new BoundSqlSqlSource(newBs)); args[MAPPED_STATEMENT_INDEX] = newMs; args[ROWBOUNDS_INDEX] = RowBounds.DEFAULT; Object result = invocation.proceed(); pageableRequest.setTotal(total); pageableRequest.setRecords((List) result); return result; }