db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kurt Hoehn" <kho...@etranscor.com>
Subject RE: [anonymous fields] querying fields of "Multiple Joined Tables"
Date Fri, 15 Aug 2003 19:43:56 GMT
I did but this could cause an alias problem so its not good but I have a way
now of getting to the super class then I can check to see if the property of
"name" exists then alias the super classes table name so I wont need to
alias the table name in the query.  This is not a production statement more
of a proof of concept that I'm doing, checking to see if ojb is a good fit
in our environment.

-kurt


-----Original Message-----
From: Jakob Braeuchi [mailto:jbraeuchi@gmx.ch] 
Sent: Friday, August 15, 2003 3:42 PM
To: OJB Developers List
Subject: Re: [anonymous fields] querying fields of "Multiple Joined Tables"

hi kurt,

do you really use the table name in ...where PROFILE.name=$1")  ??


jakob

Kurt Hoehn wrote:

>Hello,
>
>I'm new to the group and the ojb stuff, but I noticed that only the
>ObjectReferenceDescriptor using the name of super will have a null for the
>name of the persistent field. This is what I did to get it to work, its not
>pretty and I don't know if I'm going down the right path but I used the
>extends in the class descriptor and used the refrence-descriptor of super
to
>get a 1:1 relationship.
>
>            OQLQuery query = odmg.newOQLQuery();
>            query.create( "select all from " + Branch.class.getName() + "
>where PROFILE.name=$1");
>            query.bind("Army");
>
><class-descriptor class="com.etranscor.ojb.terminal.Profile"
>table="PROFILE">
>        <field-descriptor name="profileId"
>                          column="PROFILE_ID"
>                          jdbc-type="INTEGER"
>                          primarykey="true"
>                          nullable="false"
>                          autoincrement="true"
>                          sequence-name="TERMINAL_GENERATOR"/>
>        <field-descriptor name="name"
>                          column="NAME"
>                          jdbc-type="VARCHAR"
>                          nullable="false"
>                          length="200"/>
>        <field-descriptor name="status"
>                          column="STATUS"
>                          jdbc-type="CHAR"
>                          nullable="false"
>                          length="1"/>
>        <field-descriptor name="lastUpdateTime"
>                          column="LAST_UPDATE_TIME"
>                          jdbc-type="TIMESTAMP"
>                          nullable="false"/>
>    </class-descriptor>
><!-- Definitions for com.etranscor.ojb.terminal.military.Branch -->
>    <class-descriptor class="com.etranscor.ojb.terminal.military.Branch"
>                      table="BRANCH"
>                      extends="com.etranscor.ojb.terminal.Profile">
>        <field-descriptor name="profileId"
>                          column="PROFILE_ID"
>                          jdbc-type="INTEGER"
>                          primarykey="true"
>                          nullable="false"
>                          autoincrement="true"
>                          sequence-name="TERMINAL_GENERATOR"/>
>        <field-descriptor name="code"
>                          column="CODE"
>                          jdbc-type="CHAR"
>                          length="2"
>                          nullable="false"/>
>
>        <reference-descriptor name="super"
>class-ref="com.etranscor.ojb.terminal.Profile">
>            <foreignkey field-ref="profileId"/>
>        </reference-descriptor>
>        <collection-descriptor name="regions"
> 
>element-class-ref="com.etranscor.ojb.terminal.military.Region"
>                               refresh="true"
>                               proxy="true"
>                               auto-retrieve="true">
>            <inverse-foreignkey field-ref="branchId"/>
>        </collection-descriptor>
>    </class-descriptor>
>
>
>Here are the methods in the SqlSelectStatement.java
>
>    private void appendSuperClassJoin(ClassDescriptor cld, ClassDescriptor
>cldSuper, StringBuffer stmt, StringBuffer where)
>    {
>        stmt.append(",").append(cldSuper.getFullTableName());
>        if(where != null && where.length() > 0){
>            where.append(" AND ");
>        }
>
>        // get reference field in super class
>        Iterator objRefs = cld.getObjectReferenceDescriptors().iterator();
>        while( objRefs.hasNext() )
>        {
>            ObjectReferenceDescriptor superRef =
(ObjectReferenceDescriptor)
>objRefs.next();
>            if( superRef.getPersistentField().getName() == null )
>            {
>                Iterator itr = superRef.getForeignKeyFields().iterator();
>                while( itr.hasNext() )
>                {
>                    FieldDescriptor field = cld.getFieldDescriptorByName(
>(String) itr.next() );
> 
>where.append(cldSuper.getFullTableName()).append(".").append(
>cldSuper.getPrimaryKey().getColumnName() );
>                    where.append(" = ");
>
where.append(cld.getFullTableName()).append(".").append(
>field.getColumnName() );
>
>                    if( itr.hasNext() )
>                    {
>                        where.append(" AND ");
>                    }
>                }
>
>	  	    break;
>            }
>        }
>    }
>
>    private void appendSuperClassColumns(ClassDescriptor cldSub,
>ClassDescriptor cldSuper, StringBuffer buf)
>    {
>        FieldDescriptor[] fields = cldSuper.getFieldDescriptions();
>        for (int i = 0; i < fields.length; i++)
>        {
>            FieldDescriptor field = fields[i];
>
>		  //Bad 
>             if (i >= 0)
>                {
>                    buf.append(",");
>                }
>                buf.append(cldSuper.getFullTableName());
>                buf.append(".");
>                buf.append(field.getColumnName());
>                //columnList.add(field.getAttributeName());
>
>        }
>
>    }
>
>This works but I noticed that aliasing could be come an issue, and are they
>going to be deprecating extends in the class-descriptor, sorry about all
the
>code.
>
>-kurt
>
>
>-----Original Message-----
>From: Jakob Braeuchi [mailto:jbraeuchi@gmx.ch] 
>Sent: Friday, August 15, 2003 2:28 PM
>To: OJB Developers List
>Cc: houari.tine@ca-cedicam.fr
>Subject: [anonymous fields] querying fields of "Multiple Joined Tables" 
>
>hi all,
>
>armin found a problem in the testcase which uses attributes of the super 
>class in a query.
>the situation is as follows:
>
> <class-descriptor
>        class="org.apache.ojb.broker.ObjectRepository$E"
>        table="TABLE_E">
> ...
>        <field-descriptor
>            name="someSuperValue"
>            column="SOMESUPERVALUE"
>            jdbc-type="INTEGER"
>        />
>
> </class-descriptor>
>
> <class-descriptor
>        class="org.apache.ojb.broker.ObjectRepository$F"
>        table="TABLE_F">
>...
>        <field-descriptor
>            name="eID"
>            column="E_ID"
>            jdbc-type="INTEGER"
>            access="anonymous"
>        />
>
>        <field-descriptor
>            name="someValue"
>            column="SOMEVALUE"
>            jdbc-type="INTEGER"
>        />
>
>          <reference-descriptor name="super"
>              class-ref="org.apache.ojb.broker.ObjectRepository$E"
>            <foreignkey field-ref="eID" />
>          </reference-descriptor>
>    </class-descriptor>
>
>
>when querying for 'F' using attributes of 'F' (someValue) everything is 
>ok. but using attributes of the super E (someSuperValue) does not work 
>because there's no real relationship between 'F' and 'E'.
>i could solve the problem by adding the name 'super' to the appropriate 
>anonymous field:
>
>   public AnonymousPersistentFieldForInheritance(ClassDescriptor cld)
>   {
>       super("super");
>       this.cld = cld;
>   }
>
>in the query the attribute of class 'E' has to be prefixed by 'super':
>
>       c.addEqualTo("super.someSuperValue", new Integer(key2));
>
>this works, but we loose transparency :(
>
>what do you think ???
>
>jakob
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>
>  
>


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



---------------------------------------------------------------------
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