Package io.dropwizard.hibernate
Class UnitOfWorkAspect
- java.lang.Object
-
- io.dropwizard.hibernate.UnitOfWorkAspect
-
public class UnitOfWorkAspect extends Object
An aspect providing operations around a method with theUnitOfWork
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 Constructor Description UnitOfWorkAspect(Map<String,org.hibernate.SessionFactory> sessionFactories)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
-
-
Method Detail
-
beforeStart
public void beforeStart(@Nullable UnitOfWork unitOfWork)
-
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()
-
-