Java Code Examples for org.apache.ibatis.mapping.MappedStatement#getKeyProperties()

The following examples show how to use org.apache.ibatis.mapping.MappedStatement#getKeyProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaginationHandler.java    From sqlhelper with GNU Lesser General Public License v3.0 6 votes vote down vote up
private MappedStatement customOrderByStatement(final MappedStatement ms, final String orderByStatementId) {
    final MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), orderByStatementId, ms.getSqlSource(), ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (Emptys.isNotEmpty(ms.getKeyProperties())) {
        final StringBuilder keyProperties = new StringBuilder();
        for (final String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    builder.resultMaps(ms.getResultMaps());
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
    return builder.build();
}
 
Example 2
Source File: SundialInterceptor.java    From Milkomeda with MIT License 6 votes vote down vote up
private MappedStatement copyFrom(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 (ms.getKeyProperties() != null && ms.getKeyProperties().length > 0) {
        builder.keyProperty(org.apache.commons.lang3.StringUtils.join(ms.getKeyProperties(), ','));
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    builder.resultMaps(ms.getResultMaps());
    builder.resultOrdered(ms.isResultOrdered());
    builder.resultSetType(ms.getResultSetType());
    if (ms.getKeyColumns() != null && ms.getKeyColumns().length > 0) {
        builder.keyColumn(org.apache.commons.lang3.StringUtils.join(ms.getKeyColumns(), ','));
    }
    builder.databaseId(ms.getDatabaseId());
    builder.lang(ms.getLang());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
    return builder.build();
}
 
Example 3
Source File: MybatisSqlInterceptor.java    From taoshop with Apache License 2.0 6 votes vote down vote up
private MappedStatement newMappedStatement(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 (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuilder keyProperties = new StringBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    builder.resultMaps(ms.getResultMaps());
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
 
    return builder.build();
}
 
Example 4
Source File: PaginationInterceptor.java    From Shop-for-JavaWeb with MIT License 6 votes vote down vote up
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 (ms.getKeyProperties() != null) {
        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();
}
 
Example 5
Source File: MyBatisUtils.java    From platform with Apache License 2.0 6 votes vote down vote up
/**
 * 复制MappedStatement
 *
 * @param ms           {@link MappedStatement}
 * @param newSqlSource {@link SqlSource}
 * @return {@link MappedStatement}
 */
public static 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());
    String[] keyProperties = ms.getKeyProperties();
    builder.keyProperty(keyProperties == null ? null : keyProperties[0]);
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    builder.resultMaps(ms.getResultMaps());
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
    return builder.build();
}
 
Example 6
Source File: PaginationHandler.java    From sqlhelper with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MappedStatement customCountStatement(final MappedStatement ms, final String countStatementId, String querySql, PagingRequest pagingRequest) {
    MappedStatement countStatement = paginationConfig.enableCountCache() ? this.countStatementCache.getIfPresent(querySql) : null;
    if (countStatement == null) {
        final MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), countStatementId, ms.getSqlSource(), ms.getSqlCommandType());
        builder.resource(ms.getResource());
        builder.fetchSize(ms.getFetchSize());
        builder.statementType(ms.getStatementType());
        builder.keyGenerator(ms.getKeyGenerator());
        if (Emptys.isNotEmpty(ms.getKeyProperties())) {
            final StringBuilder keyProperties = new StringBuilder();
            for (final String keyProperty : ms.getKeyProperties()) {
                keyProperties.append(keyProperty).append(",");
            }
            keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
            builder.keyProperty(keyProperties.toString());
        }
        builder.timeout(ms.getTimeout());
        builder.parameterMap(ms.getParameterMap());
        final List<ResultMap> resultMaps = new ArrayList<ResultMap>();
        final ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), Long.class, new ArrayList<ResultMapping>()).build();
        resultMaps.add(resultMap);
        builder.resultMaps(resultMaps);
        builder.resultSetType(ms.getResultSetType());
        builder.cache(ms.getCache());
        builder.flushCacheRequired(ms.isFlushCacheRequired());
        boolean useCache = Objects.isNull(pagingRequest.getCacheCount()) ? ms.isUseCache() : pagingRequest.getCacheCount();
        builder.useCache(useCache);

        countStatement = builder.build();
        if (paginationConfig.enableCountCache() && useCache) {
            this.countStatementCache.set(querySql, countStatement);
        }
    }
    return countStatement;
}
 
Example 7
Source File: DataPermissionInterceptor.java    From DataPermissionHelper with Apache License 2.0 5 votes vote down vote up
private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource, String newMsId) {
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), newMsId, newSqlSource,
            ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuilder keyProperties = new StringBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }

    // setStatementTimeout()
    builder.timeout(ms.getTimeout());
    // setStatementResultMap()
    builder.parameterMap(ms.getParameterMap());
    // setStatementResultMap()
    builder.resultMaps(ms.getResultMaps());
    builder.resultSetType(ms.getResultSetType());
    // setStatementCache()
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
    return builder.build();
}
 
Example 8
Source File: IdentityKeyGenerator.java    From mybatis-jpa with Apache License 2.0 5 votes vote down vote up
public void processGeneratedKeys(MappedStatement ms, Statement stmt, Object parameter) {
  final String[] keyProperties = ms.getKeyProperties();
  if (keyProperties == null || keyProperties.length == 0) {
    return;
  }
  if (keyProperties.length > 1) {
    throw new ExecutorException(
        "There are more than one keyProperty in MappedStatement : " + ms.getId() + ".");
  }

  if (parameter instanceof Collection) {
    handleCollection(ms, stmt, (Collection) parameter);
  } else if (parameter.getClass().isArray()) {
    handleCollection(ms, stmt, Arrays.asList(parameter));
  } else if (parameter instanceof Map) {
    Map parameterMap = (Map) parameter;
    if (parameterMap.containsKey("collection")) {
      handleCollection(ms, stmt, (Collection) parameterMap.get("collection"));
    } else if (parameterMap.containsKey("list")) {
      handleCollection(ms, stmt, (List) parameterMap.get("list"));
    } else if (parameterMap.containsKey("array")) {
      handleCollection(ms, stmt, Arrays.asList((Object[]) parameterMap.get("array")));
    }
  } else {
    handleObject(ms, stmt, parameter, idGenerator.nextId());
  }
}
 
Example 9
Source File: OffsetLimitInterceptor.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
private MappedStatement copyFromMappedStatement(MappedStatement ms,SqlSource newSqlSource) {
	Builder builder = new 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(ms.getKeyProperties() != null && ms.getKeyProperties().length !=0){
           StringBuffer keyProperties = new StringBuffer();
           for(String keyProperty : ms.getKeyProperties()){
               keyProperties.append(keyProperty).append(",");
           }
           keyProperties.delete(keyProperties.length()-1, keyProperties.length());
		builder.keyProperty(keyProperties.toString());
	}
	
	//setStatementTimeout()
	builder.timeout(ms.getTimeout());
	
	//setStatementResultMap()
	builder.parameterMap(ms.getParameterMap());
	
	//setStatementResultMap()
       builder.resultMaps(ms.getResultMaps());
	builder.resultSetType(ms.getResultSetType());
    
	//setStatementCache()
	builder.cache(ms.getCache());
	builder.flushCacheRequired(ms.isFlushCacheRequired());
	builder.useCache(ms.isUseCache());
	
	return builder.build();
}
 
Example 10
Source File: PageInterceptor.java    From Zebra with Apache License 2.0 5 votes vote down vote up
public MappedStatement buildMappedStatement(MappedStatement ms, SqlSource newSqlSource, String id,
		List<ResultMap> resultMaps) {
	MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), id, newSqlSource,
			ms.getSqlCommandType());

	builder.resource(ms.getResource());
	builder.fetchSize(ms.getFetchSize());
	builder.statementType(ms.getStatementType());
	builder.keyGenerator(ms.getKeyGenerator());
	if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
		StringBuilder keyProperties = new StringBuilder();
		for (String keyProperty : ms.getKeyProperties()) {
			keyProperties.append(keyProperty).append(",");
		}
		keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
		builder.keyProperty(keyProperties.toString());
	}
	builder.timeout(ms.getTimeout());
	builder.parameterMap(ms.getParameterMap());
	builder.resultMaps(resultMaps);
	builder.resultSetType(ms.getResultSetType());
	builder.cache(ms.getCache());
	builder.flushCacheRequired(ms.isFlushCacheRequired());
	builder.useCache(ms.isUseCache());

	return builder.build();
}
 
Example 11
Source File: MSUtils.java    From Mybatis-PageHelper with MIT License 5 votes vote down vote up
/**
 * 新建count查询的MappedStatement
 *
 * @param ms
 * @param newMsId
 * @return
 */
public static MappedStatement newCountMappedStatement(MappedStatement ms, String newMsId) {
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), newMsId, ms.getSqlSource(), ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
        StringBuilder keyProperties = new StringBuilder();
        for (String keyProperty : ms.getKeyProperties()) {
            keyProperties.append(keyProperty).append(",");
        }
        keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
        builder.keyProperty(keyProperties.toString());
    }
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    //count查询返回值int
    List<ResultMap> resultMaps = new ArrayList<ResultMap>();
    ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), Long.class, EMPTY_RESULTMAPPING).build();
    resultMaps.add(resultMap);
    builder.resultMaps(resultMaps);
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());

    return builder.build();
}
 
Example 12
Source File: IdentityKeyGenerator.java    From mybatis-jpa with Apache License 2.0 4 votes vote down vote up
private void handleObject(MappedStatement ms, Statement stmt, Object parameter, Object idValue) {
  final String[] keyProperties = ms.getKeyProperties();
  final Configuration configuration = ms.getConfiguration();
  final MetaObject metaParam = configuration.newMetaObject(parameter);
  setValue(metaParam, keyProperties[0], idValue);
}
 
Example 13
Source File: PaginationHandler.java    From azeroth with Apache License 2.0 4 votes vote down vote up
/**
 * 新建count查询的MappedStatement
 *
 * @param ms
 * @return
 */
public MappedStatement getCountMappedStatement(MappedStatement ms) {

    String newMsId = ms.getId() + PAGE_COUNT_SUFFIX;

    MappedStatement statement = null;
    Configuration configuration = ms.getConfiguration();

    try {
        statement = configuration.getMappedStatement(newMsId);
        if (statement != null) { return statement; }
    } catch (Exception e) {
    }

    synchronized (configuration) {

        if (configuration.hasStatement(newMsId)) { return configuration.getMappedStatement(newMsId); }

        MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(),
                newMsId, ms.getSqlSource(), ms.getSqlCommandType());
        builder.resource(ms.getResource());
        builder.fetchSize(ms.getFetchSize());
        builder.statementType(ms.getStatementType());
        builder.keyGenerator(ms.getKeyGenerator());
        if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
            StringBuilder keyProperties = new StringBuilder();
            for (String keyProperty : ms.getKeyProperties()) {
                keyProperties.append(keyProperty).append(",");
            }
            keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
            builder.keyProperty(keyProperties.toString());
        }
        builder.timeout(ms.getTimeout());
        builder.parameterMap(ms.getParameterMap());
        //count查询返回值int
        List<ResultMap> resultMaps = new ArrayList<ResultMap>();
        String id = newMsId + "-Inline";
        ResultMap resultMap = new ResultMap.Builder(configuration, id, Long.class,
                new ArrayList<ResultMapping>(0)).build();
        resultMaps.add(resultMap);
        builder.resultMaps(resultMaps);

        builder.resultSetType(ms.getResultSetType());
        builder.cache(ms.getCache());
        builder.flushCacheRequired(ms.isFlushCacheRequired());
        builder.useCache(ms.isUseCache());

        statement = builder.build();
        configuration.addMappedStatement(statement);
        return statement;
    }

}
 
Example 14
Source File: PaginationHandler.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
/**
   * 新建count查询的MappedStatement
   *
   * @param ms
   * @return
   */
  public MappedStatement getCountMappedStatement(MappedStatement ms) {
  	
  	String newMsId = ms.getId() + PAGE_COUNT_SUFFIX;
  	
  	MappedStatement statement = null;
  	Configuration configuration = ms.getConfiguration();
	
  	try {
  		statement = configuration.getMappedStatement(newMsId);
  		if(statement != null)return statement;
} catch (Exception e) {}
  	
  	synchronized (configuration) {   
  		
  		if(configuration.hasStatement(newMsId))return configuration.getMappedStatement(newMsId);
  		
  		MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), newMsId, ms.getSqlSource(), ms.getSqlCommandType());
  		builder.resource(ms.getResource());
  		builder.fetchSize(ms.getFetchSize());
  		builder.statementType(ms.getStatementType());
  		builder.keyGenerator(ms.getKeyGenerator());
  		if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
  			StringBuilder keyProperties = new StringBuilder();
  			for (String keyProperty : ms.getKeyProperties()) {
  				keyProperties.append(keyProperty).append(",");
  			}
  			keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
  			builder.keyProperty(keyProperties.toString());
  		}
  		builder.timeout(ms.getTimeout());
  		builder.parameterMap(ms.getParameterMap());
  		//count查询返回值int
  		 List<ResultMap> resultMaps = new ArrayList<ResultMap>();
           String id = newMsId + "-Inline";
           ResultMap resultMap = new ResultMap.Builder(configuration, id, Long.class, new ArrayList<ResultMapping>(0)).build();
           resultMaps.add(resultMap);
           builder.resultMaps(resultMaps);
           
  		builder.resultSetType(ms.getResultSetType());
  		builder.cache(ms.getCache());
  		builder.flushCacheRequired(ms.isFlushCacheRequired());
  		builder.useCache(ms.isUseCache());
  		
  		statement = builder.build();
  		configuration.addMappedStatement(statement);
  		return statement;
  	}
  	
  }