当前位置: 首页>>代码示例>>Java>>正文


Java ResultMap类代码示例

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


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

示例1: getId

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
public ResultMap getId(Class<?> entityType , Class<?> resultType) {
	// 结果映射名
	String mapId = buildResultMapId(entityType, "id");
	if (configuration.hasResultMap(mapId)) {
		return configuration.getResultMap(mapId);
	}
	List<ResultMapping> mappings = new ArrayList<ResultMapping>();
	// 设置列映射
	Root root = Root.get(entityType);
	EntityMetadata metadata = EntityMetadata.get(entityType);
	for (IdProperty property : metadata.getIdProperties()) {
		Path path = root.getPath(property);
		String propName = property.getName();
		String mapping = path.getMapping();
		Class<?> javaType = property.getType();
		mappings.add(new ResultMapping.Builder(configuration, propName, mapping, javaType).build());
	}
	// 加入结果映射
	ResultMap resultMap = new ResultMap.Builder(configuration, mapId, resultType, mappings).build();
	StatementResultMapHelper.addResultMap(configuration, resultMap);
	return resultMap;
}
 
开发者ID:yaoakeji,项目名称:hibatis,代码行数:23,代码来源:ResultMapBuilder.java

示例2: createAssocResultMapping

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
private ResultMapping createAssocResultMapping(AssociationProperty association) {
	Class<?> entityType = association.getMetadata().getEntityType();
	Root root = Root.get(entityType);
	Class<?> referenceType = association.getReferenceType();
	EntityMetadata refMetadata = EntityMetadata.get(referenceType);
	List<ResultMapping> mappings = new ArrayList<ResultMapping>();
	for (ColumnProperty property : refMetadata.getSelectProperties()) {
		Path path = root.getPath(association, property);
		String propName = path.getPropertyName();
		String mapping = path.getMapping();
		Class<?> javaType = property.getType();
		mappings.add(new ResultMapping.Builder(configuration, propName, mapping, javaType).build());
	}
	Class<?> referenceProxyClass = EntityEnhancer.getEnhancer(referenceType).getProxyClass();
	String resultMapId = buildResultMapId(entityType, "association_" + association.getName());
	ResultMap resultMap = new ResultMap.Builder(configuration, resultMapId, referenceProxyClass, mappings).build();
	StatementResultMapHelper.addResultMap(configuration, resultMap);
	return new ResultMapping.Builder(configuration, association.getName()).nestedResultMapId(resultMapId)
			.javaType(referenceProxyClass).build();
}
 
开发者ID:yaoakeji,项目名称:hibatis,代码行数:21,代码来源:ResultMapBuilder.java

示例3: copyFromMappedStatement

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
protected 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());
    // setStatementTimeout()
    builder.timeout(ms.getTimeout());
    // setParameterMap()
    builder.parameterMap(ms.getParameterMap());
    // setStatementResultMap()
    List<ResultMap> resultMaps = ms.getResultMaps();
    builder.resultMaps(resultMaps);
    builder.resultSetType(ms.getResultSetType());
    // setStatementCache()
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
    return builder.build();
}
 
开发者ID:baihui212,项目名称:tsharding,代码行数:22,代码来源:MapperEnhancer.java

示例4: checkLocallyForDiscriminatedNestedResultMaps

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
protected void checkLocallyForDiscriminatedNestedResultMaps(ResultMap rm) {
	if (!rm.hasNestedResultMaps() && rm.getDiscriminator() != null) {
		for (Map.Entry<String, String> entry : rm.getDiscriminator()
				.getDiscriminatorMap().entrySet()) {
			String discriminatedResultMapName = entry.getValue();
			if (hasResultMap(discriminatedResultMapName)) {
				ResultMap discriminatedResultMap = resultMaps
						.get(discriminatedResultMapName);
				if (discriminatedResultMap.hasNestedResultMaps()) {
					rm.forceNestedResultMaps();
					break;
				}
			}
		}
	}
}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:17,代码来源:Configuration.java

示例5: loadMappedAndUnmappedColumnNames

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
private void loadMappedAndUnmappedColumnNames(ResultMap resultMap, String columnPrefix) throws SQLException {
  List<String> mappedColumnNames = new ArrayList<String>();
  List<String> unmappedColumnNames = new ArrayList<String>();
  final String upperColumnPrefix = columnPrefix == null ? null : columnPrefix.toUpperCase(Locale.ENGLISH);
  final Set<String> mappedColumns = prependPrefixes(resultMap.getMappedColumns(), upperColumnPrefix);
  for (String columnName : columnNames) {
    final String upperColumnName = columnName.toUpperCase(Locale.ENGLISH);
    if (mappedColumns.contains(upperColumnName)) {
      mappedColumnNames.add(upperColumnName);
    } else {
      unmappedColumnNames.add(columnName);
    }
  }
  mappedColumnNamesMap.put(getMapKey(resultMap, columnPrefix), mappedColumnNames);
  unMappedColumnNamesMap.put(getMapKey(resultMap, columnPrefix), unmappedColumnNames);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:17,代码来源:ResultSetWrapper.java

示例6: handleRefCursorOutputParameter

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
private void handleRefCursorOutputParameter(ResultSet rs, ParameterMapping parameterMapping, MetaObject metaParam) throws SQLException {
  if (rs == null) {
    return;
  }
  try {
    final String resultMapId = parameterMapping.getResultMapId();
    final ResultMap resultMap = configuration.getResultMap(resultMapId);
    final DefaultResultHandler resultHandler = new DefaultResultHandler(objectFactory);
    final ResultSetWrapper rsw = new ResultSetWrapper(rs, configuration);
    handleRowValues(rsw, resultMap, resultHandler, new RowBounds(), null);
    metaParam.setValue(parameterMapping.getProperty(), resultHandler.getResultList());
  } finally {
    // issue #228 (close resultsets)
    closeResultSet(rs);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:17,代码来源:DefaultResultSetHandler.java

示例7: handleCursorResultSets

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
@Override
public <E> Cursor<E> handleCursorResultSets(Statement stmt) throws SQLException {
  ErrorContext.instance().activity("handling cursor results").object(mappedStatement.getId());

  ResultSetWrapper rsw = getFirstResultSet(stmt);

  List<ResultMap> resultMaps = mappedStatement.getResultMaps();

  int resultMapCount = resultMaps.size();
  validateResultMapsCount(rsw, resultMapCount);
  if (resultMapCount != 1) {
    throw new ExecutorException("Cursor results cannot be mapped to multiple resultMaps");
  }

  ResultMap resultMap = resultMaps.get(0);
  return new DefaultCursor<E>(this, resultMap, rsw, rowBounds);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:18,代码来源:DefaultResultSetHandler.java

示例8: handleResultSet

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
private void handleResultSet(ResultSetWrapper rsw, ResultMap resultMap, List<Object> multipleResults, ResultMapping parentMapping) throws SQLException {
  try {
    if (parentMapping != null) {
      handleRowValues(rsw, resultMap, null, RowBounds.DEFAULT, parentMapping);
    } else {
      if (resultHandler == null) {
        DefaultResultHandler defaultResultHandler = new DefaultResultHandler(objectFactory);
        handleRowValues(rsw, resultMap, defaultResultHandler, rowBounds, null);
        multipleResults.add(defaultResultHandler.getResultList());
      } else {
        handleRowValues(rsw, resultMap, resultHandler, rowBounds, null);
      }
    }
  } finally {
    // issue #228 (close resultsets)
    closeResultSet(rsw.getResultSet());
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:19,代码来源:DefaultResultSetHandler.java

示例9: queryCount

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
private Object queryCount(Invocation invocation, Object[] args, MappedStatement ms, BoundSql boundSql)
		throws InvocationTargetException, IllegalAccessException {
	MappedStatement countRowStatement = COUNT_MAPPED_STATS.get(ms.getId());

	if (countRowStatement == null) {
		String countSql = dialect.getCountSql(boundSql.getSql());
		BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), countSql, boundSql.getParameterMappings(),
				boundSql.getParameterObject());
		MetaObject mo = (MetaObject) ReflectionUtils.getFieldValue(boundSql, "metaParameters");
		ReflectionUtils.setFieldValue(newBoundSql, "metaParameters", mo);
		List<ResultMap> resultMaps = new ArrayList<ResultMap>();
		ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.class,
				EMPTY_RESULTMAPPING).build();
		resultMaps.add(resultMap);
		countRowStatement = buildMappedStatement(ms, new SqlSourceWrapper(newBoundSql), ms.getId() + "_COUNT",
				resultMaps);
	}

	args[0] = countRowStatement;
	args[2] = new RowBounds();
	args[3] = null;

	return invocation.proceed();
}
 
开发者ID:dianping,项目名称:zebra,代码行数:25,代码来源:PageInterceptor.java

示例10: applyAutomaticMappings

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
private boolean applyAutomaticMappings(ResultSetWrapper rsw, ResultMap resultMap, MetaObject metaObject, String columnPrefix) throws SQLException {
  List<UnMappedColumnAutoMapping> autoMapping = createAutomaticMappings(rsw, resultMap, metaObject, columnPrefix);
  boolean foundValues = false;
  if (autoMapping.size() > 0) {
    for (UnMappedColumnAutoMapping mapping : autoMapping) {
      final Object value = mapping.typeHandler.getResult(rsw.getResultSet(), mapping.column);
      if (value != null) {
        foundValues = true;
      }
      if (value != null || (configuration.isCallSettersOnNulls() && !mapping.primitive)) {
        // gcode issue #377, call setter on nulls (value is not 'found')
        metaObject.setValue(mapping.property, value);
      }
    }
  }
  return foundValues;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:18,代码来源:DefaultResultSetHandler.java

示例11: resolveDiscriminatedResultMap

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
public ResultMap resolveDiscriminatedResultMap(ResultSet rs, ResultMap resultMap, String columnPrefix) throws SQLException {
  Set<String> pastDiscriminators = new HashSet<String>();
  Discriminator discriminator = resultMap.getDiscriminator();
  while (discriminator != null) {
    final Object value = getDiscriminatorValue(rs, discriminator, columnPrefix);
    final String discriminatedMapId = discriminator.getMapIdFor(String.valueOf(value));
    if (configuration.hasResultMap(discriminatedMapId)) {
      resultMap = configuration.getResultMap(discriminatedMapId);
      Discriminator lastDiscriminator = discriminator;
      discriminator = resultMap.getDiscriminator();
      if (discriminator == lastDiscriminator || !pastDiscriminators.add(discriminatedMapId)) {
        break;
      }
    } else {
      break;
    }
  }
  return resultMap;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:20,代码来源:DefaultResultSetHandler.java

示例12: createRowKeyForMappedProperties

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
private void createRowKeyForMappedProperties(ResultMap resultMap, ResultSetWrapper rsw, CacheKey cacheKey, List<ResultMapping> resultMappings, String columnPrefix) throws SQLException {
  for (ResultMapping resultMapping : resultMappings) {
    if (resultMapping.getNestedResultMapId() != null && resultMapping.getResultSet() == null) {
      // Issue #392
      final ResultMap nestedResultMap = configuration.getResultMap(resultMapping.getNestedResultMapId());
      createRowKeyForMappedProperties(nestedResultMap, rsw, cacheKey, nestedResultMap.getConstructorResultMappings(),
          prependPrefix(resultMapping.getColumnPrefix(), columnPrefix));
    } else if (resultMapping.getNestedQueryId() == null) {
      final String column = prependPrefix(resultMapping.getColumn(), columnPrefix);
      final TypeHandler<?> th = resultMapping.getTypeHandler();
      List<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix);
      // Issue #114
      if (column != null && mappedColumnNames.contains(column.toUpperCase(Locale.ENGLISH))) {
        final Object value = th.getResult(rsw.getResultSet(), column);
        if (value != null) {
          cacheKey.update(column);
          cacheKey.update(value);
        }
      }
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:23,代码来源:DefaultResultSetHandler.java

示例13: createRowKeyForUnmappedProperties

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
private void createRowKeyForUnmappedProperties(ResultMap resultMap, ResultSetWrapper rsw, CacheKey cacheKey, String columnPrefix) throws SQLException {
  final MetaClass metaType = MetaClass.forClass(resultMap.getType(), reflectorFactory);
  List<String> unmappedColumnNames = rsw.getUnmappedColumnNames(resultMap, columnPrefix);
  for (String column : unmappedColumnNames) {
    String property = column;
    if (columnPrefix != null && !columnPrefix.isEmpty()) {
      // When columnPrefix is specified, ignore columns without the prefix.
      if (column.toUpperCase(Locale.ENGLISH).startsWith(columnPrefix)) {
        property = column.substring(columnPrefix.length());
      } else {
        continue;
      }
    }
    if (metaType.findProperty(property, configuration.isMapUnderscoreToCamelCase()) != null) {
      String value = rsw.getResultSet().getString(column);
      if (value != null) {
        cacheKey.update(column);
        cacheKey.update(value);
      }
    }
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:23,代码来源:DefaultResultSetHandler.java

示例14: checkGloballyForDiscriminatedNestedResultMaps

import org.apache.ibatis.mapping.ResultMap; //导入依赖的package包/类
protected void checkGloballyForDiscriminatedNestedResultMaps(ResultMap rm) {
	if (rm.hasNestedResultMaps()) {
		for (Map.Entry<String, ResultMap> entry : resultMaps.entrySet()) {
			Object value = entry.getValue();
			if (value instanceof ResultMap) {
				ResultMap entryResultMap = (ResultMap) value;
				if (!entryResultMap.hasNestedResultMaps() && entryResultMap.getDiscriminator() != null) {
					Collection<String> discriminatedResultMapNames = entryResultMap.getDiscriminator().getDiscriminatorMap().values();
					if (discriminatedResultMapNames.contains(rm.getId())) {
						entryResultMap.forceNestedResultMaps();
					}
				}
			}
		}
	}
}
 
开发者ID:whatlookingfor,项目名称:spring-boot-sample,代码行数:17,代码来源:Configuration.java

示例15: prepareSelectAuthorViaOutParams

import org.apache.ibatis.mapping.ResultMap; //导入依赖的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:yuexiahandao,项目名称:MybatisCode,代码行数:19,代码来源:ExecutorTestHelper.java


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