Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Texo] Using different EntityManager
[Texo] Using different EntityManager [message #1015368] Thu, 28 February 2013 11:24 Go to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
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
Re: [Texo] Using different EntityManager [message #1015486 is a reply to message #1015368] Thu, 28 February 2013 17:34 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
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 #1015534 is a reply to message #1015486] Fri, 01 March 2013 07:25 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
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
Re: [Texo] Using different EntityManager [message #1015550 is a reply to message #1015534] Fri, 01 March 2013 08:48 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
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 #1015606 is a reply to message #1015550] Fri, 01 March 2013 11:08 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
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
Re: [Texo] Using different EntityManager [message #1015608 is a reply to message #1015606] Fri, 01 March 2013 11:14 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
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
Re: [Texo] Using different EntityManager [message #1015610 is a reply to message #1015608] Fri, 01 March 2013 11:28 Go to previous message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi Martin,

I think we're on the same page, now Smile Thank you for your help. I'll try a little on it and see, if using different databases is a good idea, at all. But now, I think, I know how to achieve it.

Thanks
Bastian
Previous Topic:[Texo] HTML web interface projects?
Next Topic:[EMFStore] Updating the model on the server side based on clients modifications
Goto Forum:
  


Current Time: Fri Apr 19 10:21:58 GMT 2024

Powered by FUDForum. Page generated in 0.02436 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top