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

The following examples show how to use org.springframework.data.repository.core.RepositoryInformation. These examples are extracted from open source projects. 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
@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 2
Source Project: dubbox   Source File: SolrRepositoryFactory.java    License: 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 3
Source Project: spring-content   Source File: RepositoryUtils.java    License: 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 4
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 5
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 6
@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 7
Source Project: sdn-rx   Source File: ReactiveNeo4jRepositoryFactory.java    License: 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 8
Source Project: sdn-rx   Source File: Neo4jRepositoryFactory.java    License: 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 9
Source Project: sdn-rx   Source File: Neo4jRepositoryFactoryTest.java    License: 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 10
Source Project: sdn-rx   Source File: ReactiveNeo4jRepositoryFactoryTest.java    License: 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 11
Source Project: web-flash   Source File: BaseRepositoryFactoryBean.java    License: 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 12
Source Project: flash-waimai   Source File: BaseRepositoryFactoryBean.java    License: 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 13
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 14
@Override
protected Object getTargetRepository(RepositoryInformation information) {
    final EntityInformation<?, Serializable> entityInformation =
        getEntityInformation(information.getDomainType());
    return getTargetRepositoryViaReflection(information, entityInformation,
        this.applicationContext);
}
 
Example 15
@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 16
@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 17
@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 18
Source Project: spring-content   Source File: RepositoryUtils.java    License: 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 19
Source Project: spring-content   Source File: RepositoryUtils.java    License: 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 20
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 21
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 22
@Override
public void postProcess(ProxyFactory factory,
		RepositoryInformation repositoryInformation) {

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

}
 
Example 23
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 24
public MybatisBasicMapperBuilder(Configuration configuration,
		RepositoryInformation repositoryInformation,
		PersistentEntity<?, ?> persistentEntity) {

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

}
 
Example 25
Source Project: java-platform   Source File: CustomRepositoryFactoryBean.java    License: 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 26
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 27
Source Project: ignite   Source File: IgniteRepositoryFactory.java    License: 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 28
Source Project: ignite   Source File: IgniteRepositoryFactory.java    License: 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 29
@Override
    protected Object getTargetRepository(RepositoryInformation metadata) {
//        RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(metadata.getDomainType());

        return getTargetRepositoryViaReflection(metadata);
    }
 
Example 30
Source Project: spring-data   Source File: ArangoRepositoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected Object getTargetRepository(final RepositoryInformation metadata) {
	return new SimpleArangoRepository(arangoOperations, metadata.getDomainType());
}