当前位置: 首页>>代码示例>>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;未经允许,请勿转载。