ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fábio Pisaruk" <pisa...@gmail.com>
Subject xmlbeans and ibatis
Date Thu, 30 Aug 2007 20:36:14 GMT
Hello!
I´ve got something for you that migth help in getting started with ibatis +
xmlbeans.
Yes, you will have to implement your own ResultObjectFactory but no big deal
´cause it´s easy and painless.
The real problem is to fill xmlbeans arrays. Trust me, I haven´t found a
simple way to do it.
Well, forget this smalltalk and let´s talking business...

First and foremost your custom ResultObjectFactory should resemble this:

public class XMLBeansResultObjectFactory implements
        com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactory {
    private static final Log logger = LogFactory
            .getLog(XMLBeansResultObjectFactory.class);

    public Object createInstance(String statement, Class c) {
        try {
            for (int i = 0; i < c.getDeclaredClasses().length; i++) {
                if (c.getDeclaredClasses()[i].getName().endsWith("Factory"))
{
                    logger.debug(c.getDeclaredClasses()[i].getName());
                    Object obj = c.getDeclaredClasses()[i].getMethod(
                            "newInstance", null).invoke(null, null);
                    return obj;
                }
            }
            if (Collection.class.isAssignableFrom (c))
                return new ArrayList();
            return c.newInstance();
        } catch (Exception e) {
            RuntimeException err = new RuntimeException(
                    "Erro na tentativa de instar objeto da classe "
                            + c.getName() + "\n" + e.getMessage());
            err.initCause(e);
            throw err;
        }
    }

    public void setProperty(String arg0, String arg1) {
    }

}

It´s not that hard to see that it´s using inner static factioy class in
order to build xmlbean object instances.

Second you must inform ibatis to use your custom builder instead of the
provided one.
<sqlMapConfig>
    <resultObjectFactory
        type="CustomResultObjectFactory" />
...

Remember to use the full qualified class name otherwise it won´t work.


See ya.



-- 
Visto como se não executa logo a sentença sobre a má obra, o coração dos
filhos dos homens está inteiramente disposto a praticar o mal.


--Nerd´s sign

If you have four classes, Everybody, Somebody, Anybody, and Nobody, if
Somebody has a bug, it could be Anybody 's fault but Nobody really knows,
while Everybody shares responsibility.

-- 
Visto como se não executa logo a sentença sobre a má obra, o coração dos
filhos dos homens está inteiramente disposto a praticar o mal.


--Nerd´s sign

If you have four classes, Everybody, Somebody, Anybody, and Nobody, if
Somebody has a bug, it could be Anybody 's fault but Nobody really knows,
while Everybody shares responsibility.
Mime
View raw message