org.springframework.data.repository.Repository Java Examples

The following examples show how to use org.springframework.data.repository.Repository. 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: RepositoryRestrictionTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
@DisplayName("Testing if environment module's components are using the repositories trough delegated method(s) from the related service")
void testForSingleRepositoryUsage() {
    Set<Class<? extends Repository>> repos = getRepos();
    Set<Class<?>> compos = getServicesAndComponents();
    repos.forEach(repo -> {
        AtomicLong count = new AtomicLong(0);
        Set<String> compoNames = new LinkedHashSet<>();
        compos.forEach(service -> {
            Set<? extends Class<?>> injectedFields = ReflectionUtils.getFields(service)
                    .stream()
                    .map(Field::getType)
                    .collect(toSet());
            if (injectedFields.stream().anyMatch(fieldClass -> fieldClass.equals(repo))) {
                count.addAndGet(1L);
                compoNames.add(service.getSimpleName());
            }
        });
        Assertions.assertTrue(count.get() <= 1, getExceptionMessage(repo.getSimpleName(), compoNames));
    });
}
 
Example #2
Source File: RepositoryRestrictionTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@SuppressWarnings("unchecked")
@MethodSource("testDataProvider")
@DisplayName("Testing if core module's components are using the repositories trough delegated method(s) from the related service")
void testForSingleRepositoryUsage(String basePath) {
    Set<Class<? extends Repository>> repos = getRepos(basePath);
    Set<Class<?>> compos = getServicesAndComponents(basePath);
    repos.forEach(repo -> {
        AtomicLong count = new AtomicLong(0);
        Set<String> compoNames = new LinkedHashSet<>();
        compos.forEach(service -> {
            Set<? extends Class<?>> injectedFields = ReflectionUtils.getFields(service)
                    .stream()
                    .filter(this::isFieldInjected)
                    .map(Field::getType)
                    .collect(toSet());
            if (injectedFields.stream().anyMatch(fieldClass -> fieldClass.equals(repo))) {
                count.addAndGet(1L);
                compoNames.add(service.getSimpleName());
            }
        });
        Assertions.assertTrue(count.get() <= 1, getExceptionMessage(repo.getSimpleName(), compoNames));
    });
}
 
Example #3
Source File: SpringDataJPAProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
void contributeClassesToIndex(BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClasses) {
    // index the Spring Data repository interfaces that extend Repository because we need to pull the generic types from it
    additionalIndexedClasses.produce(new AdditionalIndexedClassesBuildItem(
            Repository.class.getName(),
            CrudRepository.class.getName(),
            PagingAndSortingRepository.class.getName(),
            JpaRepository.class.getName(),
            QueryByExampleExecutor.class.getName()));
}
 
Example #4
Source File: ArangoRepositoryFactory.java    From spring-data with Apache License 2.0 5 votes vote down vote up
@Override
protected RepositoryMetadata getRepositoryMetadata(final Class<?> repositoryInterface) {
	Assert.notNull(repositoryInterface, "Repository interface must not be null!");

	return Repository.class.isAssignableFrom(repositoryInterface)
			? new DefaultArangoRepositoryMetadata(repositoryInterface)
			: new AnnotationArangoRepositoryMetadata(repositoryInterface);
}
 
Example #5
Source File: StatefulFactory.java    From statefulj with Apache License 2.0 5 votes vote down vote up
/**
 * @param entityToRepositoryMapping
 * @param bfName
 * @param bf
 * @throws ClassNotFoundException
 */
private void mapEntityToRepository(Map<Class<?>, String> entityToRepositoryMapping,
		String bfName, BeanDefinition bf) throws ClassNotFoundException {

	// Determine the Entity Class associated with the Repo
	//
	String value = (String)bf.getPropertyValues().getPropertyValue("repositoryInterface").getValue();
	Class<?> repoInterface = Class.forName(value);
	Class<?> entityType = null;
	for(Type type : repoInterface.getGenericInterfaces()) {
		if (type instanceof ParameterizedType) {
			ParameterizedType parmType = (ParameterizedType)type;
			if (Repository.class.isAssignableFrom((Class<?>)parmType.getRawType()) &&
			    parmType.getActualTypeArguments() != null &&
			    parmType.getActualTypeArguments().length > 0) {
				entityType = (Class<?>)parmType.getActualTypeArguments()[0];
				break;
			}
		}
	}

	if (entityType == null) {
		throw new RuntimeException("Unable to determine Entity type for class " + repoInterface.getName());
	}

	// Map Entity to the RepositoryFactoryBeanSupport bean
	//
	logger.debug("Mapped \"{}\" to repo \"{}\", beanId=\"{}\"", entityType.getName(), value, bfName);

	entityToRepositoryMapping.put(entityType, bfName);
}
 
Example #6
Source File: CmisRegistrar.java    From spring-content with Apache License 2.0 4 votes vote down vote up
public CmisEntityRepositoryComponentProvider(String cmisEntityClassName, ClassLoader classLoader) {
	AssignableTypeFilter assignableTypeFilter = new AssignableTypeFilter(Repository.class);
	CmisEntityTypeFilter cmisEntityTypeFilter = new CmisEntityTypeFilter(cmisEntityClassName, classLoader);

	this.addIncludeFilter(new AllTypeFilter(cmisEntityTypeFilter, assignableTypeFilter));
}
 
Example #7
Source File: KeyValueRepositoryFactoryBeanUnitTests.java    From spring-data-keyvalue with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
	this.factoryBean = new KeyValueRepositoryFactoryBean<Repository<Object, Object>, Object, Object>(
			SampleRepository.class);
}
 
Example #8
Source File: RepositoryRestrictionTest.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private Set<Class<? extends Repository>> getRepos() {
    Reflections reflections = new Reflections(RepositoryRestrictionTest.ENVIRONMENT_BASE_PACKAGE);
    return reflections.getSubTypesOf(Repository.class);
}
 
Example #9
Source File: RepositoryRestrictionTest.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private Set<Class<? extends Repository>> getRepos(String basePathForRepos) {
    Reflections reflections = new Reflections(basePathForRepos);
    return reflections.getSubTypesOf(Repository.class);
}