Betwixt bug as well it seems... (sigh)

Gus Heck <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user,gmane.text.xml.commons.devel
Message-ID <[email protected]>
In light of this, I decided to enable further development by setting the 
missing username and password for now until the bug can be resolved. 
When I did I got more funny results that look very much like a bug... 
The following code:

        InputStream is = 
Thread.currentThread().getContextClassLoader().getResourceAsStream("project_schema.xml");
        Database db = null;
        try {
            DatabaseReader reader = new DatabaseReader();
            db = (Database) reader.parse( is );
        } catch (IntrospectionException ie) {
            throw new RuntimeException("Error creating DatabaseReader 
for project_schema.xml");
        } catch (IOException ioe ) {
            throw new RuntimeException("Error loading project_schema.xml");
        } catch (SAXException saxe ) {
            throw new RuntimeException("Error parsing project_schema.xml");
        }

        System.out.println(db);
        for (Iterator iter = db.getTables().iterator();iter.hasNext();) {
            org.apache.commons.sql.model.Table t
            = (org.apache.commons.sql.model.Table) iter.next();
            System.out.println(t);
            System.out.println(t.getName());           
        }

produces the following output:

org.apache.commons.sql.model.Database@e6235d[name=fdbtest2;tableCount=1]
org.apache.commons.sql.model.Table@11775bc
null

The number of tables is correct, but I feel certain that it should not 
be named null giventhe following project_schema.xml (still in defaults 
for the field sizes... I'll deal with that after I write something to 
the database successfully):

<database name="fdbtest2">
    <table name="LocationBase">
        <column name="id"
                javaName="id"
                type="INTEGER"
                primaryKey="true"
                required="true"
        />
        <column name="country"
                javaName="country"
                type="VARCHAR"
                size="24"
        />
        <column name="stateOrRegion"
                javaName="stateOrRegion"
                type="VARCHAR"
                size="24"
        />
        <column name="subRegion"
                javaName="subRegion"
                type="VARCHAR"
                size="24"
        />
        <column name="city"
                javaName="city"
                type="VARCHAR"
                size="24"
        />
    </table>
</database>

Sadly it appears that commons-sql's DatabaseReader is just a fairly 
simple extension of a betwixt BeanReader...

package org.apache.commons.sql.io;

import java.beans.IntrospectionException;

import org.apache.commons.betwixt.XMLIntrospector;
import org.apache.commons.betwixt.io.BeanReader;
import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
import org.apache.commons.sql.model.Database;

/**
 * This class parsers XML and creates a fully populated Database bean.
 * This class is-a Digester and so can support configuration via custom 
rules.
 *
 * @author <a href="mailto:[email protected]">James Strachan</a>
 * @version $Revision: 1.14 $
 */
public class DatabaseReader extends BeanReader {
   
    public DatabaseReader() throws IntrospectionException {
        setXMLIntrospector( newXMLIntrospector() );
        registerBeanClass(Database.class);
    }

    /**
     * A factory method to create the default introspector used to turn
     * the Database object model into XML
     */   
    protected static XMLIntrospector newXMLIntrospector() {
        XMLIntrospector introspector = new XMLIntrospector();

        // configure the style of the XML, to brief and attribute based
        introspector.setAttributesForPrimitives(true);
        introspector.setWrapCollectionsInElement(false);

        // set the mixed case name mapper
        introspector.setElementNameMapper(new HyphenatedNameMapper());
        //introspector.setElementNameMapper(new DecapitalizeNameMapper());

        return introspector;
    }
}


and so this is probably a betwixt bug. I hope someone who understands 
betwixt can verify this.... (hence the cross post to commons-dev).

-Gus



Andy Malakov wrote:

>Hello All,
>
>It looks like a bug:
>
>Class o.a.ojb.broker.metadata.MetadataManager.copyOfGlobalRepository() uses SerializationUtils.clone() to return a copy of OJB
>repository. At the same time some objects in repository graph have transient fields which become un-initialized (null) after the
>clone.
>
>For example, o.a.ojb.broker.metadata.fieldaccess.AnonymousPersistentField has fkCache map that will become null in clone, and will
>cause NullPointerException when get()/set() will be executed.
>
>Method copyOfGlobalRepository() is required for per-thread handling of metadata.
>
>Thank you,
>Andy
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>
>  
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.