public class UnitOfWorkAspect extends Object
UnitOfWork
annotation.
It opens a Hibernate session and optionally a transaction.
It should be created for every invocation of the method.
Usage :
UnitOfWorkProxyFactory unitOfWorkProxyFactory = ...
UnitOfWork unitOfWork = ... // get annotation from method.
UnitOfWorkAspect aspect = unitOfWorkProxyFactory.newAspect();
try {
aspect.beforeStart(unitOfWork);
... // perform business logic.
aspect.afterEnd();
} catch (Exception e) {
aspect.onError();
throw e;
} finally {
aspect.onFinish();
}
Constructor and Description |
---|
UnitOfWorkAspect(Map<String,org.hibernate.SessionFactory> sessionFactories) |
Modifier and Type | Method and Description |
---|---|
void |
afterEnd() |
void |
beforeStart(UnitOfWork unitOfWork) |
protected void |
configureSession() |
protected org.hibernate.Session |
getSession() |
protected org.hibernate.SessionFactory |
getSessionFactory() |
void |
onError() |
void |
onFinish() |
protected void |
validateSession() |
public void beforeStart(@Nullable UnitOfWork unitOfWork)
public void afterEnd()
public void onError()
public void onFinish()
protected void configureSession()
protected void validateSession()
protected org.hibernate.Session getSession()
protected org.hibernate.SessionFactory getSessionFactory()
Copyright © 2020. All rights reserved.