Created
July 26, 2013 14:12
-
-
Save yanaga/6089174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
import javax.persistence.EntityManager; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.data.jpa.repository.support.JpaEntityInformation; | |
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory; | |
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean; | |
import org.springframework.data.repository.core.RepositoryMetadata; | |
import org.springframework.data.repository.core.support.RepositoryFactorySupport; | |
public class NonTransactionalQuerydslJpaRepositoryFactoryBean<R extends JpaRepository<T, I>, T, I extends Serializable> | |
extends JpaRepositoryFactoryBean<R, T, I> { | |
@Override | |
protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) { | |
return new NonTransactionalQuerydslJpaRepositoryFactory<T, I>(entityManager); | |
} | |
private static class NonTransactionalQuerydslJpaRepositoryFactory<T, I extends Serializable> extends | |
JpaRepositoryFactory { | |
private EntityManager entityManager; | |
public NonTransactionalQuerydslJpaRepositoryFactory(EntityManager entityManager) { | |
super(entityManager); | |
this.entityManager = entityManager; | |
} | |
@SuppressWarnings("unchecked") | |
@Override | |
protected Object getTargetRepository(RepositoryMetadata metadata) { | |
JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType()); | |
return new NonTransactionalQuerydslJpaRepository<T, I>((JpaEntityInformation<T, I>) entityInformation, | |
entityManager); | |
} | |
@Override | |
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) { | |
return NonTransactionalQuerydslJpaRepository.class; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment