You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Gary <gl...@yahoo.com> on 2004/03/19 21:16:06 UTC

Complex (for me) OJB Problem

I have a, for me, complex OJB problem, and am looking
for pointers.

I have two classes: a Test, and a PanelOfTests.  I
have two tables: Tests_Table, and Panel_Test_Table.

Here is the pseudocode:

public class Test {
	int testID;
	String category; // can be "TE" for test, "PA" for
panel
}

public class PanelOfTests extends Test {
	Collection tests; // a collection of Test objects
}

table Tests_Table
	test_key, int
	category, varchar

table Panel_Test_Table
	panel_test_key, int
	panel_key, int
	test_key, int

A PanelOfTests then is in fact a Test, one that has a
category of "PA," and which contains 1-n other Tests. 
To find the tests that a given panel (say, 55)
contains I get all the rows in Panel_Test_Table where
panel_key = 55 and instantiate a Test object for each
of the test_keys.

Any good ideas on how to do this in OJB metadata/row
readers/?  I am unable to change the database layout.

Thanks, Gary

__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

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


Re: Complex (for me) OJB Problem

Posted by Gary <gl...@yahoo.com>.
Thanks for all your help, Jakob - I'll give it a try!

Gary

--- Jakob Braeuchi <jb...@gmx.ch> wrote:
> hi gary,
> 
> i propose you define a m:n mapping between Test and
> Test_Panel with 
> Panel_Test_Table as intermediate table.
> 
> i'm not sure about the pk Panel_Test_Table. in our
> examples the pk is the 
> combined pk of the linked tables. afaik it's not
> possible to define a special pk 
> for the intermediate table, but you could probably
> use an autoincrement feature 
> of your dbms.
> 
> the other point is that Test ans Test_Panel are
> mapped to the same table. ojb 
> uses the column ojbConcreteClass to distiguish the
> class in the table. this 
> column is automatically added in QueryFactory and
> it's also used by 
> RowReaderDefaultImpl to get the class to be
> instantiated.
> 
> protected ClassDescriptor selectClassDescriptor(Map
> row) throws 
> PersistenceBrokerException
>      {
>          // check if there is an attribute which
> tells us which concrete class 
> is to be instantiated
>          FieldDescriptor concreteClassFD =
> m_cld.getOjbConcreteClassField();
> 
>          if (concreteClassFD == null)
>              return m_cld;
>          else
>          {
> ....
> 
> you'll have to implement your own row-reader using
> the column 'category' to 
> decide which class to use.
> 
> hth
> 
> jakob
> 
> Gary wrote:
> 
> > Jakob:
> > 
> > 
> >>>Thanks for your quick reply.
> > 
> > 
> > --- Jakob Braeuchi <jb...@gmx.ch> wrote:
> > 
> >>hi gary,
> >>
> >>imo the table Panel_Test_Table is a link table to
> >>connect rows in Test_table, is 
> >>that correct ?
> >>
> >>>Yes
> >>
> >>Test_table
> >>test_key / category
> >>
> >>55 / PA
> >>10 / TE
> >>15 / TE
> >>66 / PA
> >>
> >>Panel_Test_Table
> >>panel_test_key / panel_key / test_key
> >>
> >>1 / 55 / 10
> >>2 / 55 / 15
> >>3 / 66 / 10
> >>
> >>a test can be connected to multiple panels ?
> >>
> >>>Yes
> >>
> >>is it a m:n relationship between Test_table rows ?
> >>
> >>>Yes, if I understand the question, when the
> > 
> > category >> is "PA"
> > 
> >>what's the meaning of the panel_test_key ?
> >>
> >>>No meaning, just a unique ID for the row.
> >>
> >>jakob
> >>
> >>
> >>Gary wrote:
> >>
> >>
> >>>I have a, for me, complex OJB problem, and am
> >>
> >>looking
> >>
> >>>for pointers.
> >>>
> >>>I have two classes: a Test, and a PanelOfTests. 
> I
> >>>have two tables: Tests_Table, and
> >>
> >>Panel_Test_Table.
> >>
> >>>Here is the pseudocode:
> >>>
> >>>public class Test {
> >>>	int testID;
> >>>	String category; // can be "TE" for test, "PA"
> >>
> >>for
> >>
> >>>panel
> >>>}
> >>>
> >>>public class PanelOfTests extends Test {
> >>>	Collection tests; // a collection of Test
> objects
> >>>}
> >>>
> >>>table Tests_Table
> >>>	test_key, int
> >>>	category, varchar
> >>>
> >>>table Panel_Test_Table
> >>>	panel_test_key, int
> >>>	panel_key, int
> >>>	test_key, int
> >>>
> >>>A PanelOfTests then is in fact a Test, one that
> >>
> >>has a
> >>
> >>>category of "PA," and which contains 1-n other
> >>
> >>Tests. 
> >>
> >>>To find the tests that a given panel (say, 55)
> >>>contains I get all the rows in Panel_Test_Table
> >>
> >>where
> >>
> >>>panel_key = 55 and instantiate a Test object for
> >>
> >>each
> >>
> >>>of the test_keys.
> >>>
> >>>Any good ideas on how to do this in OJB
> >>
> >>metadata/row
> >>
> >>>readers/?  I am unable to change the database
> >>
> >>layout.
> >>
> >>>Thanks, Gary
> >>>
> >>>__________________________________
> >>>Do you Yahoo!?
> >>>Yahoo! Mail - More reliable, more storage, less
> >>
> >>spam
> >>
> >>>http://mail.yahoo.com
> >>>
> >>>
> >>
> >
>
---------------------------------------------------------------------
> > 
> >>>To unsubscribe, e-mail:
> >>
> >>ojb-user-unsubscribe@db.apache.org
> >>
> >>>For additional commands, e-mail:
> >>
> >>ojb-user-help@db.apache.org
> >>
> >>>
> >>
> >
>
---------------------------------------------------------------------
> > 
> >>To unsubscribe, e-mail:
> >>ojb-user-unsubscribe@db.apache.org
> >>For additional commands, e-mail:
> >>ojb-user-help@db.apache.org
> >>
> > 
> > 
> > 
> > __________________________________
> 
=== message truncated ===


__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html

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


Re: Complex (for me) OJB Problem

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi gary,

i propose you define a m:n mapping between Test and Test_Panel with 
Panel_Test_Table as intermediate table.

i'm not sure about the pk Panel_Test_Table. in our examples the pk is the 
combined pk of the linked tables. afaik it's not possible to define a special pk 
for the intermediate table, but you could probably use an autoincrement feature 
of your dbms.

the other point is that Test ans Test_Panel are mapped to the same table. ojb 
uses the column ojbConcreteClass to distiguish the class in the table. this 
column is automatically added in QueryFactory and it's also used by 
RowReaderDefaultImpl to get the class to be instantiated.

protected ClassDescriptor selectClassDescriptor(Map row) throws 
PersistenceBrokerException
     {
         // check if there is an attribute which tells us which concrete class 
is to be instantiated
         FieldDescriptor concreteClassFD = m_cld.getOjbConcreteClassField();

         if (concreteClassFD == null)
             return m_cld;
         else
         {
....

you'll have to implement your own row-reader using the column 'category' to 
decide which class to use.

hth

jakob

Gary wrote:

> Jakob:
> 
> 
>>>Thanks for your quick reply.
> 
> 
> --- Jakob Braeuchi <jb...@gmx.ch> wrote:
> 
>>hi gary,
>>
>>imo the table Panel_Test_Table is a link table to
>>connect rows in Test_table, is 
>>that correct ?
>>
>>>Yes
>>
>>Test_table
>>test_key / category
>>
>>55 / PA
>>10 / TE
>>15 / TE
>>66 / PA
>>
>>Panel_Test_Table
>>panel_test_key / panel_key / test_key
>>
>>1 / 55 / 10
>>2 / 55 / 15
>>3 / 66 / 10
>>
>>a test can be connected to multiple panels ?
>>
>>>Yes
>>
>>is it a m:n relationship between Test_table rows ?
>>
>>>Yes, if I understand the question, when the
> 
> category >> is "PA"
> 
>>what's the meaning of the panel_test_key ?
>>
>>>No meaning, just a unique ID for the row.
>>
>>jakob
>>
>>
>>Gary wrote:
>>
>>
>>>I have a, for me, complex OJB problem, and am
>>
>>looking
>>
>>>for pointers.
>>>
>>>I have two classes: a Test, and a PanelOfTests.  I
>>>have two tables: Tests_Table, and
>>
>>Panel_Test_Table.
>>
>>>Here is the pseudocode:
>>>
>>>public class Test {
>>>	int testID;
>>>	String category; // can be "TE" for test, "PA"
>>
>>for
>>
>>>panel
>>>}
>>>
>>>public class PanelOfTests extends Test {
>>>	Collection tests; // a collection of Test objects
>>>}
>>>
>>>table Tests_Table
>>>	test_key, int
>>>	category, varchar
>>>
>>>table Panel_Test_Table
>>>	panel_test_key, int
>>>	panel_key, int
>>>	test_key, int
>>>
>>>A PanelOfTests then is in fact a Test, one that
>>
>>has a
>>
>>>category of "PA," and which contains 1-n other
>>
>>Tests. 
>>
>>>To find the tests that a given panel (say, 55)
>>>contains I get all the rows in Panel_Test_Table
>>
>>where
>>
>>>panel_key = 55 and instantiate a Test object for
>>
>>each
>>
>>>of the test_keys.
>>>
>>>Any good ideas on how to do this in OJB
>>
>>metadata/row
>>
>>>readers/?  I am unable to change the database
>>
>>layout.
>>
>>>Thanks, Gary
>>>
>>>__________________________________
>>>Do you Yahoo!?
>>>Yahoo! Mail - More reliable, more storage, less
>>
>>spam
>>
>>>http://mail.yahoo.com
>>>
>>>
>>
> ---------------------------------------------------------------------
> 
>>>To unsubscribe, e-mail:
>>
>>ojb-user-unsubscribe@db.apache.org
>>
>>>For additional commands, e-mail:
>>
>>ojb-user-help@db.apache.org
>>
>>>
>>
> ---------------------------------------------------------------------
> 
>>To unsubscribe, e-mail:
>>ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail:
>>ojb-user-help@db.apache.org
>>
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - More reliable, more storage, less spam
> http://mail.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

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


Re: Complex (for me) OJB Problem

Posted by Gary <gl...@yahoo.com>.
Jakob:

>> Thanks for your quick reply.

--- Jakob Braeuchi <jb...@gmx.ch> wrote:
> hi gary,
> 
> imo the table Panel_Test_Table is a link table to
> connect rows in Test_table, is 
> that correct ?
>> Yes
> 
> Test_table
> test_key / category
> 
> 55 / PA
> 10 / TE
> 15 / TE
> 66 / PA
> 
> Panel_Test_Table
> panel_test_key / panel_key / test_key
> 
> 1 / 55 / 10
> 2 / 55 / 15
> 3 / 66 / 10
> 
> a test can be connected to multiple panels ?
>> Yes
> is it a m:n relationship between Test_table rows ?
>> Yes, if I understand the question, when the
category >> is "PA"
> what's the meaning of the panel_test_key ?
>> No meaning, just a unique ID for the row.
> 
> jakob
> 
> 
> Gary wrote:
> 
> > I have a, for me, complex OJB problem, and am
> looking
> > for pointers.
> > 
> > I have two classes: a Test, and a PanelOfTests.  I
> > have two tables: Tests_Table, and
> Panel_Test_Table.
> > 
> > Here is the pseudocode:
> > 
> > public class Test {
> > 	int testID;
> > 	String category; // can be "TE" for test, "PA"
> for
> > panel
> > }
> > 
> > public class PanelOfTests extends Test {
> > 	Collection tests; // a collection of Test objects
> > }
> > 
> > table Tests_Table
> > 	test_key, int
> > 	category, varchar
> > 
> > table Panel_Test_Table
> > 	panel_test_key, int
> > 	panel_key, int
> > 	test_key, int
> > 
> > A PanelOfTests then is in fact a Test, one that
> has a
> > category of "PA," and which contains 1-n other
> Tests. 
> > To find the tests that a given panel (say, 55)
> > contains I get all the rows in Panel_Test_Table
> where
> > panel_key = 55 and instantiate a Test object for
> each
> > of the test_keys.
> > 
> > Any good ideas on how to do this in OJB
> metadata/row
> > readers/?  I am unable to change the database
> layout.
> > 
> > Thanks, Gary
> > 
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Mail - More reliable, more storage, less
> spam
> > http://mail.yahoo.com
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail:
> ojb-user-help@db.apache.org
> > 
> > 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail:
> ojb-user-help@db.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

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


Re: Complex (for me) OJB Problem

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi gary,

imo the table Panel_Test_Table is a link table to connect rows in Test_table, is 
that correct ?

Test_table
test_key / category

55 / PA
10 / TE
15 / TE
66 / PA

Panel_Test_Table
panel_test_key / panel_key / test_key

1 / 55 / 10
2 / 55 / 15
3 / 66 / 10

a test can be connected to multiple panels ?
is it a m:n relationship between Test_table rows ?
what's the meaning of the panel_test_key ?

jakob


Gary wrote:

> I have a, for me, complex OJB problem, and am looking
> for pointers.
> 
> I have two classes: a Test, and a PanelOfTests.  I
> have two tables: Tests_Table, and Panel_Test_Table.
> 
> Here is the pseudocode:
> 
> public class Test {
> 	int testID;
> 	String category; // can be "TE" for test, "PA" for
> panel
> }
> 
> public class PanelOfTests extends Test {
> 	Collection tests; // a collection of Test objects
> }
> 
> table Tests_Table
> 	test_key, int
> 	category, varchar
> 
> table Panel_Test_Table
> 	panel_test_key, int
> 	panel_key, int
> 	test_key, int
> 
> A PanelOfTests then is in fact a Test, one that has a
> category of "PA," and which contains 1-n other Tests. 
> To find the tests that a given panel (say, 55)
> contains I get all the rows in Panel_Test_Table where
> panel_key = 55 and instantiate a Test object for each
> of the test_keys.
> 
> Any good ideas on how to do this in OJB metadata/row
> readers/?  I am unable to change the database layout.
> 
> Thanks, Gary
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - More reliable, more storage, less spam
> http://mail.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

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