/** * Creates a {@link SimpleUserRepository} instance. * * @throws Exception */ @Before public void setUp() { em = factory.createEntityManager(); projectRepository = new JpaRepositoryFactory(em).getRepository(TMProjectRepository.class); userRepository = new JpaRepositoryFactory(em).getRepository(TMUserRepository.class); em.getTransaction().begin(); user = new TMUser("jchaganti", "jch"); user = userRepository.save(user); project = TMProject.getBuilder(user, "description", "title").build(); project = projectRepository.save(project); em.getTransaction().commit(); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (repository.get() == null) { synchronized (this) { if (repository.get() == null) { repository.set(new JpaRepositoryFactory(em).getRepository(implementingInterfaceClass)); } } } return method.invoke(repository.get(), args); }
@Override public void afterPropertiesSet() { applicationContext.getAutowireCapableBeanFactory().autowireBean(this); this.jpaRepositoryFactory = new JpaRepositoryFactory(entityManager); try { // Make sure calls to the repository instance are intercepted for annotated transactions Class transactionalRepositoryProxyPostProcessor = Class.forName("org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor"); final Constructor constructor = transactionalRepositoryProxyPostProcessor.getConstructor(ListableBeanFactory.class, String.class); final RepositoryProxyPostProcessor repositoryProxyPostProcessor = (RepositoryProxyPostProcessor) constructor.newInstance(applicationContext.getBeanFactory(), TxUtils.DEFAULT_TRANSACTION_MANAGER); jpaRepositoryFactory.addRepositoryProxyPostProcessor(repositoryProxyPostProcessor); } catch (Exception e) { log.error("Failed to initialize the TransactionalRepositoryProxyPostProcessor class", e); } }
/** * Creates a {@link SimpleUserRepository} instance. * * @throws Exception */ @Before public void setUp() { em = factory.createEntityManager(); userRepository = new JpaRepositoryFactory(em).getRepository(SimpleUserRepository.class); em.getTransaction().begin(); user = new User(); user.setUsername("username"); user.setFirstname("firstname"); user.setLastname("lastname"); user = userRepository.save(user); }
@Bean public RepositoryFactorySupport repositoryFactorySupport(){ LOGGER.info("In bean repositoryFactorySupport() entity manager is : {}", em.toString()); return new JpaRepositoryFactory(em); }
@Bean public JpaRepositoryFactory repositoryFactory(EntityManagerFactory emf) { return new JpaRepositoryFactory(emf.createEntityManager()); }
@Bean public AddressStorage addressStorage(JpaRepositoryFactory rf) { return rf.getRepository(AddressStorage.class); }
@Bean public EmailStorage emailStorage(JpaRepositoryFactory rf) { return rf.getRepository(EmailStorage.class); }
@Bean public PhoneStorage phoneStorage(JpaRepositoryFactory rf) { return rf.getRepository(PhoneStorage.class); }