List of usage examples for org.apache.ibatis.mapping ResultMap getResultMappings
public List<ResultMapping> getResultMappings()
From source file:com.github.abel533.mapper.MapperHelper.java
License:Open Source License
/** * ?Key?/*from ww w. ja va 2 s . c o m*/ * * @param result * @param ms */ public void cameHumpMap(Object result, MappedStatement ms) { ResultMap resultMap = ms.getResultMaps().get(0); Class<?> type = resultMap.getType(); //?typeMap,???resultMap,??? if (result instanceof List && ((List) result).size() > 0 && Map.class.isAssignableFrom(type) && !resultMap.hasNestedQueries() && !resultMap.hasNestedResultMaps()) { List resultList = (List) result; //1.resultType if (resultMap.getId().endsWith("-Inline")) { for (Object re : resultList) { processMap((Map) re); } } else {//2.resultMap for (Object re : resultList) { processMap((Map) re, resultMap.getResultMappings()); } } } }
From source file:com.ibatis.sqlmap.engine.builder.XmlSqlMapParser.java
License:Apache License
@NodeEvent("/sqlMap/resultMap") public void sqlMapresultMap(XNode context) throws Exception { String xmlName = context.getStringAttribute("xmlName"); if (xmlName != null) { throw new UnsupportedOperationException("xmlName is not supported by iBATIS 3"); }//from www . j a v a 2 s . c o m String id = applyNamespace(context.getStringAttribute("id")); String resultClassName = context.getStringAttribute("class"); String extendedId = applyNamespace(context.getStringAttribute("extends")); String groupBy = context.getStringAttribute("groupBy"); if (groupBy != null) { groupByProperties = Arrays.asList(groupBy.split(", ")); } Class resultClass; try { resultClass = config.getTypeAliasRegistry().resolveAlias(resultClassName); } catch (Exception e) { throw new RuntimeException("Error configuring Result. Could not set ResultClass. Cause: " + e, e); } resultMappingList = new ArrayList<ResultMapping>(); resultMapBuilder = new ResultMap.Builder(config, id, resultClass, resultMappingList); if (extendedId != null) { ResultMap extendedResultMap = config.getResultMap(extendedId); for (ResultMapping mapping : extendedResultMap.getResultMappings()) { resultMappingList.add(mapping); } resultMapBuilder.discriminator(extendedResultMap.getDiscriminator()); } }
From source file:com.yunmel.syncretic.core.CameHumpInterceptor.java
License:Apache License
public Object intercept(Invocation invocation) throws Throwable { // ??/* www . j a v a2 s. c o m*/ Object result = invocation.proceed(); MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; ResultMap resultMap = mappedStatement.getResultMaps().get(0); Class<?> type = resultMap.getType(); // ?typeMap,???resultMap,??? if (((List) result).size() > 0 && Map.class.isAssignableFrom(type) && !resultMap.hasNestedQueries() && !resultMap.hasNestedResultMaps()) { List resultList = (List) result; // 1.resultType if (resultMap.getId().endsWith(RESULT_TYPE)) { for (Object re : resultList) { if (re == null) continue; processMap((Map) re); } } else {// 2.resultMap for (Object re : resultList) { processMap((Map) re, resultMap.getResultMappings()); } } } return result; }
From source file:das.orm.ORMBackendConnector.java
License:Apache License
public List<BeanPropertyMapping> getBeanPropertiesMapping(Class<?> beanClass) { log.trace(">>> getBeanPropertiesMapping()"); List<BeanPropertyMapping> DAOprops = new ArrayList<BeanPropertyMapping>(); Configuration conf = getConfiguration(); if (conf != null) { ////from w w w.j a va2s . c o m //checkDAOMapperClass(mapperClass, dao); Collection<ResultMap> rmc = conf.getResultMaps(); //log.debug("ResultMaps size="+rmc.size()); Iterator<ResultMap> rmci = rmc.iterator(); while (rmci.hasNext()) { ResultMap rm = rmci.next(); // ID=com.example.server.dao.UserMapper.UserMap, Type=com.example.server.dao.UserDTO log.debug("ResultMap ID=" + rm.getId() + ", Type=" + rm.getType().getName()); // ?, ?? ResultMap ?? beanClass if (isCompatibleMap(rm, beanClass)) { List<ResultMapping> r = rm.getResultMappings(); Iterator<ResultMapping> i2 = r.iterator(); while (i2.hasNext()) { ResultMapping r2 = i2.next(); // ? ?? (?) . // ? ?? ? ? ?? DAOprops.add(new BeanPropertyMapping(r2.getProperty(), r2.getColumn(), r2.getJavaType(), r2.getFlags(), r2.getNotNullColumns())); StringBuilder s = new StringBuilder(); s.append("Column=").append(r2.getColumn()); s.append(", Property=").append(r2.getProperty()); s.append(", JavaType=").append(r2.getJavaType()); s.append(", Flags=["); List<ResultFlag> flags = r2.getFlags(); for (ResultFlag rf : flags) { s.append(rf.name()).append(", "); } s.append("]"); s.append(", NotNullColumns=["); Set<String> nncs = r2.getNotNullColumns(); for (String nnc : nncs) { s.append(nnc).append(", "); } s.append("]"); log.debug(s.toString()); } break; // ?? , ? } } } return DAOprops; }
From source file:fxapp01.orm.ORMBackendConnector.java
License:Apache License
public List<BeanPropertyMapping> getBeanPropertiesMapping(Class beanClass) { log.trace(">>> getDAOProperties()"); List<BeanPropertyMapping> DAOprops = new ArrayList<>(); Configuration conf = getConfiguration(); if (conf != null) { ////from w ww . j a va2 s. c o m //checkDAOMapperClass(mapperClass, dao); Collection<ResultMap> rmc = conf.getResultMaps(); //log.debug("ResultMaps size="+rmc.size()); Iterator<ResultMap> rmci = rmc.iterator(); while (rmci.hasNext()) { ResultMap rm = rmci.next(); // ID=com.example.server.dao.UserMapper.UserMap, Type=com.example.server.dao.UserDTO log.debug("ResultMap ID=" + rm.getId() + ", Type=" + rm.getType().getName()); // ?, ?? ResultMap ?? beanClass if (isCompatibleMap(rm, beanClass)) { List<ResultMapping> r = rm.getResultMappings(); Iterator<ResultMapping> i2 = r.iterator(); while (i2.hasNext()) { ResultMapping r2 = i2.next(); // ? ?? (?) . // ? ?? ? ? ?? DAOprops.add(new BeanPropertyMapping(r2.getProperty(), r2.getColumn(), r2.getJavaType())); log.debug("Column=" + r2.getColumn() + ", Property=" + r2.getProperty() + ", JavaType=" + r2.getJavaType()); } break; // ?? , ? } } } return DAOprops; }
From source file:org.hswebframework.web.dao.mybatis.builder.EasyOrmSqlBuilder.java
License:Apache License
protected RDBTableMetaData createMeta(String tableName, String resultMapId) { RDBDatabaseMetaData active = getActiveDatabase(); String cacheKey = tableName.concat("-").concat(resultMapId); Map<String, RDBTableMetaData> cache = metaCache.get(active); RDBTableMetaData cached = cache.get(cacheKey); if (cached != null) { return cached; }/*from w w w.j a v a 2 s .c o m*/ RDBTableMetaData rdbTableMetaData = new RDBTableMetaData(); ResultMap resultMaps = MybatisUtils.getResultMap(resultMapId); rdbTableMetaData.setName(tableName); rdbTableMetaData.setDatabaseMetaData(active); List<ResultMapping> resultMappings = new ArrayList<>(resultMaps.getResultMappings()); resultMappings.addAll(resultMaps.getIdResultMappings()); resultMappings.forEach(resultMapping -> { if (resultMapping.getNestedQueryId() == null) { RDBColumnMetaData column = new RDBColumnMetaData(); column.setJdbcType(JDBCType.valueOf(resultMapping.getJdbcType().name())); column.setName(resultMapping.getColumn()); if (!StringUtils.isNullOrEmpty(resultMapping.getProperty())) { column.setAlias(resultMapping.getProperty()); } column.setJavaType(resultMapping.getJavaType()); column.setProperty("resultMapping", resultMapping); ValueConverter dateConvert = new DateTimeConverter("yyyy-MM-dd HH:mm:ss", column.getJavaType()) { @Override public Object getData(Object value) { if (value instanceof Number) { return new Date(((Number) value).longValue()); } return super.getData(value); } }; if (column.getJdbcType() == JDBCType.DATE) { column.setValueConverter(dateConvert); } else if (column.getJdbcType() == JDBCType.TIMESTAMP) { column.setValueConverter(dateConvert); } else if (column.getJdbcType() == JDBCType.NUMERIC) { column.setValueConverter(new NumberValueConverter(column.getJavaType())); } rdbTableMetaData.addColumn(column); } }); cache.put(cacheKey, rdbTableMetaData); if (useJpa) { Class type = entityFactory == null ? resultMaps.getType() : entityFactory.getInstanceType(resultMaps.getType()); RDBTableMetaData parseResult = JpaAnnotationParser.parseMetaDataFromEntity(type); if (parseResult != null) { for (RDBColumnMetaData columnMetaData : parseResult.getColumns()) { if (rdbTableMetaData.findColumn(columnMetaData.getName()) == null) { columnMetaData = columnMetaData.clone(); columnMetaData.setProperty("fromJpa", true); rdbTableMetaData.addColumn(columnMetaData); } } } } return rdbTableMetaData; }
From source file:org.molasdin.wbase.batis.support.BasicBatisEngine.java
License:Apache License
private String resultMapNameFromProp(String prop, ResultMap resultMap) { for (ResultMapping mapping : resultMap.getResultMappings()) { if (mapping.getNestedResultMapId() != null && prop.equals(mapping.getProperty())) { return mapping.getNestedResultMapId(); }// w ww .java 2s.co m } return null; }