Class AsyncCommitIntegrator

java.lang.Object
org.keycloak.connections.jpa.AsyncCommitIntegrator
All Implemented Interfaces:
org.hibernate.event.spi.PreDeleteEventListener, org.hibernate.event.spi.PreInsertEventListener, org.hibernate.event.spi.PreUpdateEventListener

public class AsyncCommitIntegrator extends Object implements org.hibernate.event.spi.PreInsertEventListener, org.hibernate.event.spi.PreUpdateEventListener, org.hibernate.event.spi.PreDeleteEventListener
Hibernate event listener that enables asynchronous commit for PostgreSQL transactions that only modify entities implementing AsynchronousCommitAllowed.

On PostgreSQL, issues SET LOCAL synchronous_commit TO OFF before commit when all modified entities in the transaction allow it. This skips the WAL fsync wait, improving throughput for ephemeral data. The database remains crash-consistent; only the last few milliseconds of such transactions may be lost on a crash.

On non-PostgreSQL databases, registerListeners(EntityManagerFactory) is a no-op.

Author:
Alexander Schwartz
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    onPreDelete(org.hibernate.event.spi.PreDeleteEvent event)
     
    boolean
    onPreInsert(org.hibernate.event.spi.PreInsertEvent event)
     
    boolean
    onPreUpdate(org.hibernate.event.spi.PreUpdateEvent event)
     
    static void
    registerListeners(jakarta.persistence.EntityManagerFactory emf)
    Registers asynchronous commit listeners on the given EntityManagerFactory if the underlying database is PostgreSQL.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AsyncCommitIntegrator

      public AsyncCommitIntegrator()
  • Method Details

    • registerListeners

      public static void registerListeners(jakarta.persistence.EntityManagerFactory emf)
      Registers asynchronous commit listeners on the given EntityManagerFactory if the underlying database is PostgreSQL. No-op for other databases.
    • onPreInsert

      public boolean onPreInsert(org.hibernate.event.spi.PreInsertEvent event)
      Specified by:
      onPreInsert in interface org.hibernate.event.spi.PreInsertEventListener
    • onPreUpdate

      public boolean onPreUpdate(org.hibernate.event.spi.PreUpdateEvent event)
      Specified by:
      onPreUpdate in interface org.hibernate.event.spi.PreUpdateEventListener
    • onPreDelete

      public boolean onPreDelete(org.hibernate.event.spi.PreDeleteEvent event)
      Specified by:
      onPreDelete in interface org.hibernate.event.spi.PreDeleteEventListener