public class HibernateSessionManager5 extends Object
Session
. Methods will
throw IllegalStateException
if there is no active session on the executing thread.
Replacement for HibernateSessionManager
due to Hibernate 2 removal.Constructor and Description |
---|
HibernateSessionManager5(org.hibernate.SessionFactory sessionFactory,
org.springframework.transaction.PlatformTransactionManager transactionManager) |
Modifier and Type | Method and 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.
|
int |
executeThenClearSessionWithoutCommitOrFlush(int batchSize,
int expectedTotal,
Function<Integer,Integer> taskExecutor)
Execute tasks in batches and clear session after every batch, re-using the existing transaction rather than nesting transactions.
|
<I,O> Iterable<O> |
executeThenClearSessionWithoutCommitOrFlush(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 clearing the session (but NOT committing or flushing) 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) |
public HibernateSessionManager5(org.hibernate.SessionFactory sessionFactory, org.springframework.transaction.PlatformTransactionManager transactionManager)
public <I,O> Iterable<O> executeThenClearSession(Iterable<I> input, int batchSize, int expectedTotal, Function<I,O> task)
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.
I
- the type of the input itemsO
- the type of the resulting items, which can be Voidinput
- 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.IllegalStateException
- if there is no active sessionorg.springframework.dao.DataAccessException
- if there is a problem committing changes to the databasepublic <I,O> Iterable<O> executeThenFlushAndClearSession(Iterable<I> input, int batchSize, int expectedTotal, Function<I,O> task)
public <I,O> Iterable<O> executeThenClearSessionWithoutCommitOrFlush(Iterable<I> input, int batchSize, int expectedTotal, Function<I,O> task)
task
is executed once per
input
item. The session-clearing (But no commit) is done once per batchSize
items.
WARNING: the session clearing will discard any unflushed or uncommitted changes made higher in the stack. Also, the existing transaction will not be committed in this method. Use this method only for the operations that do not write to database.
I
- the type of the input itemsO
- the type of the resulting items, which can be Voidinput
- the list of items to processbatchSize
- 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.task
- the task to executeIllegalStateException
- if there is no active sessionorg.springframework.dao.DataAccessException
- if there is a problem committing changes to the databasepublic int executeThenClearSessionWithoutCommitOrFlush(int batchSize, int expectedTotal, Function<Integer,Integer> taskExecutor)
batchSize
- the positive number of tasks to execute in a batch, before any hibernate clears.expectedTotal
- the positive total number of tasks to be executed.taskExecutor
- the task executor. The taskExecutor should accept the batchSize to execute, and return how many
tasks have been successfully executed.public org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()
Copyright © 2003–2023 Atlassian. All rights reserved.
View cookie preferences