Example usage for org.apache.ibatis.scripting LanguageDriver createSqlSource

List of usage examples for org.apache.ibatis.scripting LanguageDriver createSqlSource

Introduction

In this page you can find the example usage for org.apache.ibatis.scripting LanguageDriver createSqlSource.

Prototype

SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType);

Source Link

Document

Creates an SqlSource that will hold the statement read from an annotation.

Usage

From source file:com.baomidou.mybatisplus.MybatisMapperAnnotationBuilder.java

License:Apache License

private SqlSource buildSqlSourceFromStrings(String[] strings, Class<?> parameterTypeClass,
        LanguageDriver languageDriver) {
    final StringBuilder sql = new StringBuilder();
    for (String fragment : strings) {
        sql.append(fragment);//from   w w w .  jav a2 s .  c  om
        sql.append(" ");
    }
    return languageDriver.createSqlSource(configuration, sql.toString().trim(), parameterTypeClass);
}

From source file:com.baomidou.mybatisplus.toolkit.TableInfoHelper.java

License:Apache License

public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant,
        String baseStatementId, LanguageDriver languageDriver) {
    DBType dbType = GlobalConfiguration.getDbType(builderAssistant.getConfiguration());
    if (dbType != DBType.ORACLE)
        throw new IllegalArgumentException("??Oracle?");
    String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
    Class<?> resultTypeClass = tableInfo.getKeySequence().idClazz();
    Class<?> parameterTypeClass = null;
    StatementType statementType = StatementType.PREPARED;
    String keyProperty = tableInfo.getKeyProperty();
    String keyColumn = tableInfo.getKeyColumn();
    boolean executeBefore = true;
    boolean useCache = false;
    KeyGenerator keyGenerator = new NoKeyGenerator();
    Integer fetchSize = null;/*w  w  w.  ja  v a2 s  .c  o  m*/
    Integer timeout = null;
    boolean flushCache = false;
    String parameterMap = null;
    String resultMap = null;
    ResultSetType resultSetTypeEnum = null;
    //??ORACLE????
    String sql = "select " + tableInfo.getKeySequence().value() + ".nextval from dual";
    SqlSource sqlSource = languageDriver.createSqlSource(builderAssistant.getConfiguration(), sql.trim(), null);
    SqlCommandType sqlCommandType = SqlCommandType.SELECT;
    builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout,
            parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum, flushCache,
            useCache, false, keyGenerator, keyProperty, keyColumn, null, languageDriver, null);
    id = builderAssistant.applyCurrentNamespace(id, false);
    MappedStatement keyStatement = builderAssistant.getConfiguration().getMappedStatement(id, false);
    SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore);
    builderAssistant.getConfiguration().addKeyGenerator(id, answer);
    return answer;
}

From source file:com.sinotopia.mybatis.plus.toolkit.TableInfoHelper.java

License:Apache License

/**
 * <p>//from   ww  w .  j ava  2  s  . com
 *  KEY ?
 * </p>
 */
public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant,
        String baseStatementId, LanguageDriver languageDriver) {
    IKeyGenerator keyGenerator = GlobalConfiguration.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().idClazz();
    StatementType statementType = StatementType.PREPARED;
    String keyProperty = tableInfo.getKeyProperty();
    String keyColumn = tableInfo.getKeyColumn();
    SqlSource sqlSource = languageDriver.createSqlSource(builderAssistant.getConfiguration(),
            keyGenerator.executeSql(tableInfo), 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 answer = new SelectKeyGenerator(keyStatement, true);
    builderAssistant.getConfiguration().addKeyGenerator(id, answer);
    return answer;
}