Example usage for org.apache.ibatis.mapping ParameterMap getType

List of usage examples for org.apache.ibatis.mapping ParameterMap getType

Introduction

In this page you can find the example usage for org.apache.ibatis.mapping ParameterMap getType.

Prototype

public Class<?> getType() 

Source Link

Usage

From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java

License:Open Source License

public void refresh(MappedStatement mappedStatement) {
    Integer timeout = null;/*from ww  w  .j  a v a2 s .c  om*/
    Class<?> parameterType = entityClass;

    ///~~~~~~~~~~
    boolean flushCache = true;
    boolean useCache = false;
    boolean resultOrdered = false;
    KeyGenerator keyGenerator = new NoKeyGenerator();
    String keyProperty = null;
    String keyColumn = null;

    Id id = AnnotationUtils.findDeclaredAnnotation(Id.class, entityClass);
    GeneratedValue generatedValue = AnnotationUtils.findDeclaredAnnotation(GeneratedValue.class, entityClass);
    if (id != null) {
        String keyStatementId = entityClass.getName() + ".insert" + SelectKeyGenerator.SELECT_KEY_SUFFIX;
        if (!sharded) {

            if (containSn)
                snGenerators.put(mappedStatement.getId(), new SnGenerator());
            if (configuration.hasKeyGenerator(keyStatementId)) {
                keyGenerator = configuration.getKeyGenerator(keyStatementId);
            } else if (generatedValue != null) {
                if (generatedValue.strategy() == GenerationType.UUID) {
                    keyGenerator = new UuidKeyGenerator(generatedValue.length());
                }
            } else {
                keyGenerator = id.generatedKeys() ? new Jdbc4KeyGenerator() : new NoKeyGenerator();
            }
        } else {
            if (containSn)
                shardSnGenerators.put(mappedStatement.getId(), new ShardSnGenerator());
            if (generatedValue != null) {
                if (generatedValue.strategy() == GenerationType.UUID) {
                    shardedKeyGenerators.put(mappedStatement.getId(),
                            new ShardUuidKeyGenerator(generatedValue.length()));
                } else if (generatedValue.strategy() == GenerationType.TABLE
                        || generatedValue.strategy() == GenerationType.AUTO) {
                    shardedKeyGenerators.put(mappedStatement.getId(), new ShardJdbc4KeyGenerator());
                }
            }
            //                shardedKeyGenerators.put(statementId, new shardeduu)
        }
        keyProperty = idField.getName();
        keyColumn = StringUtils.isBlank(id.column()) ? CaseFormatUtils.camelToUnderScore(idField.getName())
                : id.column();
    }

    SqlSource sqlSource = mappedStatement.getSqlSource();
    String parameterMap = null;
    Iterator<String> parameterMapNames = configuration.getParameterMapNames().iterator();
    while (parameterMapNames.hasNext()) {
        String name = parameterMapNames.next();
        ParameterMap temp = configuration.getParameterMap(name);
        if (temp.getType().equals(entityClass)) {
            parameterMap = temp.getId();
            break;
        }
    }
    assistant.addMappedStatement(mappedStatement.getId(), sqlSource, StatementType.PREPARED,
            SqlCommandType.INSERT, null, timeout, parameterMap, parameterType, null, null, null, flushCache,
            useCache, resultOrdered, keyGenerator, keyProperty, keyColumn, databaseId, lang);
}

From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java

License:Open Source License

private void buildInsert(String statementId) {
    ///*  w  w  w .  j a v  a 2  s.  c  om*/
    Integer timeout = null;
    Class<?> parameterType = entityClass;

    ///~~~~~~~~~~
    boolean flushCache = true;
    boolean useCache = false;
    boolean resultOrdered = false;
    KeyGenerator keyGenerator = new NoKeyGenerator();
    String keyProperty = null;
    String keyColumn = null;

    Id id = AnnotationUtils.findDeclaredAnnotation(Id.class, entityClass);
    GeneratedValue generatedValue = AnnotationUtils.findDeclaredAnnotation(GeneratedValue.class, entityClass);
    if (id != null) {
        String keyStatementId = entityClass.getName() + ".insert" + SelectKeyGenerator.SELECT_KEY_SUFFIX;
        if (!sharded) {

            if (containSn)
                snGenerators.put(statementId, new SnGenerator());
            if (configuration.hasKeyGenerator(keyStatementId)) {
                keyGenerator = configuration.getKeyGenerator(keyStatementId);
            } else if (generatedValue != null) {
                if (generatedValue.strategy() == GenerationType.UUID) {
                    keyGenerator = new UuidKeyGenerator(generatedValue.length());

                }
            } else {
                keyGenerator = id.generatedKeys() ? new Jdbc4KeyGenerator() : new NoKeyGenerator();
            }
        } else {
            if (containSn)
                shardSnGenerators.put(statementId, new ShardSnGenerator());
            if (generatedValue != null) {
                if (generatedValue.strategy() == GenerationType.UUID) {
                    shardedKeyGenerators.put(statementId, new ShardUuidKeyGenerator(generatedValue.length()));
                } else if (generatedValue.strategy() == GenerationType.TABLE
                        || generatedValue.strategy() == GenerationType.AUTO) {
                    shardedKeyGenerators.put(statementId, new ShardJdbc4KeyGenerator());
                }
            }
            //                shardedKeyGenerators.put(statementId, new shardeduu)
        }
        keyProperty = idField.getName();
        keyColumn = StringUtils.isBlank(id.column()) ? CaseFormatUtils.camelToUnderScore(idField.getName())
                : id.column();
    }

    List<SqlNode> contents = new ArrayList<SqlNode>();
    contents.add(this.getInsertSql());
    SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents));
    String parameterMap = null;
    Iterator<String> parameterMapNames = configuration.getParameterMapNames().iterator();
    while (parameterMapNames.hasNext()) {
        String name = parameterMapNames.next();
        ParameterMap temp = configuration.getParameterMap(name);
        if (temp.getType().equals(entityClass)) {
            parameterMap = temp.getId();
            break;
        }
    }
    assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED, SqlCommandType.INSERT, null,
            timeout, parameterMap, parameterType, null, null, null, flushCache, useCache, resultOrdered,
            keyGenerator, keyProperty, keyColumn, databaseId, lang);
}

From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java

License:Open Source License

private void buildBatchUpdate(String statementId, String collection) {
    Integer timeout = null;/*from ww  w .  j  a v a2  s.  c  o m*/
    Class<?> parameterType = entityClass;

    //~~~~~~~~~~~~~
    boolean flushCache = true;
    boolean useCache = false;
    boolean resultOrdered = false;
    KeyGenerator keyGenerator = new NoKeyGenerator();

    List<SqlNode> contents = new ArrayList<SqlNode>();
    contents.add(this.getBatchUpdateSql(collection));

    SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents));
    String parameterMap = null;
    Iterator<String> parameterMapNames = configuration.getParameterMapNames().iterator();
    while (parameterMapNames.hasNext()) {
        String name = parameterMapNames.next();
        ParameterMap temp = configuration.getParameterMap(name);
        if (temp.getType().equals(entityClass)) {
            parameterMap = temp.getId();
            break;
        }
    }
    assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED, SqlCommandType.UPDATE, null,
            timeout, parameterMap, parameterType, null, null, null, flushCache, useCache, resultOrdered,
            keyGenerator, null, null, databaseId, lang);
}

From source file:com.sxj.mybatis.orm.builder.GenericStatementBuilder.java

License:Open Source License

private void buildUpdate(String statementId) {
    Integer timeout = null;//from w ww  . j  a va  2  s  .co  m
    Class<?> parameterType = entityClass;

    //~~~~~~~~~~~~~
    boolean flushCache = true;
    boolean useCache = false;
    boolean resultOrdered = false;
    KeyGenerator keyGenerator = new NoKeyGenerator();

    List<SqlNode> contents = new ArrayList<SqlNode>();
    contents.add(this.getUpdateSql());

    SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents));
    String parameterMap = null;
    Iterator<String> parameterMapNames = configuration.getParameterMapNames().iterator();
    while (parameterMapNames.hasNext()) {
        String name = parameterMapNames.next();
        ParameterMap temp = configuration.getParameterMap(name);
        if (temp.getType().equals(entityClass)) {
            parameterMap = temp.getId();
            break;
        }
    }
    assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED, SqlCommandType.UPDATE, null,
            timeout, parameterMap, parameterType, null, null, null, flushCache, useCache, resultOrdered,
            keyGenerator, null, null, databaseId, lang);
}