db-ojb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Armin Waibel" <ar...@code-au-lait.de>
Subject Re: Antwort: Re: Using different Qualifiers in DB2
Date Wed, 17 Sep 2003 11:29:22 GMT
Hi,

----- Original Message -----
From: <lasse.lambrecht@allianz.de>
To: "OJB Users List" <ojb-user@db.apache.org>
Sent: Wednesday, September 17, 2003 12:52 PM
Subject: Antwort: Re: Using different Qualifiers in DB2


>
> Hi Armin,
>
> your suggestion might work for my problem. I'll try it.
> At which point will the different class defs (that I added via
> MM.addProfile) be loaded?
When doing
MM.readDescriptorRepository(String fileName)
the repository file will be parsed.

> All in "advance" or not until I'm doing a
> concrete MM.loadProfile(...) call. The reason why I ask this is that
> my class defs are about 650 kb in size for each qualifier. It takes
> some seconds for OJB to get ready for "business". And if that happens
> every time I want to switch the qualifier...especially because it's a
> web app where all the users use the same server.
>
When you do
MM.loadProfile(...)
the DescriptorRepository instance of the target repository file is
already load (see above). Thus the performance impact is negligible.

> But just to be sure you know what I mean: Can I extend the table name
> at runtime? In this case I would just define the Table as USER and
> PRODUCTION (in the repository) without the qualifier and add the
> right qualifier (PRODUCTION or TEST) at runtime before I'm doing a
> query/insert/.... So OJB plugs it together to PRODUCTION.USER and
> PRODUCTION.TEST. Is that possible?
>
I recommend not to do so. It is possible to change global metadata
at runtime, so you could do that. Let me try to explain what's the
problem. All PB instances share (by default, if you don't use profiles)
the same metadata instances. If now two threads try to store a
class User and you change global metadata to PRODUCTION.USER
and thread two can corrupt the first thread by setting TEST.USER.

Another suggestion (assume both schema PRODUCTION
and TEST are identical), why you don't use two different
databases: A TEST database and a PRODUCTION database
(both with same tables USER, ROLE, ...).
Then define two jdbc-connection-descriptor pointing to the
databases (e.g. jcdAlias names are "test" and "production").
Then it's easy to lookup a PB instance for each database:

PBKey key = new PBKey("test", ..., ....);
testBroker = PBF.createPersistenceBroker(key);

PBKey key = new PBKey("production", ..., ....);
prodBroker = PBF.createPersistenceBroker(key);

regards,
Armin

> <class-descriptor class="User" table="USER">
> .........
> </class-descriptor>
> <class-descriptor class="Order" table="ORDER">
> .........
> </class-descriptor>
>
> Regards
> Lasse
>
> ___
>
>
>
>
> |---------+--------------------------->
> |         |           "Armin Waibel"  |
> |         |           <armin@code-au-l|
> |         |           ait.de>         |
> |         |                           |
> |         |           16.09.03 18:16  |
> |         |           Bitte antworten |
> |         |           an "OJB Users   |
> |         |           List"           |
> |         |                           |
> |---------+--------------------------->
>
>-----------------------------------------------------------------------
--------------------------------------------------------|
>   |
|
>   |        An:      "OJB Users List" <ojb-user@db.apache.org>
|
>   |        Kopie:
|
>   |        Thema:   Re: Antwort: RE: Using different Qualifiers in DB2
|
>
>-----------------------------------------------------------------------
--------------------------------------------------------|
>
>
>
> Hi Lasse,
>
> Don't know if I understand your problem, but I will explain
> what I mean.
> Currently it's only possible to switch between different
> DescriptorRepository (metadata class-descriptor container)
> instances on a per thread based way using 'profiles' managed by
> MetadataManager (MM). See MM javadoc.
>
> In the 'normal' repository.xml only declare connection
> specific stuff (jdbc-connection-descriptors, by default in
> repository_database.xml sub-file).
> Then create additional repository files without connection
> metadata. Say all production relevant class-descriptors are declared
> in
> 'production.xml' file (with several sub-files if needed). Then create
> another repository file 'test.xml' and declare all TEST
> class-descriptor.
>
> With MetadataManager it is now possible to load/read these
> repository at runtime (before the first call to
> PersistenceBrokerFactory
> [PBF] is made) and add these as profiles
> MM.addProfile("production", prodRepository)
> MM.addProfile("test", testRepository)
> (you can set one of these DescriptorRepository instances as
> global repository - see MM javadoc).
>
> Now it is possible to load a dedicated profile using
> MM.loadProfile("test")
> for the calling thread at runtime before ask the PBF for
> a PersistenceBroker instance.
> Pitfall: be careful with caching, e.g. only use
> ObjectCachePerBrokerImpl
>
> Would this help you?
>
> regards,
> Armin
>
>
> ----- Original Message -----
> From: <lasse.lambrecht@allianz.de>
> To: "OJB Users List" <ojb-user@db.apache.org>
> Sent: Tuesday, September 16, 2003 5:04 PM
> Subject: Antwort: RE: Using different Qualifiers in DB2
>
>
> >
> > Hello,
> >
> > whoops, that was a copying error, the classes are named different,
> I
> > just added a second class-descriptor to make the example clearer.
> >
> > What I meant: PRODUCTION.USER and TEST.USER
> > I want to switch the PRODUCTION to TEST and vice versa during
> > runtime.
> > Here is the correct XML:
> >
> > <class-descriptor class="User" table="PRODUCTION.USER">
> > .........
> > </class-descriptor>
> > <class-descriptor class="Order" table="PRODUCTION.ORDER">
> > .........
> > </class-descriptor>
> >
> > and the second XML is
> >
> > <class-descriptor class="User" table="TEST.USER">
> > .........
> > </class-descriptor>
> > <class-descriptor class="Order" table="TEST.ORDER">
> > .........
> > </class-descriptor>
> >
> > Lasse
> >
> >
> >
> >
> >
> > |---------+--------------------------->
> > |         |           oliver.matz@ppi.|
> > |         |           de              |
> > |         |                           |
> > |         |           16.09.03 16:48  |
> > |         |           Bitte antworten |
> > |         |           an "OJB Users   |
> > |         |           List"           |
> > |         |                           |
> > |---------+--------------------------->
> >
> >
> ----------------------------------------------------------------------
-
>
> --------------------------------------------------------|
> >   |
> |
> >   |        An:      ojb-user@db.apache.org
> |
> >   |        Kopie:
> |
> >   |        Thema:   RE: Using different Qualifiers in DB2
> |
> >
> >
> ----------------------------------------------------------------------
-
>
> --------------------------------------------------------|
> >
> >
> >
> > Hello Lasse,
> >
> > > -----Original Message-----
> > >
> > > <class-descriptor class="User" table="PRODUCTION.USER">
> > > .........
> > > </class-descriptor>
> > > <class-descriptor class="User" table="PRODUCTION.ORDER">
> >                            ^^^^
> > I suppose you mean 'Order' here?
> >
> > > .........
> > > </class-descriptor>
> > >
> > > and
> > >
> > > <class-descriptor class="User" table="TEST.USER">
> > > .........
> > > </class-descriptor>
> > > <class-descriptor class="User" table="TEST.ORDER">
> >                            ^^^^
> > ditto.
> >
> > > .........
> > > </class-descriptor>
> >
> > >
> > > - The qualifier depends on what the user has choosen at the login
> > of
> > > our application
> > > -  It's a webbased application
> > >
> > > Is there a way I can set the qualifier at runtime in order to
> > switch
> > > between them?
> >
> > Something like (untested)
> >
> > mdm = org.apache.ojb.broker.metadata.MetadataManager.getInstance();
> > dr = mdm.getDescriptorRepository();
> > cld = dr.getDescriptorFor(User.class);
> > cld.setTableName("TEST.USER");
> >
> > might work.  Given that in your application several users access
> the
> > database with different qualifiers, you may have to switch back and
> > forth and care abot multithreading.  I do not know what happens
> then,
> > maybe someone else can help.
> >
> > Olli
> >
> >
> ---------------------------------------------------------------------
> > 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
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> 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
>
>



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


Mime
View raw message