Hi Steve,

,> 
> Hi all,
> We're starting to use OJB to replace hand coded SQL in some 
> of our objects
> now. Due to a flaky architecture, we have a 'User' object that maps to
> several tables. Here is the schema:
> 
> BV_USER
>       USER_ID         INTEGER
>       ACCOUNT_ID              INTEGER
>       USER_ALIAS              VARCHAR
>       PASSWORD                VARCHAR
> 
> BV_USER_PROFILE
>       USER_ID         INTEGER
>       FIRST_NAME              VARCHAR
>       EMAIL                   VARCHAR
> ....and about 50 more columns.
> 
> 
> We have one object that encompasses both these tables (I'm 
> not sure why
> BroadVision designed the table structure like they did, but 
> we have to live
> with it). Is it possible to have OJB materialize this object 
> with both the
> password and email address intact?
> 
> I could probably do this with a reference descriptor pointing 
> to an internal
> class that would be exposed via a facade, but I really don't 
> think that is
> the cleanest way of handling it.
> Any ideas?

Yes,
That should be possible by using the new anonymous fields feature.
Have a look at the following classes E and F. F extends E.
E is mapped to a table table_e and F is mapped to table_f:
http://cvs.apache.org/viewcvs/db-ojb/src/test/org/apache/ojb/broker/E.java
http://cvs.apache.org/viewcvs/db-ojb/src/test/org/apache/ojb/broker/F.java

There is a Testcase
http://cvs.apache.org/viewcvs/db-ojb/src/test/org/apache/ojb/broker/Anonymou
sFieldsTest.java

that demonstrates this feature:

        // produce some test data
        F entry = new F();
        entry.setSomeSuperValue(2718281);
        entry.setSomeValue(9999);
        Identity oid = new Identity(entry, broker);
        broker.store(entry);
                
        entry.setSomeSuperValue(2718282);
        entry.setSomeValue(10000);
        broker.store(entry);
                
        // clear cache and retrieve a copy from the DB
        broker.clearCache();            
        F copy = (F) broker.getObjectByIdentity(oid);

The mapping is as follows:

<!-- mappings for anonymous field testclasses-->
 <class-descriptor
        class="org.apache.ojb.broker.E"
        table="TABLE_E">

        <field-descriptor
            name="id"
            column="ID"
            jdbc-type="INTEGER"
            primarykey="true"
            autoincrement="true"
        />

        <field-descriptor
            name="someSuperValue"
            column="SOMESUPERVALUE"
            jdbc-type="INTEGER"
        />

 </class-descriptor>    

 <class-descriptor
        class="org.apache.ojb.broker.F"
        table="TABLE_F">

        <field-descriptor
            name="id"
            column="ID"
            jdbc-type="INTEGER"
            primarykey="true"
            autoincrement="true"
        />

        <field-descriptor
                name="eID"
                column="E_ID"
                jdbc-type="INTEGER"
                access="anonymous" 
        />

        <field-descriptor
            name="someValue"
            column="SOMEVALUE"
            jdbc-type="INTEGER"
        />
 
        
                <reference-descriptor name="this" 
                        class-ref="org.apache.ojb.broker.E" 
                auto-retrieve="true" 
                auto-update="true" 
                auto-delete="true">
                <foreignkey field-ref="eID" />
                </reference-descriptor>

    </class-descriptor>  



> 
> By the way, we've done stress testing of OJB and deem it fit 
> for production
> on our site which has over 2 million users. Great work.

Wow, that's great news!

cheers,
Thomas
 
> 
> 
> Steve   Cohen
> Senior Software Developer
> (216) 471-3824
> [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to