pdb
pdb copied to clipboard
Usage of DatabaseEnginePool creates complexity to hold entities and prepared statement in memory
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 DatabaseEngine
s 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 DatabaseEngine
s 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 DatabaseEngine
s that exist in the pool, even after the pool is created. This prevents leakage of information from classes using DatabaseEngine
s from the pool.
FYI @francisco-polaco :point_up: