• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SqlCommandType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: intercept

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的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: onInterceptor

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的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


示例3: prepareInsertAuthorMappedStatement

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (id,username,password,email,bio,favourite_section) values(?,?,?,?,?,?)"), SqlCommandType.INSERT)
      .parameterMap(
          new ParameterMap.Builder(
              config, "defaultParameterMap", Author.class,
              new ArrayList<ParameterMapping>() {
                {
                  add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
                  add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
                  add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
                  add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
                  add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
                  add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build());
                }
              }).build())
      .cache(authorCache).build();
  return ms;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:20,代码来源:ExecutorTestHelper.java


示例4: prepareSelectAuthorViaOutParams

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
public static MappedStatement prepareSelectAuthorViaOutParams(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "selectAuthorViaOutParams", new StaticSqlSource(config, "{call selectAuthorViaOutParams(?,?,?,?,?)}"), SqlCommandType.SELECT)
      .statementType(StatementType.CALLABLE)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
          new ArrayList<ParameterMapping>() {
            {
              add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
              add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
            }
          }).build())
      .resultMaps(new ArrayList<ResultMap>())
      .cache(authorCache).build();
  return ms;
}
 
开发者ID:txazo,项目名称:mybatis,代码行数:19,代码来源:ExecutorTestHelper.java


示例5: addMappedStatement

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的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


示例6: getSqlCommandType

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
private SqlCommandType getSqlCommandType(Method method) {
    Class<? extends Annotation> type = getSqlAnnotationType(method);

    if (type == null) {
        type = getSqlProviderAnnotationType(method);

        if (type == null) {
            return SqlCommandType.UNKNOWN;
        }

        if (type == SelectProvider.class) {
            type = Select.class;
        } else if (type == InsertProvider.class) {
            type = Insert.class;
        } else if (type == UpdateProvider.class) {
            type = Update.class;
        } else if (type == DeleteProvider.class) {
            type = Delete.class;
        }
    }

    return SqlCommandType.valueOf(type.getSimpleName().toUpperCase(Locale.ENGLISH));
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:24,代码来源:MybatisMapperAnnotationBuilder.java


示例7: genKeyGenerator

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
/**
 * <p>
 * 自定义 KEY 生成器
 * </p>
 */
public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant,
                                           String baseStatementId, LanguageDriver languageDriver) {
    Incrementer incrementer = GlobalConfigUtils.getIncrementer(builderAssistant.getConfiguration());
    if (null == incrementer) {
        throw new MybatisPlusException("Error: not configure Incrementer implementation class.");
    }
    String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
    Class<?> resultTypeClass = tableInfo.getKeySequence().idClazz();
    StatementType statementType = StatementType.PREPARED;
    String keyProperty = tableInfo.getKeyProperty();
    String keyColumn = tableInfo.getKeyColumn();
    SqlSource sqlSource = languageDriver.createSqlSource(builderAssistant.getConfiguration(),
            incrementer.getSequenceQuery(tableInfo.getKeySequence().value()), null);
    builderAssistant.addMappedStatement(id, sqlSource, statementType, SqlCommandType.SELECT, null, null, null,
            null, null, resultTypeClass, null, false, false, false,
            new NoKeyGenerator(), keyProperty, keyColumn, null, languageDriver, null);
    id = builderAssistant.applyCurrentNamespace(id, false);
    MappedStatement keyStatement = builderAssistant.getConfiguration().getMappedStatement(id, false);
    SelectKeyGenerator keyGenerator = new SelectKeyGenerator(keyStatement, true);
    builderAssistant.getConfiguration().addKeyGenerator(id, keyGenerator);
    return keyGenerator;
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:28,代码来源:TableInfoHelper.java


示例8: insert

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
public String insert(Class<?> entityType) {
	// 命令名称
	String statementId = buildStatementId(entityType, "insert");
	if (configuration.hasStatement(statementId)) {
		return statementId;
	}
	// 创建命令
	String sql = new SqlBuilder(entityType).insert();
	SqlSource sqlSource = new RawSqlSource(configuration, sql, null);
	MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, statementId, sqlSource,
			SqlCommandType.INSERT);
	// 判断是否需要自动生成主键
	EntityMetadata metadata = EntityMetadata.get(entityType);
	for (IdProperty idProperty : metadata.getIdProperties()) {
		KeyGenerator keyGenerator = idProperty.getKeyGenerator();
		if (keyGenerator == null) {
			continue;
		}
		String propertyName = idProperty.getName();
		String columnName = idProperty.getColumnName();
		statementBuilder.keyProperty(propertyName).keyColumn(columnName).keyGenerator(keyGenerator);
	}
	MappedStatement statement = statementBuilder.build();
	StatementResultMapHelper.addMappedStatement(configuration, statement);
	return statementId;
}
 
开发者ID:yaoakeji,项目名称:hibatis,代码行数:27,代码来源:MappedStatementBuilder.java


示例9: build

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver,
                         EntityInfo entity) {
    String[] names = GeneralSqlGenerator.methodDefines.updateName().split(",");
    for (String name : names) {
        String msId = entity.getMapperClass().getName() + "." + name;

        EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());

        String sql = buildUpdateSql(entityMapper, name.endsWith("Selective"));

        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql,
                entity.getEntityClass());

        MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration,
                msId, sqlSource, SqlCommandType.UPDATE);

        MappedStatement statement = statementBuilder.build();

        configuration.addMappedStatement(statement);
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:26,代码来源:UpdateBuilder.java


示例10: build

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver, EntityInfo entity) {
    String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.deleteName();

    // 从参数对象里提取注解信息
    EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
    // 生成sql
    String sql = buildDeleteSql(entityMapper);

    SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());

    MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource, SqlCommandType.DELETE);

    MappedStatement statement = statementBuilder.build();
    configuration.addMappedStatement(statement);
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:20,代码来源:DeleteBuilder.java


示例11: getDynamicDataSource

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的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


示例12: intercept

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的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


示例13: intercept

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
    MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
    Object record = invocation.getArgs()[1];
    if (record instanceof TimeTraceable) {
        TimeTraceable timeTraceableRecord = (TimeTraceable) record;
        LocalDateTime now = LocalDateTime.now();
        if (mappedStatement.getSqlCommandType().equals(SqlCommandType.INSERT)) {
            timeTraceableRecord.setCreateTime(now);
        }
        timeTraceableRecord.setUpdateTime(now);
    } else if (record instanceof TimestampTraceable) {
        TimestampTraceable timestampTraceableRecord = (TimestampTraceable) record;
        long timestamp = Instant.now().getEpochSecond();
        if (mappedStatement.getSqlCommandType().equals(SqlCommandType.INSERT)) {
            timestampTraceableRecord.setCreateTime(timestamp);
        }
        timestampTraceableRecord.setUpdateTime(timestamp);
    }
    return invocation.proceed();
}
 
开发者ID:superkoh,项目名称:k-framework,代码行数:22,代码来源:TimeTraceInterceptor.java


示例14: SqlCommand

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
public SqlCommand(Configuration configuration, Class<?> mapperInterface, Method method) {
  String statementName = mapperInterface.getName() + "." + method.getName();
  MappedStatement ms = null;
  if (configuration.hasStatement(statementName)) {
    ms = configuration.getMappedStatement(statementName);
  } else if (!mapperInterface.equals(method.getDeclaringClass())) { // issue #35
    String parentStatementName = method.getDeclaringClass().getName() + "." + method.getName();
    if (configuration.hasStatement(parentStatementName)) {
      ms = configuration.getMappedStatement(parentStatementName);
    }
  }
  if (ms == null) {
    if(method.getAnnotation(Flush.class) != null){
      name = null;
      type = SqlCommandType.FLUSH;
    } else {
      throw new BindingException("Invalid bound statement (not found): " + statementName);
    }
  } else {
    name = ms.getId();
    type = ms.getSqlCommandType();
    if (type == SqlCommandType.UNKNOWN) {
      throw new BindingException("Unknown execution method for: " + name);
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:27,代码来源:MapperMethod.java


示例15: prepareInsertAuthorMappedStatementWithAutoKey

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatementWithAutoKey(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (username,password,email,bio,favourite_section) values(?,?,?,?,?)"), SqlCommandType.INSERT)
      .parameterMap(
          new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
            {
              add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
              add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
              add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
              add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
              add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build());
            }
          }).build())
      .cache(authorCache)
      .keyGenerator(new Jdbc3KeyGenerator())
      .keyProperty("id")
      .build();
  return ms;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:20,代码来源:ExecutorTestHelper.java


示例16: prepareUpdateAuthorMappedStatement

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
public static MappedStatement prepareUpdateAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "updateAuthor", new StaticSqlSource(config,"UPDATE author SET username = ?, password = ?, email = ?, bio = ? WHERE id = ?"), SqlCommandType.UPDATE)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
          new ArrayList<ParameterMapping>() {
            {
              add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
              add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
              add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
              add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
              add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
            }
          }).build())
      .cache(authorCache).build();
  return ms;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:17,代码来源:ExecutorTestHelper.java


示例17: createSelectAuthorWithIDof99MappedStatement

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
public static MappedStatement createSelectAuthorWithIDof99MappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config,"SELECT * FROM author WHERE id = 99"), SqlCommandType.SELECT)
      .statementType(StatementType.STATEMENT)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>()).build())
      .resultMaps(new ArrayList<ResultMap>() {
        {
          add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() {
            {
              add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).build());
              add(new ResultMapping.Builder(config, "username", "username", registry.getTypeHandler(String.class)).build());
              add(new ResultMapping.Builder(config, "password", "password", registry.getTypeHandler(String.class)).build());
              add(new ResultMapping.Builder(config, "email", "email", registry.getTypeHandler(String.class)).build());
              add(new ResultMapping.Builder(config, "bio", "bio", registry.getTypeHandler(String.class)).build());
            }
          }).build());
        }
      }).build();
  return ms;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:21,代码来源:ExecutorTestHelper.java


示例18: getSqlCommandType

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
private SqlCommandType getSqlCommandType(Method method) {
  Class<? extends Annotation> type = getSqlAnnotationType(method);

  if (type == null) {
    type = getSqlProviderAnnotationType(method);

    if (type == null) {
      return SqlCommandType.UNKNOWN;
    }

    if (type == SelectProvider.class) {
      type = Select.class;
    } else if (type == InsertProvider.class) {
      type = Insert.class;
    } else if (type == UpdateProvider.class) {
      type = Update.class;
    } else if (type == DeleteProvider.class) {
      type = Delete.class;
    }
  }

  return SqlCommandType.valueOf(type.getSimpleName().toUpperCase(Locale.ENGLISH));
}
 
开发者ID:txazo,项目名称:mybatis,代码行数:24,代码来源:MapperAnnotationBuilder.java


示例19: intercept

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
@Override
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:baomidou,项目名称:mybatis-plus,代码行数:26,代码来源:SqlExplainInterceptor.java


示例20: genKeyGenerator

import org.apache.ibatis.mapping.SqlCommandType; //导入依赖的package包/类
/**
 * <p>
 * 自定义 KEY 生成器
 * </p>
 */
public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant,
                                           String baseStatementId, LanguageDriver languageDriver) {
    IKeyGenerator keyGenerator = GlobalConfigUtils.getKeyGenerator(builderAssistant.getConfiguration());
    if (null == keyGenerator) {
        throw new IllegalArgumentException("not configure IKeyGenerator implementation class.");
    }
    String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
    Class<?> resultTypeClass = tableInfo.getKeySequence().clazz();
    StatementType statementType = StatementType.PREPARED;
    String keyProperty = tableInfo.getKeyProperty();
    String keyColumn = tableInfo.getKeyColumn();
    SqlSource sqlSource = languageDriver.createSqlSource(builderAssistant.getConfiguration(),
            keyGenerator.executeSql(tableInfo.getKeySequence().value()), null);
    builderAssistant.addMappedStatement(id, sqlSource, statementType, SqlCommandType.SELECT, null, null, null,
            null, null, resultTypeClass, null, false, false, false,
            new NoKeyGenerator(), keyProperty, keyColumn, null, languageDriver, null);
    id = builderAssistant.applyCurrentNamespace(id, false);
    MappedStatement keyStatement = builderAssistant.getConfiguration().getMappedStatement(id, false);
    SelectKeyGenerator selectKeyGenerator = new SelectKeyGenerator(keyStatement, true);
    builderAssistant.getConfiguration().addKeyGenerator(id, selectKeyGenerator);
    return selectKeyGenerator;
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:28,代码来源:TableInfoHelper.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Predicates类代码示例发布时间:2022-05-21
下一篇:
Java ApiInfo类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap