Example usage for org.springframework.data.jpa.repository.support SimpleJpaRepository SimpleJpaRepository

List of usage examples for org.springframework.data.jpa.repository.support SimpleJpaRepository SimpleJpaRepository

Introduction

In this page you can find the example usage for org.springframework.data.jpa.repository.support SimpleJpaRepository SimpleJpaRepository.

Prototype

public SimpleJpaRepository(Class<T> domainClass, EntityManager em) 

Source Link

Document

Creates a new SimpleJpaRepository to manage objects of the given domain type.

Usage

From source file:example.springdata.jpa.basics.BasicSample.java

/**
 * Sets up a {@link SimpleJpaRepository} instance.
 *//*  w  ww  .j av  a  2s  . c  o m*/
@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();
}

From source file:org.lightadmin.core.config.domain.DomainTypeAdministrationConfigurationFactory.java

public DomainTypeBasicConfiguration createNonManagedDomainTypeConfiguration(Class<?> domainType) {
    JpaRepository repository = new SimpleJpaRepository(domainType, entityManager);

    PersistentEntity persistentEntity = mappingContext.getPersistentEntity(domainType);

    DefaultEntityMetadataConfigurationUnitBuilder builder = new DefaultEntityMetadataConfigurationUnitBuilder(
            domainType);/*from w w  w  . j av a2s .  co m*/

    builder.nameExtractor(EntityNameExtractorFactory.forPersistentEntity(persistentEntity));

    return new NonManagedDomainTypeConfiguration(builder.build(), persistentEntity, repository);
}

From source file:com.sinosoft.one.data.jpa.repository.support.OneJpaRepositoryFactory.java

/**
 * Callback to create a {@link org.springframework.data.jpa.repository.JpaRepository} instance with the given {@link javax.persistence.EntityManager}
 *
 * @param <T>/* w w w  .jav  a 2 s . c  o  m*/
 * @param <ID>
 * @param entityManager
 * @see #getTargetRepository(org.springframework.data.repository.core.RepositoryMetadata)
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected <T, ID extends Serializable> JpaRepository<?, ?> getTargetRepository(RepositoryMetadata metadata,
        EntityManager entityManager) {

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

    SimpleJpaRepository<?, ?> repo = isQueryDslExecutor(repositoryInterface)
            ? new QueryDslJpaRepository(entityInformation, entityManager)
            : new SimpleJpaRepository(entityInformation, entityManager);
    repo.setLockMetadataProvider(lockModePostProcessor.getLockMetadataProvider());

    return repo;
}