So, we are building an application that requires multi-tenancy support. There is one application that has to support multiple clients. Basically, we have the data hosted in 2 huge Oracle databases. For security reasons (and also to improve scalability), each client's data is stored in it's own schema within the Oracle database. When the user logs in to the application the LDAP entry for the user gives us the client code that the user belongs to. The JNDI is configured to contain the data source for each client, and we look up the data source when we create the EntittyManagerFactory
Also, we have 2 parts of the application, one is the front end and business logic layer that is hosted in
JBoss. In this case, the JBoss acts as the containerThe second is the grid computation framework that is spring based and Spring acts as the container.
Traditionally, what we have been doing is we have our own Service Locator that acts as a factory for the EntityManager, and is also responsible for setting up transactions. Our Services, access the Service Locator to get the Entity Manager; the service locator manages a map of Entity Manager Factories, and when a new client is encountered, it looks up the data source from the JNDI and create the Entity Manager Factory
As you can imagine, it's a hell a lot of code, and also we have all these Services that are dependent on this Service Locator. I wanted to change this design to use EJBs for our services, and have the container manage the Entity Manager and the Transactions. This will significantly reduce our code base and make the design much cleaner
But, the problem I keep running into is this multi-tenancy problem. If I have my service like this
The container is going to inject the Entity Manager into my service. THis is great if I had only one database to access, but I don't. The Entity Manager injected into this service has to be based on the client code. I want to customize that injection code to create my own Entity Manager instead of using the container's default implementation. Is there a way to do that? Is there a way I can do this in Spring as well as JBoss.