Package io.dropwizard.hibernate
Class UnitOfWorkAspect
java.lang.Object
io.dropwizard.hibernate.UnitOfWorkAspect
An aspect providing operations around a method with the
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterEnd()
void
beforeStart
(@Nullable UnitOfWork unitOfWork) protected void
protected org.hibernate.Session
protected org.hibernate.SessionFactory
void
onError()
void
onFinish()
protected void
-
Constructor Details
-
UnitOfWorkAspect
-
-
Method Details
-
beforeStart
-
afterEnd
public void afterEnd() -
onError
public void onError() -
onFinish
public void onFinish() -
configureSession
protected void configureSession() -
validateSession
protected void validateSession() -
getSession
protected org.hibernate.Session getSession() -
getSessionFactory
protected org.hibernate.SessionFactory getSessionFactory()
-