Without changing code and redeploying my application, I need to be able to switch persistence units in some of my EJBs based on client connected to system.
It is similar to multitenancy, but whereas there a single DB is divided into equal shares and shared between multiple tenants, here a single tenant wants multiple DBs appearing as a single one.
During runtime based on the client connected to the EJB, the specific database should be selected.
Currently I achieve this using JDBC connections and just changing the database connection details based on client connected.
The database connection details are stored in the main system database and retrieved when the client connects.
This allows the system to grow with ease as new client databases can be created on the fly and simply linked to the client
in the database.
Ideally I would like to dynamically add new persistence units to the system (persistence.xml) and then in my database
link these persistence units to a given client. When the client connects, the system loads the required persistence unit.