Java Code Examples for org.springframework.data.repository.core.RepositoryInformation#getDomainType()

The following examples show how to use org.springframework.data.repository.core.RepositoryInformation#getDomainType() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: ArangoRepositoryFactory.java    From spring-data with 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());
}
 
Example 10
Source File: BaseRepositoryFactoryBean.java    From itweet-boot with Apache License 2.0 4 votes vote down vote up
@Override
protected Object getTargetRepository(RepositoryInformation information) {
    return new BaseRepositoryImpl<T, I>((Class<T>) information.getDomainType(), em);
}
 
Example 11
Source File: CustomJpaRepositoryFactoryBean.java    From spring-boot-jpa-data-rest-soft-delete with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected Object getTargetRepository(RepositoryInformation information) {
	return new SoftDeletesRepositoryImpl<T, ID>((Class<T>) information.getDomainType(), entityManager);
}