org.springframework.data.repository.CrudRepository Java Examples

The following examples show how to use org.springframework.data.repository.CrudRepository. 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: CmisRepositoryConfigurationImpl.java    From spring-content with Apache License 2.0 6 votes vote down vote up
@Override
public List getChildren(Object parent) {
	List<Object> children = new ArrayList<>();

	for (CrudRepository repo : repositories) {
		String parentProp = null;
		Iterable candidates = repo.findAll();
		for (Object candidate : candidates) {
			if (parentProp == null) {
				parentProp = CmisServiceBridge.findParentProperty(candidate);
			}
			if (parentProp != null) {
				BeanWrapper wrapper = new BeanWrapperImpl(candidate);
				PropertyDescriptor descriptor = wrapper.getPropertyDescriptor(parentProp);
				if (descriptor != null && descriptor.getReadMethod() != null) {
					Object actualParent = ReflectionUtils.invokeMethod(descriptor.getReadMethod(), candidate);
					if (Objects.equals(parent, actualParent)) {
						children.add(candidate);
					}
				}
			}
		}
	}

	return children;
}
 
Example #2
Source File: DbCountMetrics.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Override
public void bindTo(MeterRegistry registry) {
    for (CrudRepository repository : repositories) {
        String name = DbCountRunner.getRepositoryName(repository.getClass());
        String metricName = "counter.datasource." + name;
        Gauge.builder(metricName, repository, CrudRepository::count)
                .tags("name", name)
                .description("The number of entries in " + name + "repository")
                .register(registry);
    }
}
 
Example #3
Source File: DbCountAutoConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public HealthIndicator dbCountHealthIndicator(Collection<CrudRepository> repositories) {
    CompositeHealthIndicator compositeHealthIndicator = new CompositeHealthIndicator(healthAggregator);
    for (CrudRepository repository : repositories) {
        String name = DbCountRunner.getRepositoryName(repository.getClass());
        compositeHealthIndicator.addHealthIndicator(name, new DbCountHealthIndicator(repository));
    }
    return compositeHealthIndicator;
}
 
Example #4
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 #5
Source File: DbCountAutoConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public HealthIndicator dbCountHealthIndicator(Collection<CrudRepository> repositories) {
    CompositeHealthIndicator compositeHealthIndicator = new CompositeHealthIndicator(healthAggregator);
    for (CrudRepository repository : repositories) {
        String name = DbCountRunner.getRepositoryName(repository.getClass());
        compositeHealthIndicator.addHealthIndicator(name, new DbCountHealthIndicator(repository));
    }
    return compositeHealthIndicator;
}
 
Example #6
Source File: DbCountAutoConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public HealthIndicator dbCountHealthIndicator(Collection<CrudRepository> repositories) {
    CompositeHealthIndicator compositeHealthIndicator = new CompositeHealthIndicator(healthAggregator);
    for (CrudRepository repository : repositories) {
        String name = DbCountRunner.getRepositoryName(repository.getClass());
        compositeHealthIndicator.addHealthIndicator(name, new DbCountHealthIndicator(repository));
    }
    return compositeHealthIndicator;
}
 
Example #7
Source File: AlbumRepositoryPopulator.java    From spring-music with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void populate(CrudRepository repository) {
    Object entity = getEntityFromResource(sourceData);

    if (entity instanceof Collection) {
        for (Album album : (Collection<Album>) entity) {
            if (album != null) {
                repository.save(album);
            }
        }
    } else {
        repository.save(entity);
    }
}
 
Example #8
Source File: AdvancedSolrRepositoryTests.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@PostConstruct
protected void doInitTestData(CrudRepository<Product, String> repository) {

	Product playstation = Product.builder().id("id-1").name("Playstation")
			.description("The Sony playstation was the top selling gaming system in 1994.").popularity(5).build();
	Product playstation2 = Product.builder().id("id-2").name("Playstation Two")
			.description("Playstation two is the successor of playstation in 2000.").build();
	Product superNES = Product.builder().id("id-3").name("Super Nintendo").popularity(3).build();
	Product nintendo64 = Product.builder().id("id-4").name("N64").description("Nintendo 64").popularity(2).build();

	repository.saveAll(Arrays.asList(playstation, playstation2, superNES, nintendo64));
}
 
Example #9
Source File: WhiteboardService.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Autowired
public WhiteboardService(CrudRepository<Item, String> repository) {
    this.repository = repository;
}
 
Example #10
Source File: JpaDashboardDao.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<DashboardEntity, String> getCrudRepository() {
    return dashboardRepository;
}
 
Example #11
Source File: JpaDashboardInfoDao.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository getCrudRepository() {
    return dashboardInfoRepository;
}
 
Example #12
Source File: RepositoryCacheLoaderWriterSupportUnitTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
TestRepositoryCacheLoaderWriterSupport(CrudRepository<T, ID> crudRepository) {
	super(crudRepository);
}
 
Example #13
Source File: JpaWidgetsBundleDao.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<WidgetsBundleEntity, String> getCrudRepository() {
    return widgetsBundleRepository;
}
 
Example #14
Source File: JpaTenantDao.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<TenantEntity, String> getCrudRepository() {
  return tenantRepository;
}
 
Example #15
Source File: StackJobAdapter.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends CrudRepository<Stack, Long>> getRepositoryClassForResource() {
    return StackRepository.class;
}
 
Example #16
Source File: CrudRepositoryLookupService.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
protected List<CrudRepository<?, ?>> getRepositoryList() {
    return repositoryList;
}
 
Example #17
Source File: ACLController.java    From spring-data-rest-acl with Apache License 2.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.POST, value = "/acl/user/generic/")
public @ResponseBody HttpEntity<List<String>> addACLUserGeneric(
		@RequestBody UserACLRequestSet aclSet) {
	List<String> result = new ArrayList<String>();
	try {
		SecurityACLDAO securityACLDAO = beanFactory.getBean(
				Constants.SECURITYACL_DAO, SecurityACLDAO.class);

		logger.debug("entityList size:" + aclSet.getAclList().size());
		String entityId = null;
		for (UserACLRequest acl : aclSet.getAclList()) {
			entityId = acl.getEntityId();
			String repoName = classToRepoMap.get(acl.getEntityClassName());
			CrudRepository repo = getRepo(repoName);
			AbstractSecuredEntity securedEntity = (AbstractSecuredEntity) repo
					.findOne(Long.parseLong(entityId));
			if (securedEntity == null) {
				result.add("Entity of type " + acl.getEntityClassName()
						+ " with id " + acl.getEntityId() + " not found");
				continue;
			}
			UserEntity userEntity = userEntityRepo.findByUsername(acl
					.getUserName());
			if (userEntity == null) {
				result.add("User " + acl.getUserName() + " not found");
				continue;
			}
			boolean res = securityACLDAO.addAccessControlEntry(
					securedEntity,
					new PrincipalSid(userEntity.getUsername()),
					getPermissionFromNumber(acl.getPermission()));
			if (res) {
				// on sucess don't add msg to result list
				logger.debug("Added ACL for:" + acl.toString());
			} else {
				result.add("Failed to add ACL for:" + acl.toString());
			}
		}
	} catch (Exception e) {
		logger.warn("", e);
		result.add("Exception:" + e.getMessage());
	}
	if (result.isEmpty()) {
		result.add("Successfully added all ACLs");
		return new ResponseEntity<List<String>>(result, HttpStatus.OK);
	} else {
		return new ResponseEntity<List<String>>(result, HttpStatus.OK);
	}
}
 
Example #18
Source File: EnvironmentJobAdapter.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends CrudRepository<Environment, Long>> getRepositoryClassForResource() {
    return EnvironmentRepository.class;
}
 
Example #19
Source File: JpaBaseRuleDao.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<RuleMetaDataEntity, String> getCrudRepository() {
    return ruleMetaDataRepository;
}
 
Example #20
Source File: JpaBaseEventDao.java    From Groza with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<EventEntity, String> getCrudRepository() {
    return eventRepository;
}
 
Example #21
Source File: JpaTenantDao.java    From Groza with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<TenantEntity, String> getCrudRepository() {
    return tenantRepository;
}
 
Example #22
Source File: CrudRepositoryFinderImpl.java    From statefulj with Apache License 2.0 4 votes vote down vote up
public CrudRepositoryFinderImpl(CrudRepository<T, Serializable> repo) {
	this.repo = repo;
}
 
Example #23
Source File: StackJobAdapter.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends CrudRepository> getRepositoryClassForResource() {
    return StackRepository.class;
}
 
Example #24
Source File: JpaAlarmDao.java    From Groza with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<AlarmEntity, String> getCrudRepository() {
    return alarmRepository;
}
 
Example #25
Source File: JpaUserDao.java    From Groza with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<UserEntity, String> getCrudRepository() {
    return userRepository;
}
 
Example #26
Source File: JpaUserCredentialsDao.java    From Groza with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<UserCredentialsEntity, String> getCrudRepository() {
    return userCredentialsRepository;
}
 
Example #27
Source File: JpaAuditLogDao.java    From Groza with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<AuditLogEntity, String> getCrudRepository() {
    return auditLogRepository;
}
 
Example #28
Source File: JpaDeviceDao.java    From Groza with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<DeviceEntity, String> getCrudRepository() {
    return deviceRepository;
}
 
Example #29
Source File: ACLController.java    From spring-data-rest-acl with Apache License 2.0 4 votes vote down vote up
private CrudRepository getRepo(String repoName) {
	return (CrudRepository) beanFactory.getBean(repoName);
}
 
Example #30
Source File: JpaUserDao.java    From iotplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected CrudRepository<UserEntity, String> getCrudRepository() {
    return userRepository;
}