Database Approach
Proof-of-Concept with the goal to provide a Multi Tenant Architecture using Hibernate.
- Create a Custom Connection Pool for each tenant and make them available to hibernate;
- Users log in the application and depending of their Organization the correct tenant will be loaded and select a suitable connection.
- Create an operation (ex. some object query) to demonstrate the diferent results since there is a different database/schema for each user.
- Hibernate 4.3.10.FINAL
- Apache DBCP 1.4
- JSF 2.1.21
- Servlet 2.5
- Oracle (Check if you have Oracle Driver in Maven repo, otherwise it will be necessary to intall)
-
Create some Oracle databases (different hosts) with some schemas. Be aware to select one of them to be the MAIN database/schema.
-
Clone this project to your local git.
-
Open the file /scripts/database.sql, copy and run the commands marked with MAIN for the MAIN database/schema.
-
Still in the file /scripts/database.sql, for each tenant database/schema copy and run the commands marked with TENANT.
-
Edit the file /src/main/resources/multi-tenant.properties providing the correct information for each tenant and main to be created (database/schema data).
-
Open a terminal and follow one of these approaches:
a. Run "mvn clean install" to generate the WAR package to be deployed and copy to the application server;
b. If you have a tomcat installation, change the tomcat settings for your configuration in /pom.xml and run "clean install tomcat:deploy" (Tomcat must be started);
-
Access, http://app-server-host:app-server-port/multi-tenant-db.
-
Try out with multiple users, organizations and tenants.
See javadocs for further information.