當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。