ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Henrique Alves Lima <email_danie...@yahoo.com.br>
Subject How to replace ResultMap implementation used by iBatis
Date Fri, 22 Feb 2008 23:18:43 GMT
	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);
        }
    }
}

(...)



Mime
View raw message