public class

HibernateSessionManager

extends Object
java.lang.Object
   ↳ com.atlassian.confluence.core.persistence.hibernate.HibernateSessionManager

Class Overview

Provides methods to manage objects in the current Hibernate Session. Methods will throw IllegalStateException if there is no active session on the executing thread.

Summary

Public Constructors
HibernateSessionManager(SessionFactory sessionFactory, PlatformTransactionManager transactionManager)
Public Methods
void evict(Object object)
Removes the object and its dependents from the active session.
<I, O> Iterable<O> executeWithSessionClearing(Iterable<I> input, int batchSize, int expectedTotal, Function<I, O> task)
Executes a bulk database update in a way that prevents excessive memory usage, by committing the transaction and clearing the session periodically.
Session getSession()
Returns the current session.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public HibernateSessionManager (SessionFactory sessionFactory, PlatformTransactionManager transactionManager)

Public Methods

public void evict (Object object)

Removes the object and its dependents from the active session. Any un-flushed changes will be lost.

This method should be used when processing a large number of Hibernate objects in a read-only fashion.
Throws
IllegalStateException if there is no active session
DataAccessException if there is a problem evicting the object
See Also

public Iterable<O> executeWithSessionClearing (Iterable<I> input, int batchSize, int expectedTotal, Function<I, O> task)

Executes a bulk database update in a way that prevents excessive memory usage, by committing the transaction and clearing the session periodically. The provided task is executed once per input item. The commit and session-clearing is done once per batchSize items.

WARNING: the session clearing will discard any unflushed or uncommitted changes made higher in the stack. Batch operations using this method should generally be done in a separate thread or otherwise outside the scope of a request.
Parameters
input the list of items to process
batchSize a transaction will be committed and the session will be cleared after this many input items
expectedTotal the total number of items, used for logging. A value of 0 indicates expected total is not known.
task the task to execute
Returns
  • the output of the task
Throws
IllegalStateException if there is no active session
DataAccessException if there is a problem committing changes to the database

public Session getSession ()

Returns the current session.

Throws
IllegalStateException if there is no active session