Java Code Examples for org.apache.ibatis.mapping.StatementType#CALLABLE

The following examples show how to use org.apache.ibatis.mapping.StatementType#CALLABLE . 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 Project: mybaties   File: BaseExecutor.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: mybaties   File: BaseExecutor.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: mybatis   File: BaseExecutor.java    License: Apache License 2.0 6 votes vote down vote up
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 4
Source Project: mybatis   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select({ "{call sptest.getnames(", "#{lowestId,jdbcType=INTEGER,mode=IN},", "#{totalRows,jdbcType=INTEGER,mode=OUT})}" })
@ResultMap("nameResult")
@Options(statementType = StatementType.CALLABLE)
List<Name> getNamesAnnotatedWithXMLResultMap(Map<String, Object> parms);
 
Example 5
Source Project: mybaties   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select({ "{call sptest.adder(", "#{addend1,jdbcType=INTEGER,mode=IN},", "#{addend2,jdbcType=INTEGER,mode=IN},", "#{sum,jdbcType=INTEGER,mode=OUT})}" })
@Options(statementType = StatementType.CALLABLE)
Object adderAsSelectAnnotated(Parameter parameter);
 
Example 6
Source Project: mybaties   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Update({ "{call sptest.adder(", "#{addend1,jdbcType=INTEGER,mode=IN},", "#{addend2,jdbcType=INTEGER,mode=IN},", "#{sum,jdbcType=INTEGER,mode=OUT})}" })
@Options(statementType = StatementType.CALLABLE)
void adderAsUpdateAnnotated(Parameter parameter);
 
Example 7
Source Project: mybaties   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select("{call sptest.getname(#{id,jdbcType=INTEGER,mode=IN})}")
@Results({ @Result(column = "ID", property = "id"), @Result(column = "FIRST_NAME", property = "firstName"), @Result(column = "LAST_NAME", property = "lastName") })
@Options(statementType = StatementType.CALLABLE)
Name getNameAnnotated(Integer id);
 
Example 8
Source Project: mybaties   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select("{call sptest.getname(#{id,jdbcType=INTEGER,mode=IN})}")
@ResultMap("nameResult")
@Options(statementType = StatementType.CALLABLE)
Name getNameAnnotatedWithXMLResultMap(Integer id);
 
Example 9
Source Project: mybaties   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select({ "{call sptest.getnames(", "#{lowestId,jdbcType=INTEGER,mode=IN},", "#{totalRows,jdbcType=INTEGER,mode=OUT})}" })
@Results({ @Result(column = "ID", property = "id"), @Result(column = "FIRST_NAME", property = "firstName"), @Result(column = "LAST_NAME", property = "lastName") })
@Options(statementType = StatementType.CALLABLE)
List<Name> getNamesAnnotated(Map<String, Object> parms);
 
Example 10
Source Project: mybaties   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select({ "{call sptest.getnames(", "#{lowestId,jdbcType=INTEGER,mode=IN},", "#{totalRows,jdbcType=INTEGER,mode=OUT})}" })
@ResultMap("nameResult")
@Options(statementType = StatementType.CALLABLE)
List<Name> getNamesAnnotatedWithXMLResultMap(Map<String, Object> parms);
 
Example 11
Source Project: mybatis   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select({ "{call sptest.getnames(", "#{lowestId,jdbcType=INTEGER,mode=IN},", "#{totalRows,jdbcType=INTEGER,mode=OUT})}" })
@Results({ @Result(column = "ID", property = "id"), @Result(column = "FIRST_NAME", property = "firstName"), @Result(column = "LAST_NAME", property = "lastName") })
@Options(statementType = StatementType.CALLABLE)
List<Name> getNamesAnnotated(Map<String, Object> parms);
 
Example 12
Source Project: mybaties   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select({ "{call sptest.arraytest(", "#{ids,mode=IN,jdbcType=ARRAY},", "#{requestedRows,jdbcType=INTEGER,mode=OUT},", "#{returnedIds,mode=OUT,jdbcType=ARRAY})}" })
@Results({ @Result(column = "ID", property = "id"), @Result(column = "FIRST_NAME", property = "firstName"), @Result(column = "LAST_NAME", property = "lastName") })
@Options(statementType = StatementType.CALLABLE)
List<Name> getNamesWithArrayAnnotated(Map<String, Object> parms);
 
Example 13
Source Project: platform   File: PaginationInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 14
Source Project: mybatis   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select("{call sptest.getname(#{id,jdbcType=INTEGER,mode=IN})}")
@ResultMap("nameResult")
@Options(statementType = StatementType.CALLABLE)
Name getNameAnnotatedWithXMLResultMap(Integer id);
 
Example 15
Source Project: mybaties   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select("{call sptest.getnamesanditems()}")
@ResultMap({"nameResult","itemResult"})
@Options(statementType = StatementType.CALLABLE)
List<List<?>> getNamesAndItemsAnnotatedWithXMLResultMapArray();
 
Example 16
Source Project: mybatis   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select("{call sptest.getnamesanditems()}")
@ResultMap("nameResult,itemResult")
@Options(statementType = StatementType.CALLABLE)
List<List<?>> getNamesAndItemsAnnotatedWithXMLResultMap();
 
Example 17
Source Project: tutorials   File: PersonMapper.java    License: MIT License 4 votes vote down vote up
@Select(value = "{ CALL getPersonByProc( #{personId, mode=IN, jdbcType=INTEGER})}")
@Options(statementType = StatementType.CALLABLE)
public Person getPersonByProc(Integer personId);
 
Example 18
Source Project: mybatis   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select("{call sptest.getnamesanditems()}")
@ResultMap({"nameResult","itemResult"})
@Options(statementType = StatementType.CALLABLE)
List<List<?>> getNamesAndItemsAnnotatedWithXMLResultMapArray();
 
Example 19
Source Project: mybatis   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Select("{call sptest.getname(#{id,jdbcType=INTEGER,mode=IN})}")
@Results({ @Result(column = "ID", property = "id"), @Result(column = "FIRST_NAME", property = "firstName"), @Result(column = "LAST_NAME", property = "lastName") })
@Options(statementType = StatementType.CALLABLE)
Name getNameAnnotated(Integer id);
 
Example 20
Source Project: mybatis   File: SPMapper.java    License: Apache License 2.0 4 votes vote down vote up
@Update({ "{call sptest.adder(", "#{addend1,jdbcType=INTEGER,mode=IN},", "#{addend2,jdbcType=INTEGER,mode=IN},", "#{sum,jdbcType=INTEGER,mode=OUT})}" })
@Options(statementType = StatementType.CALLABLE)
void adderAsUpdateAnnotated(Parameter parameter);