Currently, calling DAOManager.getDAOManager() in a given thread always returns the same DAOManager instance (~ "per-thread singleton"). This was useful when we weren't using dependency injection everywhere, we could just call getDAOManager() from anywhere and be happy.
Now that we use dependency injection, DAOManager.getDAOManager() could always return a new instance; we would acquire it at the beginning of an operation (e.g., when calling FrontController.doRequest), and we would inject it everywhere, so that there shouldn't be more than one DAOManager used in a given thread (and so, no more than one connection to the database), if it is what we want.
Issue #58 describes a similar problem with BgeeProperties.
Also, should we keep storing DAOManagers associated to a given thread in a synchronized Map? This is notably used to allow to kill a connection from another thread (to interrupt a long-running query). But this feature of storing DAOManagers to be potentially interrupted could be implemented by another class, e.g., TaskManager.
But, it also allows to close all DAOManagers when calling DAOManager.closeAll() (useful, e.g, for a servlet shutdown listener). So, maybe we should keep storing all opened DAOManagers.
In GitLab by @fbastian on Oct 7, 2015, 24:07
Currently, calling
DAOManager.getDAOManager()
in a given thread always returns the sameDAOManager
instance (~ "per-thread singleton"). This was useful when we weren't using dependency injection everywhere, we could just callgetDAOManager()
from anywhere and be happy.Now that we use dependency injection,
DAOManager.getDAOManager()
could always return a new instance; we would acquire it at the beginning of an operation (e.g., when callingFrontController.doRequest
), and we would inject it everywhere, so that there shouldn't be more than oneDAOManager
used in a given thread (and so, no more than one connection to the database), if it is what we want.Issue #58 describes a similar problem with
BgeeProperties
.Also, should we keep storing
DAOManager
s associated to a given thread in a synchronized Map? This is notably used to allow to kill a connection from another thread (to interrupt a long-running query). But this feature of storingDAOManager
s to be potentially interrupted could be implemented by another class, e.g.,TaskManager
.But, it also allows to close all
DAOManager
s when callingDAOManager.closeAll()
(useful, e.g, for a servlet shutdown listener). So, maybe we should keep storing all openedDAOManager
s.