If I were to build an app like that, I would use an in-memory database connection pool.
I would then:
The custom datasource would pull a connection from the pool.
2. I would write one class for all database access, and hide model code inside methods of that class. Think of this as a data access facade
For instance:
3. How to open connection: use Java Proxy feature to get a new implementation of the PeopleFacade class, but the one that can open a connection before method, and close one after the method:
Here is code example that does not use models, or actually opens connection, but it gives you a clue for my suggestion:
Simply use code in DatabaseConnectionHandler to open a connection before method execution and close after. The connection itself can be opened directly or sourced from a pool
hope this helps
tx