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 Armin Waibel <ar...@code-au-lait.de> on 2003/04/22 21:01:31 UTC
Re: Object not persists to database,TestHelper.DEF_JCD_ALIAS
Hi Emmanuel,
> I have businessObjects who are looking for datas in different
databases.
> I would like to know how I can access to different database with OJB
Define different jdbc-connection-descriptor in the repository. Use a
unique
jcdAlias name per descriptor (e.g 'db1' and 'db2').
Using PB-api:
PersistenceBroker broker_db1 =
PersistenceBrokerFactory.createPersistenceBroker("db1");
PersistenceBroker broker_db2 =
PersistenceBrokerFactory.createPersistenceBroker("db2");
Using ODMG-api:
A 'Implementation' instance (OJB.class) could only handle
one open database. To switch the database you have to close
the current one and open the new one.
Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();
db.open("db1");
...
Or you could use different Implementation instances,
one for each database.
HTH
regards,
Armin
----- Original Message -----
From: "Emmanuel Dupont" <em...@jwaretechnologies.com>
To: "'OJB Users List'" <oj...@db.apache.org>; "'Armin Waibel'"
<ar...@code-au-lait.de>
Sent: Tuesday, April 22, 2003 7:57 PM
Subject: RE : Object not persists to database,TestHelper.DEF_JCD_ALIAS
Hi Armin, All
Any help would be very appreciated!
Here is in fact my problem :
I have businessObjects who are looking for datas in different databases.
I would like to know how I can access to different database with OJB. I
am
wondering if I have to create a new Ojb instance and a new connection
for
each BusinessObject?
I have done a connectionFactory in the MotherClass of all my
businessObjects. I wanted at the beginning that factory to return the
right
instance connection for all my businessObjects.
I call the factory with the jcd alias parameter. If a connection to the
database exist, the factory return it (case of the same BusinessObject
is
called by different client), if not, the factory launch the database
connection, return it and save it in its connection list.
But it doesn't work because of the : TestHelper.DEF_JCD_ALIAS
I don't know if I am right or wrong because I didn't really understand
if
one OJB instance is able to manage different simultaneous database
connection....
My factory code:
The line: databaseName = TestHelper.DEF_JCD_ALIAS; All time send the
first
databaseName used. No new connection is created !!
*/
public Implementation getImplementation(
String jcdAlias,
String userName,
String userPassword) {
String databaseName;
PersistenceBroker broker;
Implementation Impl = null;
PBKey key = new PBKey(jcdAlias,userName,userPassword);
PersistenceBrokerFactory.setDefaultKey(key);
broker =
PersistenceBrokerFactory.createPersistenceBroker(
jcdAlias,
userName,
userPassword);
databaseName = TestHelper.DEF_JCD_ALIAS;
// Catch the Implementation instance relies on
// the jcd-alias descriptor
Impl = (Implementation) HashTabImpl.get(jcdAlias);
if (Impl == null) {
Impl = OJB.getJwtInstance();
db = Impl.newJwtDatabase();
HashTabImpl.put(jcdAlias, Impl);
// open database
try {
db.open(databaseName,
Database.OPEN_READ_WRITE);
} catch (DatabaseOpenException e) {
e.printStackTrace();
} catch (DatabaseNotFoundException e) {
e.printStackTrace();
}
}
return Impl;
}
Is there a solution ???
Thanks a lot.
-----Message d'origine-----
De : Armin Waibel [mailto:armin.waibel@code-au-lait.de]
Envoyé : lundi 14 avril 2003 20:52
À : OJB Users List; Emmanuel Dupont
Objet : Re: Object not persists to database
Hi,
>do you use container managed transaction in your bean?
>I assume you do.
>Do you use DataSources from your
>appServer to connect to your database?
Can you explain to me how you do that, I have to do that but I don't
know
where should I start?
#####
That's part of your appServer documentation. So I don't now ... ;-)
How Can I connect OJB to the CMT of my Session Bean (via datasource ?) ?
#####
There is an example jdbc-connection-descriptor using DataSource in
repository_database.xml
>So open database in ejbCreate() is OK, but never open database
>in your bean code again.
Does that mean that it is not possible to open a second database from
the
same EJB Session Façade?
######
Using database.open(....) - no, but it should be possible to deploy your
bean with different names and using 'env-entry' attribute in your
deployment
descriptor.
<env-entry>
<env-entry-name>ojb.jcdAlias</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>myDB1</env-entry-value>
</env-entry>
regards,
Armin
What can you do if your Session Façade have to connect different
database
during the runtime ?
Tx !
Emmanuel.
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
RE : Object not persists to database,TestHelper.DEF_JCD_ALIAS
Posted by Emmanuel Dupont <em...@jwaretechnologies.com>.
[Snip]
>Or you could use different Implementation instances,
>one for each database.
Thanks again Armin,
In fact it is exactly what I have done. I think I have resolve my problem.
What this line is for?
"databaseName = TestHelper.DEF_JCD_ALIAS;"
Because even if I have different instances of my OJB implementation, this
line returns all time the first database connection.
I deleted it and replaced the database open call with the jcdAliasName. And
it works.
Am I right, or will I have troubles later?
//databaseName = TestHelper.DEF_JCD_ALIAS;
//db.open(databaseName, Database.OPEN_READ_WRITE);
db.open(jcdAlias, Database.OPEN_READ_WRITE);
----- Original Message -----
From: "Emmanuel Dupont" <em...@jwaretechnologies.com>
To: "'OJB Users List'" <oj...@db.apache.org>; "'Armin Waibel'"
<ar...@code-au-lait.de>
Sent: Tuesday, April 22, 2003 7:57 PM
Subject: RE : Object not persists to database,TestHelper.DEF_JCD_ALIAS
Hi Armin, All
Any help would be very appreciated!
Here is in fact my problem :
I have businessObjects who are looking for datas in different databases.
I would like to know how I can access to different database with OJB. I
am
wondering if I have to create a new Ojb instance and a new connection
for
each BusinessObject?
I have done a connectionFactory in the MotherClass of all my
businessObjects. I wanted at the beginning that factory to return the
right
instance connection for all my businessObjects.
I call the factory with the jcd alias parameter. If a connection to the
database exist, the factory return it (case of the same BusinessObject
is
called by different client), if not, the factory launch the database
connection, return it and save it in its connection list.
But it doesn't work because of the : TestHelper.DEF_JCD_ALIAS
I don't know if I am right or wrong because I didn't really understand
if
one OJB instance is able to manage different simultaneous database
connection....
My factory code:
The line: databaseName = TestHelper.DEF_JCD_ALIAS; All time send the
first
databaseName used. No new connection is created !!
*/
public Implementation getImplementation(
String jcdAlias,
String userName,
String userPassword) {
String databaseName;
PersistenceBroker broker;
Implementation Impl = null;
PBKey key = new PBKey(jcdAlias,userName,userPassword);
PersistenceBrokerFactory.setDefaultKey(key);
broker =
PersistenceBrokerFactory.createPersistenceBroker(
jcdAlias,
userName,
userPassword);
databaseName = TestHelper.DEF_JCD_ALIAS;
// Catch the Implementation instance relies on
// the jcd-alias descriptor
Impl = (Implementation) HashTabImpl.get(jcdAlias);
if (Impl == null) {
Impl = OJB.getJwtInstance();
db = Impl.newJwtDatabase();
HashTabImpl.put(jcdAlias, Impl);
// open database
try {
db.open(databaseName,
Database.OPEN_READ_WRITE);
} catch (DatabaseOpenException e) {
e.printStackTrace();
} catch (DatabaseNotFoundException e) {
e.printStackTrace();
}
}
return Impl;
}
Is there a solution ???
Thanks a lot.
-----Message d'origine-----
De : Armin Waibel [mailto:armin.waibel@code-au-lait.de]
Envoyé : lundi 14 avril 2003 20:52
À : OJB Users List; Emmanuel Dupont
Objet : Re: Object not persists to database
Hi,
>do you use container managed transaction in your bean?
>I assume you do.
>Do you use DataSources from your
>appServer to connect to your database?
Can you explain to me how you do that, I have to do that but I don't
know
where should I start?
#####
That's part of your appServer documentation. So I don't now ... ;-)
How Can I connect OJB to the CMT of my Session Bean (via datasource ?) ?
#####
There is an example jdbc-connection-descriptor using DataSource in
repository_database.xml
>So open database in ejbCreate() is OK, but never open database
>in your bean code again.
Does that mean that it is not possible to open a second database from
the
same EJB Session Façade?
######
Using database.open(....) - no, but it should be possible to deploy your
bean with different names and using 'env-entry' attribute in your
deployment
descriptor.
<env-entry>
<env-entry-name>ojb.jcdAlias</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>myDB1</env-entry-value>
</env-entry>
regards,
Armin
What can you do if your Session Façade have to connect different
database
during the runtime ?
Tx !
Emmanuel.
---------------------------------------------------------------------
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