Class HibernateSessionManager5
- java.lang.Object
-
- com.atlassian.confluence.impl.hibernate.HibernateSessionManager5
-
public class HibernateSessionManager5 extends Object
Provides methods to manage objects in the current HibernateSession
. Methods will throwIllegalStateException
if there is no active session on the executing thread. Replacement for the old Hibernate 2 version of HibernateSessionManager due to Hibernate 2 removal.- Since:
- 7.16.0
-
-
Constructor Summary
Constructors Constructor Description HibernateSessionManager5(org.hibernate.SessionFactory sessionFactory, org.springframework.transaction.PlatformTransactionManager transactionManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <I,O>
Iterable<O>executeThenClearSession(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.<I,O>
Iterable<O>executeThenFlushAndClearSession(Iterable<I> input, int batchSize, int expectedTotal, Function<I,O> task)
Reuses the current transaction, to avoid nested transaction issues.org.springframework.transaction.support.TransactionTemplate
getTransactionTemplate()
boolean
withNewTransaction(Callable<Boolean> callable)
-
-
-
Method Detail
-
executeThenClearSession
public <I,O> Iterable<O> executeThenClearSession(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 providedtask
is executed once perinput
item. The commit and session-clearing is done once perbatchSize
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.
- Type Parameters:
I
- the type of the input itemsO
- the type of the resulting items, which can be Void- Parameters:
input
- the list of items to processtask
- the task to executebatchSize
- a transaction will be committed and the session will be cleared after this many input itemsexpectedTotal
- the total number of items, used for logging. A value of 0 indicates expected total is not known.- Returns:
- the output of the task
- Throws:
IllegalStateException
- if there is no active sessionorg.springframework.dao.DataAccessException
- if there is a problem committing changes to the database
-
executeThenFlushAndClearSession
public <I,O> Iterable<O> executeThenFlushAndClearSession(Iterable<I> input, int batchSize, int expectedTotal, Function<I,O> task)
Reuses the current transaction, to avoid nested transaction issues.- Since:
- 7.0.1
-
getTransactionTemplate
public org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()
-
-