Hi Hans,

first you have to differ between "connection metadata" and "object metadata". If you don't want to change persistence capable object metadata no need to use "per thread changes mode".

The default connection flag (jcd.setDefaultConnection(true)) can only be used by one JCD.
http://db.apache.org/ojb/docu/guides/pb-guide.html#How+to+access+the+PB-api%3F

Seems the "main" database settings are stored in a *.ini file, so it would be useful to use a separate repository file with a connection template to read the other OJB specific connection properties (instead of using hard coded ones) - example see below.

Then you can lookup the connection template file:
MetadataManager mm = MetadataManager.getInstance();
// read connection metadata from repository file
ConnectionRepository cr = mm.readConnectionRepository("con_template.xml");

The new ConnectionRepository now contain one jdbc-connection-descriptor. We can now lookup the JCD template and set additional properties or adding the new JCD to the current used ConnectionRepository.
Add the jcd to the existing metadata:
// merge new connection metadata with existing one
mm.mergeConnectionRepository(cr);
// now lookup the current used ConnectionRepository
// which contains the old and the new connection metadata
cr = mm.connectionRepository();

// Lookup the new jcd to set the specific properties
JdbcConnectionDescriptor jcd = cr.getDescriptor(new PBKey("runtime","",""));
// now set ini-file properties
jcd.setDbAlias(iniFile.getValue("DatabaseAlias"));
...

Now you can use the new DB with:
PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker(new PBKey("runtime","ini-user","ini-passwd"));

HTH
regards,
Armin

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE descriptor-repository SYSTEM "repository.dtd">

<descriptor-repository version="1.0" isolation-level="read-uncommitted">
    <jdbc-connection-descriptor
        jcd-alias="runtime"
        platform=""
        jdbc-level="2.0"
        driver=""
        protocol="jdbc"
        subprotocol=""
        dbalias=""
        username=""
        password=""
        batch-mode="false"
    >

<object-cache class="org.apache.ojb.broker.cache.ObjectCacheEmptyImpl">
        </object-cache>

        <connection-pool
            maxActive="5"
            whenExhaustedAction="0"
            validationQuery="select 1 from dual"
        />

<sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl">
            <attribute attribute-name="grabSize" attribute-value="5"/>
        </sequence-manager>
    </jdbc-connection-descriptor>
</descriptor-repository>


Hans Novak wrote:
Hi,

i have succsessful add a second broker with "createPersistenceBroker" and i can use it. But on runtime, i open the class later again and then i cant add it, because the broker alresay exists. And i cant switch to my broker, only to the "default" one. I can also not change my broker to the default broker.

This is my code:


public PartnerFactoryCore() {
             final IniFile iniFile = new IniFile("osf.ini");
             MetadataManager mm = MetadataManager.getInstance();
       mm.setEnablePerThreadChanges(true);
       ConnectionRepository cr = mm.connectionRepository();

       PBKey key = new PBKey("defaulthn", "user", "pw");

       if (cr.getDescriptor(key) == null) {
           JdbcConnectionDescriptor jcd = new JdbcConnectionDescriptor();
           jcd.setJcdAlias("defaulthn");
           jcd.setDefaultConnection(true);
           jcd.setJdbcLevel("2.0");
           jcd.setDriver("com.mysql.jdbc.Driver");
           jcd.setProtocol("jdbc");
           jcd.setSubProtocol("mysql");
           jcd.setDbAlias(iniFile.getValue("DatabaseAlias"));
           jcd.setUserName(iniFile.getValue("user"));
           jcd.setPassWord(iniFile.getValue("pw"));
           jcd.setEagerRelease(false);
           jcd.setBatchMode(false);
           jcd.setUseAutoCommit(1);
           jcd.setIgnoreAutoCommitExceptions(false);
           jcd.setDbms("MySQL");

PersistenceBroker broker1 = PersistenceBrokerFactory.defaultPersistenceBroker(); SequenceDescriptor sd = broker1.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();
           jcd.setSequenceDescriptor(sd);
           cr.addDescriptor(jcd);
broker = PersistenceBrokerFactory.createPersistenceBroker(key);
       } else {
// here i cant change to the broker broker, what i define above
           broker = PersistenceBrokerFactory.defaultPersistenceBroker();
       }
   }


---------------------------------------------------------------------
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