/** * Creates a new <b>@UnitOfWork</b> aware proxy of a class with the default constructor. * * @param clazz the specified class definition * @param <T> the type of the class * @return a new proxy */ public <T> T create(Class<T> clazz) { return create(clazz, new Class<?>[]{}, new Object[]{}); }
UnitOfWorkAwareProxyFactory factory = new UnitOfWorkAwareProxyFactory(); PersonDao proxy = factory.create(PersonDao.class);
proxy.setHandler((self, overridden, proceed, args) -> { final UnitOfWork unitOfWork = overridden.getAnnotation(UnitOfWork.class); final UnitOfWorkAspect unitOfWorkAspect = newAspect(sessionFactories); try { unitOfWorkAspect.beforeStart(unitOfWork);
final RecurringJob recurringJob = new UnitOfWorkAwareProxyFactory(hibernate).create(RecurringJob.class, FinanceService.class, financeService); TokenAuthenticator tokenAuthenticator = new UnitOfWorkAwareProxyFactory(hibernate).create(TokenAuthenticator.class, FinanceService.class, financeService); final OAuthCredentialAuthFilter<User> authFilter = new OAuthCredentialAuthFilter.Builder<User>()
UnitOfWorkAspect aspect = proxyFactory.newAspect(); try { aspect.beforeStart(mi.getMethod().getAnnotation(UnitOfWork.class));
/** * Creates a new <b>@UnitOfWork</b> aware proxy of a class with an one-parameter constructor. * * @param clazz the specified class definition * @param constructorParamType the type of the constructor parameter * @param constructorArguments the argument passed to the constructor * @param <T> the type of the class * @return a new proxy */ public <T> T create(Class<T> clazz, Class<?> constructorParamType, Object constructorArguments) { return create(clazz, new Class<?>[]{constructorParamType}, new Object[]{constructorArguments}); }
proxy.setHandler((self, overridden, proceed, args) -> { final UnitOfWork unitOfWork = overridden.getAnnotation(UnitOfWork.class); final UnitOfWorkAspect unitOfWorkAspect = newAspect(sessionFactories); try { unitOfWorkAspect.beforeStart(unitOfWork);
/** * Creates a new <b>@UnitOfWork</b> aware proxy of a class with the default constructor. * * @param clazz the specified class definition * @param <T> the type of the class * @return a new proxy */ public <T> T create(Class<T> clazz) { return create(clazz, new Class<?>[]{}, new Object[]{}); }
/** * Creates a new <b>@UnitOfWork</b> aware proxy of a class with an one-parameter constructor. * * @param clazz the specified class definition * @param constructorParamType the type of the constructor parameter * @param constructorArguments the argument passed to the constructor * @param <T> the type of the class * @return a new proxy */ public <T> T create(Class<T> clazz, Class<?> constructorParamType, Object constructorArguments) { return create(clazz, new Class<?>[]{constructorParamType}, new Object[]{constructorArguments}); }
UnitOfWorkAwareProxyFactory fac = new UnitOfWorkAwareProxyFactory(hibernate); UserAuth proxy = fac.create(UserAuth.class, UserDao.class, dao); environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<Principal>() .setAuthenticator(proxy).setRealm("SUPER SECRET STUFF").buildAuthFilter()));