Class SessionFactoryConnectionExecutor

java.lang.Object
io.hypersistence.optimizer.core.event.persistence.SessionFactoryConnectionExecutor
All Implemented Interfaces:
io.hypersistence.optimizer.util.ConnectionExecutor

public class SessionFactoryConnectionExecutor extends Object implements io.hypersistence.optimizer.util.ConnectionExecutor
The 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 Details

    • SessionFactoryConnectionExecutor

      public SessionFactoryConnectionExecutor(org.hibernate.SessionFactory sessionFactory)
      Instantiate the SessionFactoryConnectionExecutor using the provided SessionFactory.
      Parameters:
      sessionFactory - the host application's SessionFactory
  • Method Details

    • execute

      public void execute(io.hypersistence.optimizer.util.ConnectionCallback callback) throws SQLException
      Specified by:
      execute in interface io.hypersistence.optimizer.util.ConnectionExecutor
      Throws:
      SQLException