org.springframework.data.repository.core.RepositoryInformation Java Examples

The following examples show how to use org.springframework.data.repository.core.RepositoryInformation. 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: AclElasticsearchRepositoryFactoryBean.java    From strategy-spring-security-acl with Apache License 2.0 6 votes vote down vote up
@Override
protected Object getTargetRepository(RepositoryInformation metadata) {
  Class<?> domainType = metadata.getDomainType();
  ElasticsearchEntityInformation<?, Serializable> entityInformation =
      getEntityInformation(domainType);
  if (!hasAclStrategyAnnotation(domainType)) {
    return getTargetRepositoryViaReflection(metadata, entityInformation,
        elasticsearchOperations);
  }

  // invokes
  // com.github.lothar.security.acl.elasticsearch.repository.AclElasticsearchRepository.AclNumberKeyedRepository(ElasticsearchEntityInformation<T,
  // ID>, ElasticsearchOperations, AclFilterProvider)
  ElasticsearchRepository<?, ?> repository = getTargetRepositoryViaReflection(metadata,
      entityInformation, elasticsearchOperations, filterProvider);
  logger.debug("Created {}", repository);

  return repository;
}
 
Example #2
Source File: RepositoryUtils.java    From spring-content with Apache License 2.0 6 votes vote down vote up
public static RepositoryInformation findRepositoryInformation(
		Repositories repositories, String repository) {
	RepositoryInformation ri = null;
	for (Class<?> clazz : repositories) {
		Optional<RepositoryInformation> candidate = repositories
				.getRepositoryInformationFor(clazz);
		if (candidate.isPresent() == false) {
			continue;
		}
		if (repository.equals(repositoryPath(candidate.get()))) {
			ri = candidate.get();
			break;
		}
	}
	return ri;
}
 
Example #3
Source File: AbstractContentPropertyController.java    From spring-content with Apache License 2.0 6 votes vote down vote up
public static Object findOne(Repositories repositories, Class<?> domainObjClass,
		String id) throws HttpRequestMethodNotSupportedException {

	Optional<Object> domainObj = null;

	RepositoryInformation ri = RepositoryUtils.findRepositoryInformation(repositories,
			domainObjClass);

	if (ri == null) {
		throw new ResourceNotFoundException();
	}

	Class<?> domainObjClazz = ri.getDomainType();
	Class<?> idClazz = ri.getIdType();

	Optional<Method> findOneMethod = ri.getCrudMethods().getFindOneMethod();
	if (!findOneMethod.isPresent()) {
		throw new HttpRequestMethodNotSupportedException("fineOne");
	}

	Object oid = new DefaultConversionService().convert(id, idClazz);
	domainObj = (Optional<Object>) ReflectionUtils.invokeMethod(findOneMethod.get(),
			repositories.getRepositoryFor(domainObjClazz).get(), oid);

	return domainObj.orElseThrow(ResourceNotFoundException::new);
}
 
Example #4
Source File: QuerydslJdbcRepositoryFactory.java    From infobip-spring-data-querydsl with Apache License 2.0 6 votes vote down vote up
@Override
protected Object getTargetRepository(RepositoryInformation repositoryInformation) {

    JdbcAggregateTemplate template = new JdbcAggregateTemplate(publisher, context, converter, accessStrategy);

    Class<?> type = repositoryInformation.getDomainType();
    RelationalPath<?> relationalPathBase = getRelationalPathBase(repositoryInformation);
    ConstructorExpression<?> constructor = getConstructorExpression(type, relationalPathBase);
    SimpleQuerydslJdbcRepository<?, ?> repository = new SimpleQuerydslJdbcRepository(template,
                                                                                        context.getRequiredPersistentEntity(
                                                                                                type),
                                                                                        sqlQueryFactory,
                                                                                        constructor,
                                                                                        relationalPathBase);

    if (entityCallbacks != null) {
        template.setEntityCallbacks(entityCallbacks);
    }

    return repository;
}
 
Example #5
Source File: SolrRepositoryFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object getTargetRepository(RepositoryInformation metadata) {

	SolrOperations operations = this.solrOperations;
	if (factory != null) {
		SolrTemplate template = new SolrTemplate(factory);
		if (this.solrOperations.getConverter() != null) {
			template.setMappingContext(this.solrOperations.getConverter().getMappingContext());
		}
		template.setSolrCore(SolrClientUtils.resolveSolrCoreName(metadata.getDomainType()));
		addSchemaCreationFeaturesIfEnabled(template);
		template.afterPropertiesSet();
		operations = template;
	}

	SimpleSolrRepository repository = getTargetRepositoryViaReflection(metadata,
			getEntityInformation(metadata.getDomainType()), operations);
	repository.setEntityClass(metadata.getDomainType());

	this.templateHolder.add(metadata.getDomainType(), operations);
	return repository;
}
 
Example #6
Source File: AbstractContentPropertyController.java    From spring-content with Apache License 2.0 6 votes vote down vote up
public static Object save(Repositories repositories, Object domainObj)
		throws HttpRequestMethodNotSupportedException {

	RepositoryInformation ri = RepositoryUtils.findRepositoryInformation(repositories,
			domainObj.getClass());

	if (ri == null) {
		throw new ResourceNotFoundException();
	}

	Class<?> domainObjClazz = ri.getDomainType();

	if (domainObjClazz != null) {
		Optional<Method> saveMethod = ri.getCrudMethods().getSaveMethod();
		if (!saveMethod.isPresent()) {
			throw new HttpRequestMethodNotSupportedException("save");
		}
		domainObj = ReflectionUtils.invokeMethod(saveMethod.get(),
				repositories.getRepositoryFor(domainObjClazz).get(), domainObj);
	}

	return domainObj;
}
 
Example #7
Source File: MybatisMapperBuildProcessor.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcess(ProxyFactory factory,
		RepositoryInformation repositoryInformation) {

	new MybatisBasicMapperBuilder(configuration, repositoryInformation, mappingContext
			.getRequiredPersistentEntity(repositoryInformation.getDomainType()))
					.build();

}
 
Example #8
Source File: LockingAndVersioningRestController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value = ENTITY_FINDALLLATESTVERSION_MAPPING, method = RequestMethod.GET)
public ResponseEntity<?> findAllLatestVersion(RootResourceInformation repoInfo,
											  PersistentEntityResourceAssembler assembler,
											  @PathVariable String repository)
		throws ResourceNotFoundException, HttpRequestMethodNotSupportedException {

	RepositoryInformation repositoryInfo = RepositoryUtils.findRepositoryInformation(repositories, repository);
	Class<?> domainType = repositoryInfo.getDomainType();

	List result = (List)ReflectionUtils.invokeMethod(FINDALLLATESTVERSION_METHOD, repositories.getRepositoryFor(domainType).get());

	return ResponseEntity.ok(toResources(result, assembler, this.pagedResourcesAssembler, domainType, null));
}
 
Example #9
Source File: RepositoryUtils.java    From spring-content with Apache License 2.0 5 votes vote down vote up
public static String repositoryPath(RepositoryInformation info) {
	Class<?> clazz = info.getRepositoryInterface();
	RepositoryRestResource annotation = AnnotationUtils.findAnnotation(clazz,
			RepositoryRestResource.class);
	String path = annotation == null ? null : annotation.path().trim();
	path = StringUtils.hasText(path) ? path : English
			.plural(StringUtils.uncapitalize(info.getDomainType().getSimpleName()));
	return path;
}
 
Example #10
Source File: RepositoryUtils.java    From spring-content with Apache License 2.0 5 votes vote down vote up
public static RepositoryInformation findRepositoryInformation(
		Repositories repositories, Class<?> domainObjectClass) {
	RepositoryInformation ri = null;
	for (Class<?> clazz : repositories) {
		if (clazz.equals(domainObjectClass)) {
			return repositories.getRepositoryInformationFor(clazz).get();
		}
	}
	return ri;
}
 
Example #11
Source File: AbstractContentPropertyController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
public static Object findOne(Repositories repositories, String repository, String id)
		throws HttpRequestMethodNotSupportedException {

	Optional<Object> domainObj = null;

	RepositoryInformation ri = RepositoryUtils.findRepositoryInformation(repositories, repository);

	if (ri == null) {
		throw new ResourceNotFoundException();
	}

	Class<?> domainObjClazz = ri.getDomainType();
	Class<?> idClazz = ri.getIdType();

	Optional<Method> findOneMethod = ri.getCrudMethods().getFindOneMethod();
	if (!findOneMethod.isPresent()) {
		throw new HttpRequestMethodNotSupportedException("fineOne");
	}

	Object oid = new DefaultConversionService().convert(id, idClazz);
	domainObj = (Optional<Object>) ReflectionUtils.invokeMethod(findOneMethod.get(),
			repositories.getRepositoryFor(domainObjClazz).get(), oid);

	if (null == domainObj) {
		throw new ResourceNotFoundException();
	}

	return domainObj.orElseThrow(ResourceNotFoundException::new);
}
 
Example #12
Source File: AbstractContentPropertyController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
public static Iterable findAll(Repositories repositories, String repository)
		throws HttpRequestMethodNotSupportedException {

	Iterable entities = null;

	RepositoryInformation ri = RepositoryUtils.findRepositoryInformation(repositories, repository);

	if (ri == null) {
		throw new ResourceNotFoundException();
	}

	Class<?> domainObjClazz = ri.getDomainType();
	Class<?> idClazz = ri.getIdType();

	Optional<Method> findAllMethod = ri.getCrudMethods().getFindAllMethod();
	if (!findAllMethod.isPresent()) {
		throw new HttpRequestMethodNotSupportedException("fineAll");
	}

	entities = (Iterable) ReflectionUtils.invokeMethod(findAllMethod.get(),
			repositories.getRepositoryFor(domainObjClazz));

	if (null == entities) {
		throw new ResourceNotFoundException();
	}

	return entities;
}
 
Example #13
Source File: Neo4jRepositoryFactory.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
protected Object getTargetRepository(RepositoryInformation metadata) {

	Neo4jEntityInformation<?, Object> entityInformation = getEntityInformation(metadata.getDomainType());
	assertIdentifierType(metadata.getIdType(), entityInformation.getIdType());
	return getTargetRepositoryViaReflection(metadata, neo4jOperations, entityInformation);
}
 
Example #14
Source File: SimpleMybatisRepository.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
public SimpleMybatisRepository(SqlSessionTemplate sqlSessionTemplate,
		RepositoryInformation repositoryInformation,
		MybatisEntityInformation<T, ID> entityInformation) {

	super(sqlSessionTemplate);

	Assert.notNull(entityInformation, "EntityInformation must not be null!");

	this.namespace = repositoryInformation.getRepositoryInterface().getName();
	this.entityInformation = entityInformation;
}
 
Example #15
Source File: MybatisBasicMapperBuilder.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
public MybatisBasicMapperBuilder(Configuration configuration,
		RepositoryInformation repositoryInformation,
		PersistentEntity<?, ?> persistentEntity) {

	super(configuration, persistentEntity,
			repositoryInformation.getRepositoryInterface().getName());

}
 
Example #16
Source File: CustomRepositoryFactoryBean.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected Object getTargetRepository(RepositoryInformation information) {
	return isBaseRepository(information.getRepositoryInterface())
			? (isTreeRepository(information.getRepositoryInterface())
					? new TreeRepositoryImpl(getEntityInformation(information.getDomainType()), entityManager)
					: new BaseRepositoryImpl<>(getEntityInformation(information.getDomainType()),
							entityManager))
			: super.getTargetRepository(information);
}
 
Example #17
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 #18
Source File: IgniteRepositoryFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected Object getTargetRepository(RepositoryInformation metadata) {
    Ignite ignite = repoToIgnite.get(metadata.getRepositoryInterface());

    return getTargetRepositoryViaReflection(metadata, ignite,
        getRepositoryCache(metadata.getRepositoryInterface()));
}
 
Example #19
Source File: IgniteRepositoryFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected Object getTargetRepository(RepositoryInformation metadata) {
    Ignite ignite = repoToIgnite.get(metadata.getRepositoryInterface());

    return getTargetRepositoryViaReflection(metadata, ignite,
        getRepositoryCache(metadata.getRepositoryInterface()));
}
 
Example #20
Source File: ReactiveCosmosRepositoryFactory.java    From spring-data-cosmosdb with MIT License 5 votes vote down vote up
@Override
protected Object getTargetRepository(RepositoryInformation information) {
    final EntityInformation<?, Serializable> entityInformation =
        getEntityInformation(information.getDomainType());
    return getTargetRepositoryViaReflection(information, entityInformation,
        this.applicationContext);
}
 
Example #21
Source File: ReactiveNeo4jRepositoryFactoryTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {

	metadata = mock(RepositoryInformation.class);
	entityInformation = mock(Neo4jEntityInformation.class);

	doReturn(entityInformation).when(neo4jRepositoryFactory).getEntityInformation(Mockito.any());
}
 
Example #22
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 #23
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 #24
Source File: QuerydslJdbcRepositoryFactory.java    From infobip-spring-data-querydsl with Apache License 2.0 5 votes vote down vote up
private RelationalPathBase<?> getRelationalPathBase(RepositoryInformation repositoryInformation) {

        ResolvableType entityType = ResolvableType.forClass(repositoryInformation.getRepositoryInterface())
                                                 .as(QuerydslJdbcRepository.class)
                                                 .getGeneric(0);
        if (entityType.getRawClass() == null) {
            throw new IllegalArgumentException("Could not resolve query class for " + repositoryInformation);
        }

        return getRelationalPathBase(getQueryClass(entityType.getRawClass()));
    }
 
Example #25
Source File: Neo4jRepositoryFactoryTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {

	metadata = mock(RepositoryInformation.class);
	entityInformation = mock(Neo4jEntityInformation.class);

	doReturn(entityInformation).when(neo4jRepositoryFactory).getEntityInformation(Mockito.any());
}
 
Example #26
Source File: ReactiveNeo4jRepositoryFactory.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
protected Object getTargetRepository(RepositoryInformation metadata) {

	Neo4jEntityInformation<?, Object> entityInformation = getEntityInformation(metadata.getDomainType());
	assertIdentifierType(metadata.getIdType(), entityInformation.getIdType());
	return getTargetRepositoryViaReflection(metadata, neo4jOperations, entityInformation);
}
 
Example #27
Source File: DatastoreRepositoryFactoryTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void getTargetRepositoryTest() {
	RepositoryInformation repoInfo = mock(RepositoryInformation.class);
	Mockito.<Class<?>>when(repoInfo.getRepositoryBaseClass())
			.thenReturn(SimpleDatastoreRepository.class);
	Mockito.<Class<?>>when(repoInfo.getDomainType()).thenReturn(TestEntity.class);
	Object repo = this.datastoreRepositoryFactory.getTargetRepository(repoInfo);
	assertThat(repo.getClass()).isEqualTo(SimpleDatastoreRepository.class);
}
 
Example #28
Source File: SpannerRepositoryFactoryTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void getTargetRepositoryTest() {
	RepositoryInformation repoInfo = mock(RepositoryInformation.class);
	// @formatter:off
	Mockito.<Class<?>>when(repoInfo.getRepositoryBaseClass())
			.thenReturn(SimpleSpannerRepository.class);
	Mockito.<Class<?>>when(repoInfo.getDomainType()).thenReturn(TestEntity.class);
	// @formatter:on
	Object repo = this.spannerRepositoryFactory.getTargetRepository(repoInfo);
	assertThat(repo).isInstanceOf(SimpleSpannerRepository.class);
}
 
Example #29
Source File: ReactivePostgresRepositoryFactory.java    From vertx-spring-boot with Apache License 2.0 4 votes vote down vote up
@Override
    protected Object getTargetRepository(RepositoryInformation metadata) {
//        RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(metadata.getDomainType());

        return getTargetRepositoryViaReflection(metadata);
    }
 
Example #30
Source File: IgniteRepositoryFactory.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected Object getTargetRepository(RepositoryInformation metadata) {
    return getTargetRepositoryViaReflection(metadata,
        ignite.getOrCreateCache(repoToCache.get(metadata.getRepositoryInterface())));
}