How to Change Database connection at Runtime?
[Logo]
ICEsoft.org Forums: ICEfaces, ICEmobile, ICEpdf
[Search] Search   [Recent Topics] Recent Topics   [Groups] Home Page | www.icefaces.org  [Register] Register  [Login] Login 
How to Change Database connection at Runtime?  XML
Forum Index -> JBoss Seam Integration
Author Message
yulybaseball

Joined: 26/03/2010 00:00:00
Messages: 3
Offline


Hi there:

First of all: I am so sorry about my English. I am from Latin America.

I am a rookie in Seam.

At this moment, I am making a web site using Seam 1.2. My site uses a database (in MySQL Server) named ALregclients. That DB has only one table: trazasfallos. I am developing my site in Eclipse. I can change the connection to the database from the context.xml file, and it works fine... The problem comes when I deploy the site. In this case, the site will be hosted in a PC, and the MySQL server will be running in another PC. So, to make the site can run, I have to change the connection string in the context.xml and compile the project. It generates a compiled class named trazasfallos.class, and that is the file I have to overwrite in the folder I put the deployment of the site. Changing only the context.xml and overwriting it in the deployment folder, doesn't work!! Always I have to recompiling the entire site. The point is: how to change the connection string without recompiling the whole project (site)? How to connect to any MySQL server with just a change of a .xml file (or something like that)?

Is it possible to change the connection at runtime? If it is possible, how to do it???
judy.guglielmin

Joined: 20/02/2007 00:00:00
Messages: 1196
Offline


It sounds like you are using one datasource for deveopment and another for production. Why would you just not define both datasources in your project (how to do this would depend on which application server you would use), then define 2 different entity-manager factorys. (there are quite a few examples around for this, but basically you give both datasources different names and then the factories for entity-managers would tie into this and your EntityManager names would also be different).
With both being defined, you could then make which one you uses dependent on which mode you are using --development vs production.
OR

There are options in the ant scripts that seam-gen produces, so you could define a different set of xml files for development vs production here as well (then build based on the different targets).
yulybaseball

Joined: 26/03/2010 00:00:00
Messages: 3
Offline


No judy, I think you didn't understand...

I am using only one datasource. Look, the real problem is the next one:

I developed the application, it only has one datasource. The specifications for the connection to the database is in the context.xml file. Now, I have to give the application to other person. That person should have the posibility to change the connection to the database by only changing some text file (a .xml or something like that). In the time I am making the site I don't know what are the IPs where it is possible the MySQL server will be, so, I am planning only one connection in the context.xml file (for localhost only), but it should be possible for the final user to change the connection by specifying a different IP number. Do you understand now? I am sorry if my English is not good, I am from Cuba. Maybe I did not explain very well, but the problem is that the application should be use by other people, so, they should have the possibility to change the connection without my concern.

Any idea about that?
judy.guglielmin

Joined: 20/02/2007 00:00:00
Messages: 1196
Offline


You are correct, I didn't understand--I thought you knew what their JDBC connection values were ahead of time.

Try this posting on JDBC and seam....it's about defining your JDBC connection with Seam.
yulybaseball

Joined: 26/03/2010 00:00:00
Messages: 3
Offline


Thank you very much, judy. I'll try the post...
M.Aaron

Joined: 17/06/2010 06:36:15
Messages: 6
Offline


Hi there:

First of all: I am so sorry about my English. I am from Latin America.

I am a rookie in Seam.

At this moment, I am making a web site using Seam 1.2. My site uses a database (in MySQL Server) named ALregclients. That DB has only one table: trazasfallos. I am developing my site in Eclipse. I can change the connection to the database from the context.xml file, and it works fine... The problem comes when I deploy the site. In this case, the site will be hosted in a PC, and the MySQL server will be running in another PC. So, to make the site can run, I have to change the connection string in the context.xml and compile the project. It generates a compiled class named trazasfallos.class, and that is the file I have to overwrite in the folder I put the deployment of the site. Changing only the context.xml and overwriting it in the deployment folder, doesn't work!! Always I have to recompiling the entire site. The point is: how to change the connection string without recompiling the whole project (site)? How to connect to any MySQL server with just a change of a .xml file (or something like that)?

Is it possible to change the connection at runtime? If it is possible, how to do it???

Real time chicago Real Estate listings
judy.guglielmin

Joined: 20/02/2007 00:00:00
Messages: 1196
Offline


If you have a choice, you would be MUCH better off with a more recent version of Seam. FOr example with Seam-2.x, you can use ICEfaces and Seam in a war deployment (makes configuration simpler in case you want to add in other frameworks). Also, more functionality of Seam is supported in the later versions of Seam and ICEfaces (seam-pdf).

You can look at seam-comp-showcase (latest is for 1.8.x and is available from our downloads page) that shows Spanish, German and English support.

 
Forum Index -> JBoss Seam Integration
Go to:   
Powered by JForum 2.1.7ice © JForum Team