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

The following examples show how to use org.springframework.data.jpa.repository.support.JpaEntityInformation. 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: 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 #2
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 #3
Source File: SimpleBaseRepositoryFactoryBean.java    From es with Apache License 2.0 5 votes vote down vote up
protected Object getTargetRepository(RepositoryMetadata metadata) {
    Class<?> repositoryInterface = metadata.getRepositoryInterface();

    if (isBaseRepository(repositoryInterface)) {

        JpaEntityInformation<M, ID> entityInformation = getEntityInformation((Class<M>) metadata.getDomainType());
        SimpleBaseRepository repository = new SimpleBaseRepository<M, ID>(entityInformation, entityManager);

        SearchableQuery searchableQuery = AnnotationUtils.findAnnotation(repositoryInterface, SearchableQuery.class);
        if (searchableQuery != null) {
            String countAllQL = searchableQuery.countAllQuery();
            if (!StringUtils.isEmpty(countAllQL)) {
                repository.setCountAllQL(countAllQL);
            }
            String findAllQL = searchableQuery.findAllQuery();
            if (!StringUtils.isEmpty(findAllQL)) {
                repository.setFindAllQL(findAllQL);
            }
            Class<? extends SearchCallback> callbackClass = searchableQuery.callbackClass();
            if (callbackClass != null && callbackClass != SearchCallback.class) {
                repository.setSearchCallback(BeanUtils.instantiate(callbackClass));
            }

            repository.setJoins(searchableQuery.joins());

        }

        return repository;
    }
    return super.getTargetRepository(metadata);
}
 
Example #4
Source File: BaseRepositoryFactoryBean.java    From web-flash with MIT License 5 votes vote down vote up
@Override
protected JpaRepositoryImplementation<?, ?> getTargetRepository(RepositoryInformation information, EntityManager entityManager) {
    JpaEntityInformation<?, Serializable> entityInformation = this.getEntityInformation(information.getDomainType());
    Object repository = this.getTargetRepositoryViaReflection(information, new Object[]{entityInformation, entityManager});
    Assert.isInstanceOf(BaseRepositoryImpl.class, repository);
    return (JpaRepositoryImplementation)repository;
}
 
Example #5
Source File: SimpleBaseRepository.java    From es with Apache License 2.0 5 votes vote down vote up
public SimpleBaseRepository(JpaEntityInformation<M, ID> entityInformation, EntityManager entityManager) {
    super(entityInformation, entityManager);

    this.entityInformation = entityInformation;
    this.entityClass = this.entityInformation.getJavaType();
    this.entityName = this.entityInformation.getEntityName();
    this.idName = this.entityInformation.getIdAttributeNames().iterator().next();
    this.em = entityManager;

    repositoryHelper = new RepositoryHelper(entityClass);

    findAllQL = String.format(FIND_QUERY_STRING, entityName);
    countAllQL = String.format(COUNT_QUERY_STRING, entityName);
}
 
Example #6
Source File: BaseRepositoryFactoryBean.java    From flash-waimai with MIT License 5 votes vote down vote up
@Override
protected JpaRepositoryImplementation<?, ?> getTargetRepository(RepositoryInformation information, EntityManager entityManager) {
    JpaEntityInformation<?, Serializable> entityInformation = this.getEntityInformation(information.getDomainType());
    Object repository = this.getTargetRepositoryViaReflection(information, new Object[]{entityInformation, entityManager});
    Assert.isInstanceOf(BaseRepositoryImpl.class, repository);
    return (JpaRepositoryImplementation)repository;
}
 
Example #7
Source File: EntityGraphQuerydslRepository.java    From spring-data-jpa-entity-graph with MIT License 5 votes vote down vote up
public EntityGraphQuerydslRepository(
    JpaEntityInformation<T, ID> entityInformation,
    EntityManager entityManager,
    EntityPathResolver resolver) {
  super(entityInformation, entityManager);
  this.querydslJpaRepositoryDelegate =
      new EntityGraphAwareQuerydslJpaRepository<>(entityInformation, entityManager, resolver);
}
 
Example #8
Source File: EntityGraphQuerydslRepository.java    From spring-data-jpa-entity-graph with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public EntityGraphQuerydslRepository(
    JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
  super(entityInformation, entityManager);
  this.querydslJpaRepositoryDelegate =
      new EntityGraphAwareQuerydslJpaRepository<>(
          (JpaEntityInformation<T, ID>) entityInformation, entityManager);
}
 
Example #9
Source File: GenericJpaRepositoryImpl.java    From spring-data-jpa-extra with Apache License 2.0 5 votes vote down vote up
public GenericJpaRepositoryImpl(JpaEntityInformation<T, ID> eif, EntityManager em) {
    super(eif, em);
    this.eif = eif;
    PropertyDescriptor descriptor = findFieldPropertyDescriptor(eif.getJavaType(), Status.class);
    isStatusAble = descriptor != null;
    if (isStatusAble) {
        statusReadMethod = descriptor.getReadMethod();
        statusWriteMethod = descriptor.getWriteMethod();
    }
}
 
Example #10
Source File: SimpleExtendedQuerydslJpaRepository.java    From infobip-spring-data-querydsl with Apache License 2.0 5 votes vote down vote up
SimpleExtendedQuerydslJpaRepository(JpaEntityInformation<T, ID> entityInformation,
                                    EntityManager entityManager) throws SQLException {
    super(entityInformation, entityManager, SimpleEntityPathResolver.INSTANCE);
    this.jpaQueryFactory = new JPAQueryFactory(HQLTemplates.DEFAULT, entityManager);
    this.path = SimpleEntityPathResolver.INSTANCE.createPath(entityInformation.getJavaType());
    SQLTemplates sqlTemplates = getSQLServerTemplates(entityManager.getEntityManagerFactory());
    this.jpaSqlFactory = () -> new JPASQLQuery<>(entityManager, sqlTemplates);
    this.entityManager = entityManager;
}
 
Example #11
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 #12
Source File: GenericRepositoryImpl.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new {@link SimpleJpaRepository} to manage objects of the given
 * {@link JpaEntityInformation}.
 */
public GenericRepositoryImpl(final JpaEntityInformation<T, ?> entityInformation, final EntityManager entityManager,
        final NamedQueryUtil namedQueryUtil) {
    super(entityInformation, entityManager);
    this.entityInformation = entityInformation;
    this.em = entityManager;
    // provider =
    // DefaultPersistenceProvider.fromEntityManager(entityManager);
    // this.springDataRepositoryInterface = springDataRepositoryInterface;
    this.namedQueryUtil = namedQueryUtil;
    this.byExampleSpecification = new ByExampleSpecification(entityManager);
}
 
Example #13
Source File: ApplicationConfigurationTest.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void repositoriesAreAssignedToAppropriateStores() {

	Repositories repositories = new Repositories(context);

	assertThat(repositories.getEntityInformationFor(Customer.class), is(instanceOf(JpaEntityInformation.class)));
	assertThat(repositories.getEntityInformationFor(Order.class), is(instanceOf(MongoEntityInformation.class)));
}
 
Example #14
Source File: EntityGraphQuerydslRepositoryTest.java    From spring-data-jpa-entity-graph with MIT License 4 votes vote down vote up
public EntityGraphQuerydslRepositoryChild(
    JpaEntityInformation<Object, ?> entityInformation, EntityManager entityManager) {
  super(entityInformation, entityManager);
}
 
Example #15
Source File: DefaultPlatformJpaRepository.java    From abixen-platform with GNU Lesser General Public License v2.1 4 votes vote down vote up
public DefaultPlatformJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
    super(entityInformation, entityManager);
    this.entityManager = entityManager;
}
 
Example #16
Source File: EntityGraphSimpleJpaRepository.java    From spring-data-jpa-entity-graph with MIT License 4 votes vote down vote up
public EntityGraphSimpleJpaRepository(
    JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
  super(entityInformation, entityManager);
}
 
Example #17
Source File: EntityGraphAwareQuerydslJpaRepository.java    From spring-data-jpa-entity-graph with MIT License 4 votes vote down vote up
public EntityGraphAwareQuerydslJpaRepository(
    JpaEntityInformation<T, ID> entityInformation,
    EntityManager entityManager,
    EntityPathResolver resolver) {
  super(entityInformation, entityManager, resolver);
}
 
Example #18
Source File: EntityGraphAwareQuerydslJpaRepository.java    From spring-data-jpa-entity-graph with MIT License 4 votes vote down vote up
public EntityGraphAwareQuerydslJpaRepository(
    JpaEntityInformation<T, ID> entityInformation, EntityManager entityManager) {
  super(entityInformation, entityManager);
}
 
Example #19
Source File: CoreJpaRepositoryFactoryBean.java    From abixen-platform with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected DefaultPlatformJpaRepository getTargetRepository(RepositoryInformation information) {
    JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(information.getDomainType());
    return new DefaultPlatformJpaRepository(entityInformation, em);
}
 
Example #20
Source File: GenericJpaRepositoryImpl.java    From genericdao with Artistic License 2.0 4 votes vote down vote up
public JpaEntityInformation<T, ?> getEntityInformation() {
	return entityInformation;
}
 
Example #21
Source File: OrmTemplate.java    From sample-boot-hibernate with MIT License 4 votes vote down vote up
/** 指定したエンティティの ID 値を取得します。 */
@SuppressWarnings("unchecked")
public <T> Serializable idValue(T entity) {
    return ((JpaEntityInformation<T, Serializable>)OrmUtils.entityInformation(em, entity.getClass())).getId(entity);
}
 
Example #22
Source File: CustomSimpleJpaRepository.java    From wicket-spring-boot with Apache License 2.0 4 votes vote down vote up
public CustomSimpleJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
	super(entityInformation, entityManager);
}
 
Example #23
Source File: QDataTablesRepositoryImpl.java    From spring-data-jpa-datatables with Apache License 2.0 4 votes vote down vote up
QDataTablesRepositoryImpl(JpaEntityInformation<T, ID> entityInformation,
    EntityManager entityManager) {
  this(entityInformation, entityManager, DEFAULT_ENTITY_PATH_RESOLVER);
}
 
Example #24
Source File: QDataTablesRepositoryImpl.java    From spring-data-jpa-datatables with Apache License 2.0 4 votes vote down vote up
public QDataTablesRepositoryImpl(JpaEntityInformation<T, ID> entityInformation,
    EntityManager entityManager, EntityPathResolver resolver) {
  super(entityInformation, entityManager);
  EntityPath<T> path = resolver.createPath(entityInformation.getJavaType());
  this.builder = new PathBuilder<>(path.getType(), path.getMetadata());
}
 
Example #25
Source File: DataTablesRepositoryImpl.java    From spring-data-jpa-datatables with Apache License 2.0 4 votes vote down vote up
DataTablesRepositoryImpl(JpaEntityInformation<T, ?> entityInformation,
    EntityManager entityManager) {

  super(entityInformation, entityManager);
}
 
Example #26
Source File: JooqJpaRepository.java    From blog-examples with Apache License 2.0 4 votes vote down vote up
public JooqJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager, DSLContext jooq) {
	super(entityInformation, entityManager);
	this.entityInformation = entityInformation;
	this.jooq = jooq;
}
 
Example #27
Source File: ExtendedRepositoryImpl.java    From tutorials with MIT License 4 votes vote down vote up
public ExtendedRepositoryImpl(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
    super(entityInformation, entityManager);
    this.entityManager = entityManager;
}
 
Example #28
Source File: RepositoryHelper.java    From es with Apache License 2.0 4 votes vote down vote up
public <T> JpaEntityInformation<T, ?> getMetadata(Class<T> entityClass) {
    return JpaEntityInformationSupport.getMetadata(entityClass, entityManager);
}
 
Example #29
Source File: GenericRepositoryImpl.java    From spring-data-examples with MIT License 4 votes vote down vote up
public GenericRepositoryImpl(JpaEntityInformation<T, Serializable> entityInformation, EntityManager entityManager) {
  super(entityInformation, entityManager);
  this.entityInformation = entityInformation;
  this.entityManager = entityManager;
}
 
Example #30
Source File: JpaSupportRepository.java    From base-framework with Apache License 2.0 4 votes vote down vote up
public JpaSupportRepository(JpaEntityInformation<T, ?> entityInformation, EntityManager em) {
	super(entityInformation, em);
	this.entityInformation = entityInformation;
	this.entityManager = em;
}