You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Daniel Henrique Alves Lima <em...@yahoo.com.br> on 2008/02/23 00:18:43 UTC
How to replace ResultMap implementation used by iBatis
Hi everybody ! First of all: I'm sorry for my poor English :-/
Is there any way of replace iBatis ResultMap default implementation ?
I've used some "brute force" to do it, but i don't know if this is the
better way...
Thanks in advance !
=== AnyClass.java ===
(...)
Reader reader = null;
try {
try {
reader = Resources.getResourceAsReader(configFile);
ExtendedSqlMapClient client = (ExtendedSqlMapClient)
SqlMapClientBuilder
.buildSqlMapClient(reader);
SqlMapExecutorDelegate delegate = client.getDelegate();
Iterator mapNames = delegate.getResultMapNames();
while (mapNames.hasNext()) {
String name = (String) mapNames.next();
System.out.println(name);
ResultMap resultMap = delegate.getResultMap(name);
MyResultMap newResultMap = new MyResultMap(
(BasicResultMap)
resultMap, delegate);
// System.out.println(newResultMap);
delegate.addResultMap(newResultMap);
}
Iterator mappedStmtNames = delegate.getMappedStatementNames();
while (mappedStmtNames.hasNext()) {
String name = (String) mappedStmtNames.next();
System.out.println(name);
BaseStatement mappedStatement = (BaseStatement) delegate
.getMappedStatement(name);
ResultMap resultMap = mappedStatement.getResultMap();
if (resultMap != null) {
resultMap = delegate.getResultMap(resultMap.getId());
mappedStatement.setResultMap(resultMap);
}
}
} finally {
if (reader != null) {
reader.close();
reader = null;
}
}
} catch (IOException e) {
throw new IllegalArgumentException(e.getMessage());
}
(...)
=== MyResultMap.java ===
(...)
public MyResultMap(BasicResultMap sourceResultMap,
SqlMapExecutorDelegate delegate) {
super(delegate);
this.setId(sourceResultMap.getId());
this.setDataExchange(sourceResultMap.getDataExchange());
this.setDataExchange(sourceResultMap.getDataExchange());
this.setResource(sourceResultMap.getResource());
this.setResultClass(sourceResultMap.getResultClass());
this.setResultMappingList(Arrays.asList(sourceResultMap
.getResultMappings()));
this.setXmlName(sourceResultMap.getXmlName());
if (sourceResultMap.hasGroupBy()) {
Iterator groups = sourceResultMap.groupByProps();
while (groups.hasNext()) {
String group = (String) groups.next();
this.addGroupByProperty(group);
}
}
List nestedMappings = sourceResultMap.getNestedResultMappings();
if (nestedMappings != null) {
for (Iterator mappings = nestedMappings.iterator(); mappings
.hasNext();) {
ResultMapping mapping = (ResultMapping) mappings.next();
this.addNestedResultMappings(mapping);
}
}
}
(...)