Class SessionFactoryConnectionExecutor
- All Implemented Interfaces:
io.hypersistence.optimizer.util.ConnectionExecutor
SessionFactoryConnectionExecutor runs the event persistence JDBC work against a
Connection borrowed from the host application's Hibernate SessionFactory.
Because the Optimizer is always built on top of a SessionFactory (either a native one or
one unwrapped from a JPA EntityManagerFactory), reusing it means the events are stored
with the very same database credentials and connection pool as the application, and no separate
DataSource or JDBC URL needs to be configured.
The work is executed through SharedSessionContract.doWork(Work), which hands over a raw JDBC
Connection. No entity is ever persisted through the Session. However, the runtime
scanner that decorates the application SessionFactory still tracks the borrowed connection,
so the work runs within the InternalWorkScope, which drops the events it triggers. Otherwise,
every flush would report a StatementlessConnectionEvent about the Optimizer itself, and
persisting that event would trigger a new one, over and over.
- Since:
- 2.14.0
- Author:
- Vlad Mihalcea
-
Constructor Summary
ConstructorsConstructorDescriptionSessionFactoryConnectionExecutor(org.hibernate.SessionFactory sessionFactory) Instantiate theSessionFactoryConnectionExecutorusing the providedSessionFactory. -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(io.hypersistence.optimizer.util.ConnectionCallback callback)
-
Constructor Details
-
SessionFactoryConnectionExecutor
public SessionFactoryConnectionExecutor(org.hibernate.SessionFactory sessionFactory) Instantiate theSessionFactoryConnectionExecutorusing the providedSessionFactory.- Parameters:
sessionFactory- the host application'sSessionFactory
-
-
Method Details
-
execute
public void execute(io.hypersistence.optimizer.util.ConnectionCallback callback) throws SQLException - Specified by:
executein interfaceio.hypersistence.optimizer.util.ConnectionExecutor- Throws:
SQLException
-