com.google.sitebricks.persist.WorkInterceptor Maven / Gradle / Ivy
package com.google.sitebricks.persist;
import com.google.inject.Injector;
import com.google.inject.Key;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import javax.inject.Inject;
/**
* Guice AOP interceptor that manages unit of work semantics.
*
* @author [email protected] (Dhanji R. Prasanna)
*/
class WorkInterceptor implements MethodInterceptor {
private final Key persisterKey;
private Persister persister;
public WorkInterceptor(Key persisterKey) {
this.persisterKey = persisterKey;
}
@Inject
public void init(Injector injector) {
this.persister = injector.getInstance(persisterKey);
}
@Override
public Object invoke(final MethodInvocation methodInvocation) throws Throwable {
return persister.call(new Persister.InWork() {
@Override
public Object perform(EntityStore entityStore) throws Throwable {
return methodInvocation.proceed();
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy