This one time, at band camp, Rowland Watkins said:

RW>I'm having difficulties with changing the mapping file for different JDO
RW>instances.
RW>
RW>In the Tips & Tricks section on the Castor homepage, there is a mention
RW>of Castor being able to create "partial class views" and map them onto a
RW>table, allowing the programmer to get only some of the data from the
RW>table. I would like to do this as well as getting all the information
RW>using my original class. 
RW>
RW>I attempted to do all this in one mapping file, however, I found that
RW>both the partial and complete classes were being loaded, when I only
RW>wanted the partial one.
RW>
RW>I then tried using multiple JDO configurations for each type of object
RW>mapping I had, i.e. one for partial class and another for the complete
RW>one. The problem that I have noted on the mailing list is that the first
RW>loaded configuration is used for *all* subsequent JDO objects.
RW>
RW>Is it not possible to use dynamically configure the JDO at runtime?

Rowland, 

This can be achieved using the same JDO instance you simply must reload
the correct mapping descriptor. I have accomplished this in the past
using multiple <database> elements in the database descriptor, each one
with a different name and each one holding a different set of <mapping>
elements. For example:


<!DOCTYPE databases SYSTEM 
"/home/bsnyder/src/castor/build/classes/org/exolab/castor/jdo/conf/jdo-conf.dtd">

<database name="wolf1" engine="postgresql" >
    <data-source class-name="org.postgresql.jdbc2.optional.PoolingDataSource">
        <params server-name="wolf" database-name="demo9" port-number="5432" 
user="demo9" password="demo9" />
    </data-source>

  <mapping href="mapping1.xml" />
  <mapping href="mapping2.xml" />
  <mapping href="mapping3.xml" />
</database>

<database name="wolf2" engine="postgresql" >
    <data-source class-name="org.postgresql.jdbc2.optional.PoolingDataSource">
        <params server-name="wolf" database-name="demo9" port-number="5432" 
user="demo9" password="demo9" />
    </data-source>

  <mapping href="mapping4.xml" />
  <mapping href="mapping5.xml" />
  <mapping href="mapping6.xml" />
</database>

Then when I need to load a different sent of mapping descriptors,
I simply call (re)set the configuration for the JDO instance:

    public static final String DATABASE_DESC = "database-blah.xml"; 
    ...
    String jdoConfUrl = Thread.currentThread().getContextClassLoader().getResource( 
DATABASE_DESC ).toString();
    ...
    _jdo.setConfiguration( jdoConfUrl );

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