当前位置: 首页>>代码示例>>Java>>正文


Java BoundSql类代码示例

本文整理汇总了Java中org.apache.ibatis.mapping.BoundSql的典型用法代码示例。如果您正苦于以下问题:Java BoundSql类的具体用法?Java BoundSql怎么用?Java BoundSql使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BoundSql类属于org.apache.ibatis.mapping包,在下文中一共展示了BoundSql类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intercept

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
public Object intercept(Invocation invocation) throws Throwable {
    /**
     * 处理 DELETE UPDATE 语句
     */
    MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
    if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
        Executor executor = (Executor) invocation.getTarget();
        Configuration configuration = ms.getConfiguration();
        Object parameter = invocation.getArgs()[1];
        BoundSql boundSql = ms.getBoundSql(parameter);
        Connection connection = executor.getTransaction().getConnection();
        String databaseVersion = connection.getMetaData().getDatabaseProductVersion();
        if (GlobalConfigUtils.getDbType(configuration).equals(DBType.MYSQL)
                && VersionUtils.compare(minMySQLVersion, databaseVersion)) {
            logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!");
            return invocation.proceed();
        }
        /**
         * 执行 SQL 分析
         */
        sqlExplain(configuration, ms, boundSql, connection, parameter);
    }
    return invocation.proceed();
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:25,代码来源:SqlExplainInterceptor.java

示例2: genSql

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
private void genSql(Invocation invocation, SplitRequest splitRequest) {
    try {
        genParams(invocation, splitRequest);

        BoundSql boundSql = ((MappedStatement)invocation.getArgs()[0]).getBoundSql(invocation.getArgs()[1]);
        Statement statement = CCJSqlParserUtil.parse(boundSql.getSql());
        String sql = parseSql(statement);

        FieldUtil.setValue("sql", BoundSql.class, boundSql, sql);
        MappedStatement mappedStatement = copyMappedStatement((MappedStatement)invocation.getArgs()[0], boundSql);
        invocation.getArgs()[0] = mappedStatement;

    } catch (OgnlException ognl) {
        logger.error("ognl exception", ognl);
    } catch (JSQLParserException e) {
        logger.error("jSqlParser exception", e);
    } catch (Exception e1) {
        logger.error("error happend", e1);
    }
}
 
开发者ID:justice-code,项目名称:QiuQiu,代码行数:21,代码来源:SplitTableInterceptor.java

示例3: intercept

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
    if (!statementTracer.isTraceEnabled()) {
        return invocation.proceed();
    }
    MetaObject metaObject = MetaObjectUtils.findTargetObject(invocation);
    BoundSql boundSql = MetaObjectUtils.getBoundSql(metaObject);
    Configuration configuration = MetaObjectUtils.getConfiguration(metaObject);
    Exception queryException = null;
    try {
        beginTrace(boundSql.getSql(), configuration.getEnvironment());
        return invocation.proceed();
    } catch (Exception ex) {
        queryException = ex;
        throw ex;
    } finally {
        statementTracer.endTrace(0, queryException);
    }
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:20,代码来源:MybatisTracingInterceptor.java

示例4: intercept

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
/**
* 清空缓存
*/
  @Override
  public Object intercept(Invocation invocation) throws Throwable {
      StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
      BoundSql boundSql = statementHandler.getBoundSql();
      String sql = boundSql.getSql().trim().toLowerCase();
      sql=StringUtils.deleteExcessBlank(sql);        
      String tableName=null;       
      String[] words=sql.split(" ");

      if(ArrayUtils.isNotEmpty(words)){
          if(sql.contains("delete")&&words[0].equals("delete")){
          	tableName=words[2];
          }else if(sql.contains("update")&&words[0].equals("update")){
          	tableName=words[1];
          }
          if(tableName!=null){
              cacheOperator.clean(tableName);
          }
      }
      return invocation.proceed();
  }
 
开发者ID:endend20000,项目名称:mybatisx,代码行数:25,代码来源:StatementInterceptor.java

示例5: intercept

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
	RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();
	StatementHandler delegate = (StatementHandler) ReflectUtil.getFieldValue(handler, "delegate");
	BoundSql boundSql = delegate.getBoundSql();
	Object obj = boundSql.getParameterObject();
	Page page = seekPage(obj);
	if (page != null) {
		MappedStatement mappedStatement = (MappedStatement) ReflectUtil.getFieldValue(delegate, "mappedStatement");
		Connection connection = (Connection) invocation.getArgs()[0];
		String sql = boundSql.getSql();
		this.setTotalRecord(page, mappedStatement, connection);
		String pageSql = this.getPageSql(page, sql);
		ReflectUtil.setFieldValue(boundSql, "sql", pageSql);
	}
	return invocation.proceed();
}
 
开发者ID:lemon-china,项目名称:lemon-mybatis-plus,代码行数:18,代码来源:PageInterceptor.java

示例6: intercept

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
/**
 * 拦截后要执行的方法
 */
@Override
public Object intercept(Invocation invocation) throws Throwable {
    Page<?> page = PageThreadLocal.getThreadLocalPage();
    if (page == null) {
        return invocation.proceed();
    }
    PageThreadLocal.removeThreadLocalPage();
    RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();
    // 通过反射获取到当前RoutingStatementHandler对象的delegate属性
    StatementHandler delegate = (StatementHandler) ReflectUtil.getFieldValue(handler, "delegate");
    BoundSql boundSql = delegate.getBoundSql();
    MappedStatement mappedStatement = (MappedStatement) ReflectUtil.getFieldValue(delegate, "mappedStatement");
    // 获取当前要执行的Sql语句,也就是我们直接在Mapper映射语句中写的Sql语句
    String sql = boundSql.getSql();
    // 是否查询总页数和总数据 默认为TRUE
    if (page.getTotalFlag()) {
        // 给当前的page参数对象设置总记录数
        this.setTotalRecord(page, mappedStatement, boundSql, sql);
    }

    String pageSql = this.getPageSql(sql, page);
    // 利用反射设置当前BoundSql对应的sql属性为我们建立好的分页Sql语句
    ReflectUtil.setFieldValue(boundSql, "sql", pageSql);
    return invocation.proceed();
}
 
开发者ID:tonyruiyu,项目名称:dubbo-mock,代码行数:29,代码来源:PageInterceptor.java

示例7: getCount

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
/**
 * 查询总纪录数
 *
 * @param mappedStatement mapped
 * @param parameterObject 参数
 * @param boundSql        boundSql
 * @param dialect         database dialect
 * @return 总记录数
 * @throws java.sql.SQLException sql查询错误
 */
public static int getCount(
                           final MappedStatement mappedStatement, final Transaction transaction, final Object parameterObject,
                           final BoundSql boundSql, Dialect dialect) throws SQLException {
    final String count_sql = dialect.getCountSQL();
    logger.debug("Total count SQL [{}] ", count_sql);
    logger.debug("Total count Parameters: {} ", parameterObject);

    Connection connection = transaction.getConnection();
    PreparedStatement countStmt = connection.prepareStatement(count_sql);
    DefaultParameterHandler handler = new DefaultParameterHandler(mappedStatement,parameterObject,boundSql);
    handler.setParameters(countStmt);

    ResultSet rs = countStmt.executeQuery();
    int count = 0;
    if (rs.next()) {
        count = rs.getInt(1);
    }
    logger.debug("Total count: {}", count);
    return count;

}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:32,代码来源:SQLHelp.java

示例8: executeQueryCount

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private Long executeQueryCount(Executor executor, MappedStatement countMs, Object parameter,
                               BoundSql boundSql, RowBounds rowBounds,
                               ResultHandler resultHandler) throws IllegalAccessException,
        SQLException {
    CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT,
            boundSql);

    String orignSql = boundSql.getSql().replaceAll(";$", "");
    // count sql
    String countSql = PageSqlUtils.getCountSql(orignSql);

    BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql,
            boundSql.getParameterMappings(), parameter);
    // 执行 count 查询
    Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT,
            resultHandler, countKey, countBoundSql);
    Long count = (Long) ((List) countResultList).get(0);
    return count;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:21,代码来源:PaginationHandler.java

示例9: getDynamicDataSource

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
/**
 * 获得动态数据源
 *
 * @param ms              MappedStatement
 * @param parameterObject Parameter
 * @return DynamicDataSourceGlobal
 */
private DynamicDataSourceGlobal getDynamicDataSource(MappedStatement ms, Object parameterObject) {
    DynamicDataSourceGlobal dynamicDataSourceGlobal;
    //读方法
    if (ms.getSqlCommandType().equals(SqlCommandType.SELECT)) {
        //!selectKey 为自增id查询主键(SELECT LAST_INSERT_ID() )方法,使用主库
        if (ms.getId().contains(SelectKeyGenerator.SELECT_KEY_SUFFIX)) {
            dynamicDataSourceGlobal = DynamicDataSourceGlobal.WRITE;
        } else {
            BoundSql boundSql = ms.getSqlSource().getBoundSql(parameterObject);
            String sql = boundSql.getSql().toLowerCase(Locale.CHINA).replaceAll("[\\t\\n\\r]", " ");
            if (sql.matches(REGEX)) {
                dynamicDataSourceGlobal = DynamicDataSourceGlobal.WRITE;
            } else {
                dynamicDataSourceGlobal = DynamicDataSourceGlobal.READ;
            }
        }
    } else {
        dynamicDataSourceGlobal = DynamicDataSourceGlobal.WRITE;
    }
    return dynamicDataSourceGlobal;
}
 
开发者ID:ruyangit,项目名称:angit,代码行数:29,代码来源:DynamicPlugin.java

示例10: getBoundSql

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
public BoundSql getBoundSql(Object parameterObject) {
    DynamicContext context = new DynamicContext(configuration, parameterObject);
    rootSqlNode.apply(context);
    SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
    Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
    SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
    if (count) {
        sqlSource = getCountSqlSource(configuration, sqlSource, parameterObject);
    } else {
        sqlSource = getPageSqlSource(configuration, sqlSource, parameterObject);
    }
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
    // 设置条件参数
    for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
        boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
    }
    return boundSql;
}
 
开发者ID:PekingGo,项目名称:ipayquery,代码行数:19,代码来源:SqlUtil.java

示例11: doQueryCursor

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
@Override
protected <E> Cursor<E> doQueryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds, BoundSql boundSql) throws SQLException {
  Configuration configuration = ms.getConfiguration();
  StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, null, boundSql);
  Statement stmt = prepareStatement(handler, ms.getStatementLog());
  return handler.<E>queryCursor(stmt);
}
 
开发者ID:txazo,项目名称:mybatis,代码行数:8,代码来源:ReuseExecutor.java

示例12: handleLocallyCachedOutputParameters

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
private void handleLocallyCachedOutputParameters(MappedStatement ms, CacheKey key, Object parameter, BoundSql boundSql) {
  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);
        }
      }
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:17,代码来源:BaseExecutor.java

示例13: RoutingStatementHandler

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {

    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());
    }

  }
 
开发者ID:txazo,项目名称:mybatis,代码行数:18,代码来源:RoutingStatementHandler.java

示例14: doQuery

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
@Override
public <E> List<E> doQuery(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql)
    throws SQLException {
  Statement stmt = null;
  try {
    flushStatements();
    Configuration configuration = ms.getConfiguration();
    StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameterObject, rowBounds, resultHandler, boundSql);
    Connection connection = getConnection(ms.getStatementLog());
    stmt = handler.prepare(connection, transaction.getTimeout());
    handler.parameterize(stmt);
    return handler.<E>query(stmt, resultHandler);
  } finally {
    closeStatement(stmt);
  }
}
 
开发者ID:txazo,项目名称:mybatis,代码行数:17,代码来源:BatchExecutor.java

示例15: BaseStatementHandler

import org.apache.ibatis.mapping.BoundSql; //导入依赖的package包/类
protected BaseStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
  this.configuration = mappedStatement.getConfiguration();
  this.executor = executor;
  this.mappedStatement = mappedStatement;
  this.rowBounds = rowBounds;

  this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
  this.objectFactory = configuration.getObjectFactory();

  if (boundSql == null) { // issue #435, get the key before calculating the statement
    generateKeys(parameterObject);
    boundSql = mappedStatement.getBoundSql(parameterObject);
  }

  this.boundSql = boundSql;

  this.parameterHandler = configuration.newParameterHandler(mappedStatement, parameterObject, boundSql);
  this.resultSetHandler = configuration.newResultSetHandler(executor, mappedStatement, rowBounds, parameterHandler, resultHandler, boundSql);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:20,代码来源:BaseStatementHandler.java


注:本文中的org.apache.ibatis.mapping.BoundSql类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。