當前位置: 首頁>>代碼示例>>Java>>正文


Java MappedStatement類代碼示例

本文整理匯總了Java中org.apache.ibatis.mapping.MappedStatement的典型用法代碼示例。如果您正苦於以下問題:Java MappedStatement類的具體用法?Java MappedStatement怎麽用?Java MappedStatement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MappedStatement類屬於org.apache.ibatis.mapping包,在下文中一共展示了MappedStatement類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onInterceptor

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
@Override
public Object onInterceptor(Invocation invocation) throws Throwable {

    Object[] objects = invocation.getArgs();
    MappedStatement ms = (MappedStatement) objects[0];
    //已指定強製使用
    if (DataSourceContextHolder.get().isForceUseMaster()) {
        logger.debug("Method[{}] force use Master..", ms.getId());
        return null;
    }

    //讀方法
    if (ms.getSqlCommandType().equals(SqlCommandType.SELECT)) {
        //!selectKey 為自增id查詢主鍵(SELECT LAST_INSERT_ID() )方法,使用主庫
        if (!ms.getId().contains(SelectKeyGenerator.SELECT_KEY_SUFFIX)) {
            DataSourceContextHolder.get().useSlave(true);
            logger.debug("Method[{} use Slave Strategy..", ms.getId());
        }
    } else {
        logger.debug("Method[{}] use Master Strategy..", ms.getId());
        DataSourceContextHolder.get().useSlave(false);
    }

    return null;
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:26,代碼來源:RwRouteHandler.java

示例2: genSql

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的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: getMappedStatement

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
@Override
public MappedStatement getMappedStatement(String id) {
    Exception exception = null;
    MappedStatement mappedStatement = null;
    for (SqlSessionFactory sqlSessionFactory : getSqlSessionFactories()) {
        try {
            mappedStatement = sqlSessionFactory.getConfiguration().getMappedStatement(id);
        } catch (Exception e) {
            // ignore exception
            exception = e;
        }

        if (mappedStatement != null) {
            return mappedStatement;
        }
    }

    throw new BindingException("Invalid bound statement (not found): " + id, exception);
}
 
開發者ID:devpage,項目名稱:sharding-quickstart,代碼行數:20,代碼來源:MyBatisConfigurationsWrapper.java

示例4: copyFromMappedStatement

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
private MappedStatement copyFromMappedStatement(MappedStatement ms,
		SqlSource newSqlSource) {
	MappedStatement.Builder builder = new MappedStatement.Builder(
			ms.getConfiguration(), ms.getId(), newSqlSource,
			ms.getSqlCommandType());
	builder.resource(ms.getResource());
	builder.fetchSize(ms.getFetchSize());
	builder.statementType(ms.getStatementType());
	builder.keyGenerator(ms.getKeyGenerator());
	if (null != ms.getKeyProperties()) {
		for (String keyProperty : ms.getKeyProperties()) {
			builder.keyProperty(keyProperty);
		}
	}
	builder.timeout(ms.getTimeout());
	builder.parameterMap(ms.getParameterMap());
	builder.resultMaps(ms.getResultMaps());
	builder.cache(ms.getCache());
	return builder.build();
}
 
開發者ID:jiangzongyao,項目名稱:kettle_support_kettle8.0,代碼行數:21,代碼來源:PaginationInterceptor.java

示例5: intercept

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
@Override
public Object intercept(Invocation invocation) throws Throwable {
	// TODO Auto-generated method stub
	if (invocation.getTarget() instanceof RoutingStatementHandler) {
		StatementHandler statementHandler = (RoutingStatementHandler) invocation.getTarget();
		MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
		MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
		String mapperId = mappedStatement.getId();
		String mapperClassName = mapperId.substring(0, mapperId.lastIndexOf("."));
		Class<?> mapperClass = Class.forName(mapperClassName);
		if (isDaoMapper(mapperClass)&&mapperId.endsWith(".insertUseReturnGeneratedKeys")) {
			BaseStatementHandler baseStatementHandler = (BaseStatementHandler) metaStatementHandler.getValue("delegate");
			if ("query".equals(invocation.getMethod().getName())) {
				return handPreparedStatementHandlerQuery(invocation, baseStatementHandler);
			} else if ("prepare".equals(invocation.getMethod().getName())) {
				return handPreparedStatementHandlerPrepare(invocation, baseStatementHandler);
			}
		}
	}
	return invocation.proceed();
}
 
開發者ID:wulizhong,項目名稱:mybatis-dao,代碼行數:22,代碼來源:DaoPlugin.java

示例6: addMappedStatement

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
public MappedStatement addMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource,
                                            SqlCommandType sqlCommandType, Class<?> parameterClass, String resultMap, Class<?> resultType,
                                            KeyGenerator keyGenerator, String keyProperty, String keyColumn) {
      String statementName = mapperClass.getName() + "." + id;
      if (configuration.hasStatement(statementName)) {
          System.err.println("{" + statementName
                  + "} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.");
          return null;
      }
/* 緩存邏輯處理 */
      boolean isSelect = false;
      if (sqlCommandType == SqlCommandType.SELECT) {
          isSelect = true;
      }
      return builderAssistant.addMappedStatement(id, sqlSource, StatementType.PREPARED, sqlCommandType, null, null, null,
              parameterClass, resultMap, resultType, null, !isSelect, isSelect, false, keyGenerator, keyProperty, keyColumn,
              configuration.getDatabaseId(), languageDriver, null);
  }
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:19,代碼來源:AutoSqlInjector.java

示例7: intercept

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的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

示例8: intercept

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
@Override
public Object intercept(Invocation invocation) throws Throwable {
    Author author = authorAware.getAuthor();
    if (null == author) {
        return invocation.proceed();
    }
    MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
    Object record = invocation.getArgs()[1];
    if (record instanceof AuthorTraceable) {
        AuthorTraceable authorTraceableRecord = (AuthorTraceable) record;
        if (mappedStatement.getSqlCommandType().equals(SqlCommandType.INSERT)) {
            authorTraceableRecord.setCreateUser(author.getAuthorId());
        }
        authorTraceableRecord.setUpdateUser(author.getAuthorId());
    }
    return invocation.proceed();
}
 
開發者ID:superkoh,項目名稱:k-framework,代碼行數:18,代碼來源:AuthorTraceInterceptor.java

示例9: insertList

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
/**
 * 批量插入
 *
 * @param ms
 */
public String insertList(MappedStatement ms) {
    final Class<?> entityClass = getEntityClass(ms);
    //開始拚sql
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.insertIntoTable(entityClass, tableName(entityClass)));
    sql.append(SqlHelper.insertColumns(entityClass, true, false, false));
    sql.append(" VALUES ");
    sql.append("<foreach collection=\"list\" item=\"record\" separator=\",\" >");
    sql.append("<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">");
    //獲取全部列
    Set<EntityColumn> columnList = EntityHelper.getColumns(entityClass);
    //當某個列有主鍵策略時,不需要考慮他的屬性是否為空,因為如果為空,一定會根據主鍵策略給他生成一個值
    for (EntityColumn column : columnList) {
        if (!column.isId() && column.isInsertable()) {
            sql.append(column.getColumnHolder("record") + ",");
        }
    }
    sql.append("</trim>");
    sql.append("</foreach>");
    return sql.toString();
}
 
開發者ID:Yanweichen,項目名稱:MybatisGeneatorUtil,代碼行數:27,代碼來源:SpecialProvider.java

示例10: deleteByIds

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
/**
 * 根據主鍵字符串進行刪除,類中隻有存在一個帶有@Id注解的字段
 *
 * @param ms
 * @return
 */
public String deleteByIds(MappedStatement ms) {
    final Class<?> entityClass = getEntityClass(ms);
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass)));
    Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
    if (columnList.size() == 1) {
        EntityColumn column = columnList.iterator().next();
        sql.append(" where ");
        sql.append(column.getColumn());
        sql.append(" in (${_parameter})");
    } else {
        throw new RuntimeException("繼承 deleteByIds 方法的實體類[" + entityClass.getCanonicalName() + "]中必須隻有一個帶有 @Id 注解的字段");
    }
    return sql.toString();
}
 
開發者ID:Yanweichen,項目名稱:MybatisGeneatorUtil,代碼行數:22,代碼來源:IdsProvider.java

示例11: selectByIds

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
/**
 * 根據主鍵字符串進行查詢,類中隻有存在一個帶有@Id注解的字段
 *
 * @param ms
 * @return
 */
public String selectByIds(MappedStatement ms) {
    final Class<?> entityClass = getEntityClass(ms);
    //將返回值修改為實體類型
    setResultType(ms, entityClass);
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.selectAllColumns(entityClass));
    sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
    Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
    if (columnList.size() == 1) {
        EntityColumn column = columnList.iterator().next();
        sql.append(" where ");
        sql.append(column.getColumn());
        sql.append(" in (${_parameter})");
    } else {
        throw new RuntimeException("繼承 selectByIds 方法的實體類[" + entityClass.getCanonicalName() + "]中必須隻有一個帶有 @Id 注解的字段");
    }
    return sql.toString();
}
 
開發者ID:Yanweichen,項目名稱:MybatisGeneatorUtil,代碼行數:25,代碼來源:IdsProvider.java

示例12: executeQueryCount

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的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

示例13: getDynamicDataSource

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的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

示例14: processConfiguration

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
/**
 * 配置指定的接口
 *
 * @param configuration
 * @param mapperInterface
 */
public void processConfiguration(Configuration configuration, Class<?> mapperInterface) {
    String prefix;
    if (mapperInterface != null) {
        prefix = mapperInterface.getCanonicalName();
    } else {
        prefix = "";
    }
    for (Object object : new ArrayList<Object>(configuration.getMappedStatements())) {
        if (object instanceof MappedStatement) {
            MappedStatement ms = (MappedStatement) object;
            if (ms.getId().startsWith(prefix) && isMapperMethod(ms.getId())) {
                if (ms.getSqlSource() instanceof ProviderSqlSource) {
                    setSqlSource(ms);
                }
            }
        }
    }
}
 
開發者ID:godlike110,項目名稱:tk-mybatis,代碼行數:25,代碼來源:MapperHelper.java

示例15: intercept

import org.apache.ibatis.mapping.MappedStatement; //導入依賴的package包/類
@Override
public Object intercept(Invocation invocation) throws Throwable {

    boolean synchronizationActive = TransactionSynchronizationManager.isSynchronizationActive();
    //如果沒有事務
    if (!synchronizationActive) {
        Object[] objects = invocation.getArgs();
        MappedStatement ms = (MappedStatement) objects[0];

        DynamicDataSourceGlobal dynamicDataSourceGlobal;

        if ((dynamicDataSourceGlobal = CACHE_MAP.get(ms.getId())) == null) {
            dynamicDataSourceGlobal = getDynamicDataSource(ms, objects[1]);
            LOGGER.warn("設置方法[{}] use [{}] Strategy, SqlCommandType [{}]..", ms.getId(), dynamicDataSourceGlobal.name(), ms.getSqlCommandType().name());
            CACHE_MAP.put(ms.getId(), dynamicDataSourceGlobal);
        }
        DynamicDataSourceHolder.putDataSource(dynamicDataSourceGlobal);
    }

    return invocation.proceed();
}
 
開發者ID:ruyangit,項目名稱:angit,代碼行數:22,代碼來源:DynamicPlugin.java


注:本文中的org.apache.ibatis.mapping.MappedStatement類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。