db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carsten Spräner_Ext" <CSprae...@provinzial-online.de>
Subject Re: Re: Referencing an abstract class. The next turn...
Date Tue, 12 Oct 2004 07:51:59 GMT
Hello Tom,

here is my repository_test.xml:

<class-descriptor class="db.A" table="A" isolation-level
="read-uncommitted">
  <extent-class class-ref="db.B"/>
  <field-descriptor name="id" id="1" column="ID" primarykey="true"
autoincrement="true" jdbc-type="BIGINT" />
  <field-descriptor name="aAttr" id="1" column="A_ATTR" jdbc-type="VARCHAR"
/>
  <field-descriptor name="colId" jdbc-type="BIGINT" access="anonymous"
column="COL_ID" />
</class-descriptor>

<class-descriptor class="db.B" table="B" isolation-level
="read-uncommitted">
  <field-descriptor name="id" id="1" column="ID" primarykey="true"
autoincrement="true" jdbc-type="BIGINT" />
  <field-descriptor name="superID" id="1" column="SUPER_ID" jdbc-type
="BIGINT" access="anonymous"/>
  <field-descriptor name="bAttr" id="2" column="B_ATTR" jdbc-type="VARCHAR"
/>
  <reference-descriptor name="super"
    auto-update="true"
    auto-retrieve="true"
    class-ref="db.A">
     <foreignkey field-ref="superID"/>
  </reference-descriptor>
</class-descriptor>

<class-descriptor class="db.Col" table="COL" isolation-level
="read-uncommitted">
  <field-descriptor name="id" id="1" column="ID" primarykey="true"
autoincrement="true" jdbc-type="BIGINT" />
  <collection-descriptor
    name="aCol"
    auto-retrieve="true"
    auto-update="true"
    element-class-ref="db.A"
  >
    <inverse-foreignkey field-ref="colId"/>
  </collection-descriptor>
</class-descriptor>

I got the first error fixed in the ClassDesriptor. In the method
getFieldDescriptorByName it only returns the FieldDescriptors of its own.
It does not look in the baseClass if it has one. The following code fixes
this problem:

    /**
     * Returns the matching {@link FieldDescriptor}.
     */
    public FieldDescriptor getFieldDescriptorByName(String name)
    {
        if (name == null || m_FieldDescriptions == null)
        {
            return null;
        }

        if (m_fieldDescriptorNameMap == null)
        {
            HashMap nameMap = new HashMap();

            FieldDescriptor[] descriptors = getFieldDescriptions();
            for (int i = descriptors.length - 1; i >= 0; i--)
            {
                FieldDescriptor fld = descriptors[i];
                nameMap.put(fld.getPersistentField().getName(), fld);
            }

            m_fieldDescriptorNameMap = nameMap;
        }
        // OLD: return (FieldDescriptor)
m_fieldDescriptorNameMap.get(name);
        /****************** FIX ***********************/
        FieldDescriptor fd = (FieldDescriptor)
m_fieldDescriptorNameMap.get(name);
        if( fd == null ) {
            String baseClass = getBaseClass();
            if( baseClass == null ) return null;
            ClassDescriptor cld  = getRepository().getDescriptorFor(
baseClass );
            fd = cld.getFieldDescriptorByName( name );
        }
        return fd;
    }

Thank you for your answer....

carsten




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message