pdb icon indicating copy to clipboard operation
pdb copied to clipboard

Usage of DatabaseEnginePool creates complexity to hold entities and prepared statement in memory

Open artpdr opened this issue 2 years ago • 1 comments

DatabaseEnginePool contains a pool of DatabaseEngine. However, each of these Database Engines may have different entities and prepared statements in memory if we don't propagate the entities and prepared statements to all DatabaseEngines in the pool.

To deal with this, every time that I do a DatabaseEnginePool#borrow I need to do a DatabaseEngine#loadEntity if I want to persist an entity. Otherwise, doing a DatabaseEngine#persist will throw an exception if the entity on that DatabaseEngine wasn't loaded yet. In relation to the prepared statements, every time I do a DatabaseEnginePool#borrow to do an operation using a prepared statement (e.g. DatabaseEngine#executePSUpdate), I need to perform a check to see if a prepared statement exists or create it (DatabaseEngine#preparedStatementExists and DatabaseEngine#createPreparedStatement).

Can we have a way to set the entities and prepared statements globally inside the DatabaseEnginePool and use that on every DatabaseEngine from the pool? At the moment, we can use a Function on the DatabaseEnginePool#getConnectionPool to run some action on the DatabaseEngines returned from the pool where we could register the prepared statements and entities but this needs to be done when we create the DatabaseEnginePool and not after. Hence, it would require information to be passed outside of the scope where the pool will be necessary. IMO we should be able to update the context associated with the DatabaseEngines that exist in the pool, even after the pool is created. This prevents leakage of information from classes using DatabaseEngines from the pool.

artpdr avatar Jan 25 '22 20:01 artpdr

FYI @francisco-polaco :point_up:

artpdr avatar Jan 25 '22 20:01 artpdr