This one time, at band camp, Bruce Snyder said:

BS>This one time, at band camp, Rowland Watkins said:
BS>
BS>RW>I'm having difficulties with changing the mapping file for different JDO
BS>RW>instances.
BS>RW>
BS>RW>In the Tips & Tricks section on the Castor homepage, there is a mention
BS>RW>of Castor being able to create "partial class views" and map them onto a
BS>RW>table, allowing the programmer to get only some of the data from the
BS>RW>table. I would like to do this as well as getting all the information
BS>RW>using my original class. 
BS>RW>
BS>RW>I attempted to do all this in one mapping file, however, I found that
BS>RW>both the partial and complete classes were being loaded, when I only
BS>RW>wanted the partial one.
BS>RW>
BS>RW>I then tried using multiple JDO configurations for each type of object
BS>RW>mapping I had, i.e. one for partial class and another for the complete
BS>RW>one. The problem that I have noted on the mailing list is that the first
BS>RW>loaded configuration is used for *all* subsequent JDO objects.
BS>RW>
BS>RW>Is it not possible to use dynamically configure the JDO at runtime?
BS>
BS>Rowland, 
BS>
BS>This can be achieved using the same JDO instance you simply must reload
BS>the correct mapping descriptor. I have accomplished this in the past
BS>using multiple <database> elements in the database descriptor, each one
BS>with a different name and each one holding a different set of <mapping>
BS>elements. For example:
BS>
BS>
BS><!DOCTYPE databases SYSTEM 
"/home/bsnyder/src/castor/build/classes/org/exolab/castor/jdo/conf/jdo-conf.dtd">
BS>
BS><database name="wolf1" engine="postgresql" >
BS>    <data-source class-name="org.postgresql.jdbc2.optional.PoolingDataSource">
BS>        <params server-name="wolf" database-name="demo9" port-number="5432" 
user="demo9" password="demo9" />
BS>    </data-source>
BS>
BS>  <mapping href="mapping1.xml" />
BS>  <mapping href="mapping2.xml" />
BS>  <mapping href="mapping3.xml" />
BS></database>
BS>
BS><database name="wolf2" engine="postgresql" >
BS>    <data-source class-name="org.postgresql.jdbc2.optional.PoolingDataSource">
BS>        <params server-name="wolf" database-name="demo9" port-number="5432" 
user="demo9" password="demo9" />
BS>    </data-source>
BS>
BS>  <mapping href="mapping4.xml" />
BS>  <mapping href="mapping5.xml" />
BS>  <mapping href="mapping6.xml" />
BS></database>
BS>
BS>Then when I need to load a different sent of mapping descriptors,
BS>I simply call (re)set the configuration for the JDO instance:
BS>
BS>    public static final String DATABASE_DESC = "database-blah.xml"; 
BS>    ...
BS>    String jdoConfUrl = Thread.currentThread().getContextClassLoader().getResource( 
DATABASE_DESC ).toString();
BS>    ...
BS>    _jdo.setConfiguration( jdoConfUrl );

My apologies, the code above is incomplete. Below is the full version: 

    public static final String DATABASE_DESC1 = "database-blah1.xml"; 
    public static final String DATABASE_DESC2 = "database-blah2.xml"; 
    ...
    String jdoConfUrl = Thread.currentThread().getContextClassLoader().getResource( 
DATABASE_DESC1 ).toString();
    ...
    _jdo.setConfiguration( jdoConfUrl );
    _jdo.setName( "wolf1" );

    _db = _jdo.getDatabase();
    ...

    // Do some work with this set of mapping descriptors
    ...
    // Now load the other set of mapping descriptors

    String jdoConfUrl = Thread.currentThread().getContextClassLoader().getResource( 
DATABASE_DESC2 ).toString();
    ...
    _jdo.setConfiguration( jdoConfUrl );
    _jdo.setName( "wolf2" );

    _db = _jdo.getDatabase();
    ...

    // And you're now using the new set of mapping descriptors

Bruce
-- 
perl -e 'print unpack("u30","<0G)[EMAIL PROTECTED]&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'

The Castor Project 
http://www.castor.org/

Apache Geronimo 
http://incubator.apache.org/projects/geronimo.html

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to