List of usage examples for org.apache.ibatis.mapping ResultMap.Builder ResultMap.Builder
public Builder(Configuration configuration, String id, Class<?> type, List<ResultMapping> resultMappings)
From source file:SqlUtil.java
License:Open Source License
/** * countMappedStatement//from w w w . ja va2 s . c o m * * @param ms * @param newSqlSource * @param suffix * @return */ private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource, String suffix) { String id = ms.getId() + suffix; 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()); if (suffix == SUFFIX_PAGE) { builder.resultMaps(ms.getResultMaps()); } else { //countint List<ResultMap> resultMaps = new ArrayList<ResultMap>(); ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), id, int.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(); }
From source file:cn.myblog.uitl.MybatisPageHelper.PageHelper.java
License:Open Source License
/** * MappedStatement?????/*w w w .jav a 2 s .c om*/ * * @param ms * @param newSqlSource * @return */ 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) { StringBuffer keyProperties = new StringBuffer(); 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()); //resultMaps?int??resultMap - ? List<ResultMap> resultMaps = new ArrayList<ResultMap>(); ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.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(); }
From source file:com.autonavi.tsp.workbackend.util.page.SqlUtil.java
License:Open Source License
/** * countMappedStatement/* w w w. j a v a 2s. c o m*/ * * @param ms * @param sqlSource * @param suffix * @return */ private MappedStatement newMappedStatement(MappedStatement ms, SqlSource sqlSource, String suffix) { String id = ms.getId() + suffix; MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), id, sqlSource, 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()); if (suffix == SUFFIX_PAGE) { builder.resultMaps(ms.getResultMaps()); } else { //countint List<ResultMap> resultMaps = new ArrayList<ResultMap>(); ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), id, int.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(); }
From source file:com.baidu.dpop.ctp.common.mybatis.page.SqlUtil.java
License:Open Source License
/** * countMappedStatement//from w ww .jav a 2 s . com * * @param ms * @param sqlSource * @param suffix * @return */ private MappedStatement newMappedStatement(MappedStatement ms, SqlSource sqlSource, String suffix) { String id = ms.getId() + suffix; MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), id, sqlSource, 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()); if (suffix.equals(SUFFIX_PAGE)) { builder.resultMaps(ms.getResultMaps()); } else { //countint List<ResultMap> resultMaps = new ArrayList<ResultMap>(); ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), id, int.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(); }
From source file:com.hotpot.commons.pagination.PageHelper.java
License:Open Source License
/** * MappedStatement?????.//w w w . ja v a2 s.c o m * * @param ms the ms * @param newSqlSource the new sql source * @return the mapped statement */ private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource) { MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId() + "_PageHelper", 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) { StrBuilder keyProperties = new StrBuilder(); 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()); //resultMaps?int??resultMap - ? List<ResultMap> resultMaps = new ArrayList<ResultMap>(); ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.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(); }
From source file:com.ibatis.sqlmap.engine.builder.XmlSqlStatementParser.java
License:Apache License
public void parseGeneralStatement(XNode context) { // get attributes String id = context.getStringAttribute("id"); String parameterMapName = context.getStringAttribute("parameterMap"); String parameterClassName = context.getStringAttribute("parameterClass"); String resultMapName = context.getStringAttribute("resultMap"); String resultClassName = context.getStringAttribute("resultClass"); String cacheModelName = context.getStringAttribute("cacheModel"); String resultSetType = context.getStringAttribute("resultSetType"); String fetchSize = context.getStringAttribute("fetchSize"); String timeout = context.getStringAttribute("timeout"); // 2.x -- String allowRemapping = context.getStringAttribute("remapResults"); if (context.getStringAttribute("xmlResultName") != null) { throw new UnsupportedOperationException("xmlResultName is not supported by iBATIS 3"); }//from www. j ava2 s . com if (mapParser.getConfigParser().isUseStatementNamespaces()) { id = mapParser.applyNamespace(id); } String[] additionalResultMapNames = null; if (resultMapName != null) { additionalResultMapNames = getAllButFirstToken(resultMapName); resultMapName = getFirstToken(resultMapName); resultMapName = mapParser.applyNamespace(resultMapName); for (int i = 0; i < additionalResultMapNames.length; i++) { additionalResultMapNames[i] = mapParser.applyNamespace(additionalResultMapNames[i]); } } String[] additionalResultClassNames = null; if (resultClassName != null) { additionalResultClassNames = getAllButFirstToken(resultClassName); resultClassName = getFirstToken(resultClassName); } Class[] additionalResultClasses = null; if (additionalResultClassNames != null) { additionalResultClasses = new Class[additionalResultClassNames.length]; for (int i = 0; i < additionalResultClassNames.length; i++) { additionalResultClasses[i] = resolveClass(additionalResultClassNames[i]); } } Integer timeoutInt = timeout == null ? null : new Integer(timeout); Integer fetchSizeInt = fetchSize == null ? null : new Integer(fetchSize); // 2.x -- boolean allowRemappingBool = "true".equals(allowRemapping); SqlSource sqlSource = new SqlSourceFactory(mapParser).newSqlSourceIntance(mapParser, context); String nodeName = context.getNode().getNodeName(); SqlCommandType sqlCommandType; try { sqlCommandType = SqlCommandType.valueOf(nodeName.toUpperCase()); } catch (Exception e) { sqlCommandType = SqlCommandType.UNKNOWN; } MappedStatement.Builder builder = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType); builder.useCache(true); if (!"select".equals(context.getNode().getNodeName())) { builder.flushCacheRequired(true); } if (parameterMapName != null) { parameterMapName = mapParser.applyNamespace(parameterMapName); builder.parameterMap(configuration.getParameterMap(parameterMapName)); } else if (parameterClassName != null) { Class parameterClass = resolveClass(parameterClassName); List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>(); if (sqlSource instanceof SimpleSqlSource) { parameterMappings = sqlSource.getBoundSql(null).getParameterMappings(); } ParameterMap.Builder parameterMapBuilder = new ParameterMap.Builder(configuration, id + "-ParameterMap", parameterClass, parameterMappings); builder.parameterMap(parameterMapBuilder.build()); } List<ResultMap> resultMaps = new ArrayList<ResultMap>(); if (resultMapName != null) { resultMaps.add(configuration.getResultMap(resultMapName)); if (additionalResultMapNames != null) { for (String additionalResultMapName : additionalResultMapNames) { resultMaps.add(configuration.getResultMap(additionalResultMapName)); } } } else if (resultClassName != null) { Class resultClass = resolveClass(resultClassName); ResultMap.Builder resultMapBuilder = new ResultMap.Builder(configuration, id + "-ResultMap", resultClass, new ArrayList<ResultMapping>()); resultMaps.add(resultMapBuilder.build()); if (additionalResultClasses != null) { for (Class additionalResultClass : additionalResultClasses) { resultMapBuilder = new ResultMap.Builder(configuration, id + "-ResultMap", additionalResultClass, new ArrayList<ResultMapping>()); resultMaps.add(resultMapBuilder.build()); } } } builder.resultMaps(resultMaps); builder.fetchSize(fetchSizeInt); builder.timeout(timeoutInt); if (cacheModelName != null) { cacheModelName = mapParser.applyNamespace(cacheModelName); Cache cache = configuration.getCache(cacheModelName); builder.cache(cache); } if (resultSetType != null) { builder.resultSetType(ResultSetType.valueOf(resultSetType)); } // allowRemappingBool -- silently ignored findAndParseSelectKey(id, context); configuration.addMappedStatement(builder.build()); }
From source file:com.ibatis.sqlmap.engine.builder.XmlSqlStatementParser.java
License:Apache License
private void buildSelectKeyStatement(String parentId, XNode context, boolean runStatementFirstParam) throws ClassNotFoundException { final String keyPropName = context.getStringAttribute("keyProperty"); String resultClassName = context.getStringAttribute("resultClass"); final SimpleSqlSource source = new SimpleSqlSource(mapParser, context); final boolean runStatementFirst = "post" .equalsIgnoreCase(context.getStringAttribute("type", runStatementFirstParam ? "post" : "pre")); final String keyStatementId = SqlMapSessionImpl.selectKeyIdFor(parentId); TypeHandler typeHandler = configuration.getTypeHandlerRegistry().getUnknownTypeHandler(); if (resultClassName != null) { final Class resultClass = configuration.getTypeAliasRegistry().resolveAlias(resultClassName); typeHandler = configuration.getTypeHandlerRegistry().getTypeHandler(resultClass); }/* w ww . jav a 2s. c om*/ ResultMapping.Builder mappingBuilder = new ResultMapping.Builder(configuration, keyPropName, keyPropName, typeHandler); ArrayList<ResultMapping> resultMappingArrayList = new ArrayList<ResultMapping>(); resultMappingArrayList.add(mappingBuilder.build()); ResultMap.Builder resultMapBuilder = new ResultMap.Builder(configuration, keyStatementId + "ResultMap", HashMap.class, resultMappingArrayList); ArrayList<ResultMap> resultMapList = new ArrayList<ResultMap>(); resultMapList.add(resultMapBuilder.build()); MappedStatement.Builder builder = new MappedStatement.Builder(configuration, keyStatementId, source, SqlCommandType.SELECT); builder.resultMaps(resultMapList); configuration.setPostSelectKey(keyStatementId, runStatementFirst); configuration.addMappedStatement(builder.build()); }
From source file:com.jeeplus.weixin.common.pagination.PageHelper.java
License:Open Source License
/** * MappedStatement?????//from w w w.ja v a2 s.co m * * @param ms * @param newSqlSource * @return */ private MappedStatement newMappedStatement(MappedStatement ms, SqlSource newSqlSource) { MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId() + "_PageHelper", 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()); //resultMaps?int??resultMap - ? List<ResultMap> resultMaps = new ArrayList<ResultMap>(); ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.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(); }
From source file:com.linju.framework.pager.MSUtils.java
License:Open Source License
/** * countMappedStatement/*from w ww .j a v a2 s .c o m*/ * * @param ms * @param sqlSource * @param suffix * @return */ public MappedStatement newMappedStatement(MappedStatement ms, SqlSource sqlSource, String suffix) { String id = ms.getId() + suffix; MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), id, sqlSource, 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()); if (suffix == SUFFIX_PAGE) { builder.resultMaps(ms.getResultMaps()); } else { //countint List<ResultMap> resultMaps = new ArrayList<ResultMap>(); ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), id, int.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(); }