org.springframework.data.jpa.repository.support.SimpleJpaRepository Java Examples

The following examples show how to use org.springframework.data.jpa.repository.support.SimpleJpaRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicSample.java    From spring-data-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up a {@link SimpleJpaRepository} instance.
 */
@Before
public void setUp() {

	EntityManagerFactory factory = Persistence.createEntityManagerFactory("jpa.sample.plain");
	em = factory.createEntityManager();

	userRepository = new SimpleJpaRepository<User, Long>(User.class, em);

	em.getTransaction().begin();
}
 
Example #2
Source File: DefaultRepositoryFactory.java    From gazpachoquest with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected <T, ID extends Serializable> SimpleJpaRepository<?, ?> getTargetRepository(
        final RepositoryMetadata metadata, final EntityManager entityManager) {

    Class<?> repositoryInterface = metadata.getRepositoryInterface();

    JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType());

    if (isQueryDslExecutor(repositoryInterface)) {
        return new QueryDslJpaRepository(entityInformation, entityManager);
    } else {
        return new GenericRepositoryImpl(entityInformation, entityManager, namedQueryUtil); // custom
    }
}
 
Example #3
Source File: TestEntityRepositoryTest.java    From spring-repository-plus with Apache License 2.0 5 votes vote down vote up
@Before
public void setup(){
    JpaEntityInformation<TestEntity, Integer> information = new JpaMetamodelEntityInformation<>(
            TestEntity.class, em.getMetamodel());
    repository = new SimpleJpaRepository<>(information, em);
    entities = SpecificationBuilder.selectDistinctFrom(repository).where(new Filter("string",EQUAL,"a")).findAll();
    Assert.assertTrue(entities.size() >= 1);
}
 
Example #4
Source File: AclJpaRepositoryFactoryBean.java    From strategy-spring-security-acl with Apache License 2.0 5 votes vote down vote up
protected SimpleJpaRepository<?, ?> getTargetRepository(RepositoryInformation information,
    EntityManager entityManager) {
  Class<?> domainType = information.getDomainType();
  if (!hasAclStrategyAnnotation(domainType)) {
    return super.getTargetRepository(information, entityManager);
  }

  JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(domainType);

  // invokes
  // com.github.lothar.security.acl.jpa.repository.AclJpaRepository.AclJpaRepository(JpaEntityInformation<T,
  // ?>, EntityManager, JpaSpecProvider<T>)
  SimpleJpaRepository<?, ?> repository = getTargetRepositoryViaReflection(information,
      entityInformation, entityManager, jpaSpecProvider);
  logger.debug("Created {}", repository);

  return repository;
}
 
Example #5
Source File: AbstractRepositoryImplementation.java    From galeb with Apache License 2.0 4 votes vote down vote up
public void setSimpleJpaRepository(Class<T> klazz, GenericDaoService genericDaoService) {
    if (this.simpleJpaRepository != null) return;
    this.simpleJpaRepository = new SimpleJpaRepository<>(klazz, genericDaoService.entityManager());
    this.genericDaoService = genericDaoService;
}
 
Example #6
Source File: DefaultRepositoryFactory.java    From HA-DB with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected <T, ID extends Serializable> SimpleJpaRepository<?, ?> getTargetRepository(RepositoryMetadata metadata, EntityManager entityManager) {
	JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType());
	return new GenericRepositoryImpl(entityInformation, entityManager);
}
 
Example #7
Source File: RepositoryTest.java    From spring-data-jpa-datatables with Apache License 2.0 4 votes vote down vote up
@Test
public void checkGeneratedRepositories() {
  assertThat(getTargetObject(employeeRepository)).isEqualTo(DataTablesRepositoryImpl.class);
  assertThat(getTargetObject(officeRepository)).isEqualTo(SimpleJpaRepository.class);
  assertThat(getTargetObject(qEmployeeRepository)).isEqualTo(QDataTablesRepositoryImpl.class);
}