|
Re: [Texo] Using different EntityManager [message #1015486 is a reply to message #1015368] |
Thu, 28 February 2013 17:34 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Bastian,
That would not be too difficult and quite possible (needs some coding, but nothing really dramatic), for my
understanding (and also on the issue you entered previously). Do you use/extend the standard JSONRestWebServiceServlet?
Or did you create your own servlet implementation.
gr. Martin
On 02/28/2013 12:24 PM, Bastian Wagenfeld wrote:
> Hi Martin,
>
> another question crossed my mind: is it possible to use different EntityManager in one servlet? For example, a user
> starts a request with http://localhost:8080/texo/oracle and accesses an Oracle database, or a request to
> http://localhost:8080/texo/mysql to get data of a MySQL database. Is that possible/recommendable?
>
> Regards
> Bastian
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
|
Re: [Texo] Using different EntityManager [message #1015550 is a reply to message #1015534] |
Fri, 01 March 2013 08:48 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Bastian,
Yes, an approach:
1) create your own EntityManagerProvider which extends the current one from Texo but also has a ThreadLocal<String>
database (with a public static/getter)
2) set this EntityManagerProvider using EntityManagerProvider.setInstance(...) when the web context initializes
3) implement a filter which sets the database name in the ThreadLocal in your EntityManagerProvider (and clears it after
the request)
4) in your EntityManagerProvider.createEntityManager use the correct EMF on the basis of the threadlocal
There are also other ways by extending the JSONRestWebServiceServlet or by replacin the WebServiceHandler etc. But the
above is also a way to do this.
Btw, I still don't understand how/why an entitymanager is re-used across requests, it really should not.
gr. Martin
On 03/01/2013 08:25 AM, Bastian Wagenfeld wrote:
> Hi Martin,
>
> I'm using JSONRestWebServiceServlet. My approach now would be to add a filter that finds request parameters and then
> switches the underlying database. Could I then just change the PersistenceOptions?
>
> Regards
> Bastian
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
|
Re: [Texo] Using different EntityManager [message #1015608 is a reply to message #1015606] |
Fri, 01 March 2013 11:14 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Bastian,
I don't propose to re-use an entitymanager there seems to be a bug that you notice currently that it is being re-used.
In the EntityManagerProvider you can create new entity managers from different entitymanagerfactories, different
entitymanagerfactories are needed to connect to different databases.
gr. Martin
On 03/01/2013 12:08 PM, Bastian Wagenfeld wrote:
> Hi Martin,
>
> my intention was not to re-use an EntityManager. I want to use two (or more) different databases. Users with parameter
> "mysql" should get their data from an MySQL database and so on. I don't want to explicitly use one EntityManager, but it
> would be nice to switch the database for each request, if this is needed.
>
> Best regards
> Bastian
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
|
Powered by
FUDForum. Page generated in 0.02436 seconds