You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Diego Cattelan <ca...@gmail.com> on 2014/04/04 15:17:46 UTC

Multitenants app

Hi, I'm using TomEE 1.6 to run a simple multitenat web application.

I have a global users database and each tenant has his own private database.
After a user logins succesfully, I manually instantiate the private 
tenant's  EntityManagerFactory
with info for connecting to the right database.

The application is working withouth problems. When I need an 
EntityManager I manually request it to
the tenant's EntityManagerFactory, etc.

Now, I want to use container managed transaction and injection.

Requirements:
- Tenants are created at runtime withouth container restart

It's my first J2EE project so I need some hints to go in the right 
direction.

How can I achieve this ? Thank you.

Re: Multitenants app

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

you can do it while not used using openejb DataSourceFactory. You even
don't need to put them in jndi or whatever if you use dynamic
datasource. Just store them in a map in the router.
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-04-05 14:02 GMT+02:00 Diego Cattelan <ca...@gmail.com>:
> Yes, datasource routing is what I need.
> I try with DataSources declared in /WEB-INF/resources.xml and it works.
>
> But, can I programmatically define a DataSource ? I don't understand how. Is
> it possible (at runtime, not in tests)?
>
>
>
> Il 04/04/2014 15:28, Romain Manni-Bucau ha scritto:
>
>> Hi
>>
>> does
>> http://tomee.apache.org/examples-trunk/dynamic-datasource-routing/README.html
>> help? basically give you a hook to select the datasource
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>>
>> 2014-04-04 15:17 GMT+02:00 Diego Cattelan <ca...@gmail.com>:
>>>
>>> Hi, I'm using TomEE 1.6 to run a simple multitenat web application.
>>>
>>> I have a global users database and each tenant has his own private
>>> database.
>>> After a user logins succesfully, I manually instantiate the private
>>> tenant's
>>> EntityManagerFactory
>>> with info for connecting to the right database.
>>>
>>> The application is working withouth problems. When I need an
>>> EntityManager I
>>> manually request it to
>>> the tenant's EntityManagerFactory, etc.
>>>
>>> Now, I want to use container managed transaction and injection.
>>>
>>> Requirements:
>>> - Tenants are created at runtime withouth container restart
>>>
>>> It's my first J2EE project so I need some hints to go in the right
>>> direction.
>>>
>>> How can I achieve this ? Thank you.
>
>

Re: Multitenants app

Posted by Diego Cattelan <ca...@gmail.com>.
Yes, datasource routing is what I need.
I try with DataSources declared in /WEB-INF/resources.xml and it works.

But, can I programmatically define a DataSource ? I don't understand 
how. Is it possible (at runtime, not in tests)?



Il 04/04/2014 15:28, Romain Manni-Bucau ha scritto:
> Hi
>
> does http://tomee.apache.org/examples-trunk/dynamic-datasource-routing/README.html
> help? basically give you a hook to select the datasource
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014-04-04 15:17 GMT+02:00 Diego Cattelan <ca...@gmail.com>:
>> Hi, I'm using TomEE 1.6 to run a simple multitenat web application.
>>
>> I have a global users database and each tenant has his own private database.
>> After a user logins succesfully, I manually instantiate the private tenant's
>> EntityManagerFactory
>> with info for connecting to the right database.
>>
>> The application is working withouth problems. When I need an EntityManager I
>> manually request it to
>> the tenant's EntityManagerFactory, etc.
>>
>> Now, I want to use container managed transaction and injection.
>>
>> Requirements:
>> - Tenants are created at runtime withouth container restart
>>
>> It's my first J2EE project so I need some hints to go in the right
>> direction.
>>
>> How can I achieve this ? Thank you.


Re: Multitenants app

Posted by Diego Cattelan <ca...@gmail.com>.
yes,  it works! 
thank you

On 04 aprile 2014 15:28:57 CEST, Romain Manni-Bucau <rm...@gmail.com> wrote:
>Hi
>
>does
>http://tomee.apache.org/examples-trunk/dynamic-datasource-routing/README.html
>help? basically give you a hook to select the datasource
>Romain Manni-Bucau
>Twitter: @rmannibucau
>Blog: http://rmannibucau.wordpress.com/
>LinkedIn: http://fr.linkedin.com/in/rmannibucau
>Github: https://github.com/rmannibucau
>
>
>
>2014-04-04 15:17 GMT+02:00 Diego Cattelan <ca...@gmail.com>:
>> Hi, I'm using TomEE 1.6 to run a simple multitenat web application.
>>
>> I have a global users database and each tenant has his own private
>database.
>> After a user logins succesfully, I manually instantiate the private
>tenant's
>> EntityManagerFactory
>> with info for connecting to the right database.
>>
>> The application is working withouth problems. When I need an
>EntityManager I
>> manually request it to
>> the tenant's EntityManagerFactory, etc.
>>
>> Now, I want to use container managed transaction and injection.
>>
>> Requirements:
>> - Tenants are created at runtime withouth container restart
>>
>> It's my first J2EE project so I need some hints to go in the right
>> direction.
>>
>> How can I achieve this ? Thank you.

-- Inviato dal mio cellulare Android con K-9 Mail.

Re: Multitenants app

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

does http://tomee.apache.org/examples-trunk/dynamic-datasource-routing/README.html
help? basically give you a hook to select the datasource
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-04-04 15:17 GMT+02:00 Diego Cattelan <ca...@gmail.com>:
> Hi, I'm using TomEE 1.6 to run a simple multitenat web application.
>
> I have a global users database and each tenant has his own private database.
> After a user logins succesfully, I manually instantiate the private tenant's
> EntityManagerFactory
> with info for connecting to the right database.
>
> The application is working withouth problems. When I need an EntityManager I
> manually request it to
> the tenant's EntityManagerFactory, etc.
>
> Now, I want to use container managed transaction and injection.
>
> Requirements:
> - Tenants are created at runtime withouth container restart
>
> It's my first J2EE project so I need some hints to go in the right
> direction.
>
> How can I achieve this ? Thank you.