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 Marcel Baumann <ma...@bbv.ch> on 2003/08/21 21:32:56 UTC

ODMG behavior with multiple databases and multiple clients

Hello everybody,

We are using the ODMG layer with OJB RC4 to connect to 2 DB2 databases and 1
Oracle database. We found out that each time we open a database through ODMG
the previous one is closed. This behavior is coded in the OJB class. It
seems that only the current default database can be open at any time.
Additionally the transaction interface does not allow to define the database
on which it will act on.

Examples from commercial ODMG products show that it should be possible to
specify the database on which a transaction should work on and have multiple
databases open. Currently we redefined the OJB class to support the creation
of a new transaction with a Parameter indicating the database on which to
execute.

        Configurator configurator =
PersistenceBrokerFactory.getConfigurator();

        ...

        // This method is an extension of the method defined in
org.apache.ojb.odmg.OJB

        public Transaction newTransaction(Database database) {

                TransactionImpl tx = new
TransactionImpl((DatabaseImpl)database);

                try {

                        configurator.configure(tx);

                } catch (ConfiguratorException e) {

            ...

        }

The multiple databases are managed as follow.


// workaround of the problem that Database.open calls
OJB.registerOpenDatabase(DatabaseImpl) which always close the previously
opened database.

        public synchronized Database getOracleDatabase() throws
ODMGException {

        if (oracleDatabase == null) {

                oracleDatabase = odmg.newDatabase();

                oracleDatabase.open(ORACLE_DATABASE_REPOSITORY,
Database.OPEN_READ_WRITE);

         } else if (!(DatabaseImpl)oracleDatabase).isOpen()) {

                oracleDatabase.open(ORACLE_DATABASE_REPOSITORY,
Database.OPEN_READ_WRITE);

       }

        return oracleDatabase;

    }

The above solution cannot work in an environment where multiple clients
access the server and get various databases in parallel for obvious reasons.

What is the correct way to access simultaneously multiple database through
the ODMG layer using OJB RC4?

Thanks for any pointer to a FAQ or an answer. We did not found an example in
the OJB FAQ or the Mail archives. Examples for commercial ODMG products show
that multiple databases can be opened At the same time and that a
transaction can be created with a database parameter.

What are we doing wrong or have missed?

Marcel Baumann




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