Is there a way to change which database is used based on user?

As the subject says - I’m wondering if there’s a way to change which database is being used based on which user is logged in.

Our package is a full-office management package for a niche medical industry, and we have to comply with HIPAA (American medical info privacy regulations). The way we handle this now is easy - just separate installations of our package. We self-host (via RDP/terminal server) many of our clients; some have their own on-site servers. We’re working on converting to CUBA/Java, and plan to self-host all our clients on the new version.

We’ll be using Postgres, and it seems the easiest way to ensure company-A can never see company-B’s data is by setting up a way such that when a company-A-user logs in, company-A’s Postgres DB is accessed, and vice versa with company-B’s users. Obviously another way would be to just have numerous separate deployments all pointing to their own PG DB’s via context.xml. Having it happen automatically by user would be more elegant; is it possible?

Hi,
Such mechanism is called a “database per tenant”.
Please take a look to this topic:

So, basically, it’s coming, but as a single DB solution?

There is an example of the DB-per-tenant application posted in the thread. You can try to utilize it in your project.