当前位置: 首页>>代码示例>>Java>>正文


Java CrudRepository类代码示例

本文整理汇总了Java中org.springframework.data.repository.CrudRepository的典型用法代码示例。如果您正苦于以下问题:Java CrudRepository类的具体用法?Java CrudRepository怎么用?Java CrudRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CrudRepository类属于org.springframework.data.repository包,在下文中一共展示了CrudRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hasPermission

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
@Override
public boolean hasPermission(@NotNull Authentication authentication,
                             @NotNull Serializable serializable,
                             @NotNull String className,
                             @NotNull Object permissions) {
    boolean result = false;
    CrudRepository<Object, Serializable> repository = repositoryFinder.find(className);
    if (repository != null) {
        Object targetDomainObject = repository.findOne(serializable);
        if (targetDomainObject instanceof CreatorAware) {
            result = hasPermission(authentication, targetDomainObject, permissions);
        } else if (targetDomainObject == null) {
            result = true;
        }
    }
    return result;
}
 
开发者ID:hmcts,项目名称:document-management-store-app,代码行数:18,代码来源:PermissionEvaluatorImpl.java

示例2: the_database_will_be_empty

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
@Then("^the database will be empty$")
public void the_database_will_be_empty() throws Throwable {
    ClosureService closureService = getBean(ClosureService.class);
    Map<String, CrudRepository> crudRepositories = getBeansOfType(CrudRepository.class);

    for (final Map.Entry<String, CrudRepository> repository : crudRepositories.entrySet()) {
        Closure checkEmpty = new Closure() {
            @Override
            public void execute() throws Exception {
                long entityCount = repository.getValue().count();
                String message = format("%s must be empty but is %s", repository.getKey(), entityCount);
                assertThat(message, entityCount, is(EMPTY));
            }
        };
        closureService.execute(checkEmpty);
    }

}
 
开发者ID:arranbartish,项目名称:d-kom-collaborative,代码行数:19,代码来源:ServiceStepDefinitions.java

示例3: setUpDomainClassAnalyzer

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
public void setUpDomainClassAnalyzer(CrudRepository crudRepository, User user) throws ReflectiveOperationException {
    Map<String, DomainClass> domainMap = new HashMap<>();
    List<String> tablesExpected = new ArrayList<>();
    tablesExpected.add("user");
    DomainClass domainClass = new DomainClass();
    domainClass.setDomainClass(User.class);
    domainClass.setCrudRepository(crudRepository);
    OneToOneRequester cartSQLRequester = new OneToOneRequester();
    cartSQLRequester.setAssociatedField(User.class.getDeclaredField("cart"));
    Map<String, SQLRequester> sqlRequesterMap = new HashMap<>();
    sqlRequesterMap.put("cart", cartSQLRequester);
    domainClass.setSqlRequesters(sqlRequesterMap);
    domainMap.put("user", domainClass);
    when(domainClassAnalyzer.getDomainClassMap()).thenReturn(domainMap);
    when(domainClassAnalyzer.getMappingTablesExpected()).thenReturn(tablesExpected);
    doReturn(user).when(domainClassAnalyzer).generateInstanceFromName("user");
}
 
开发者ID:juanwolf,项目名称:mysql-binlog-replicator,代码行数:18,代码来源:MySQLEventListenerTest.java

示例4: RichObjectRepositoryImpl

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
public RichObjectRepositoryImpl(
        Class<RichObjectType> domainClass,
        Class<RichObjectImplementation> implementationClass,
        Class<EntityType> entityType,
        CrudRepository<EntityType, ID> entityRepository,
        final ApplicationContext applicationContext) {

    this.domainClass = domainClass;
    this.entityRepository = entityRepository;
    this.applicationContext = applicationContext;

    try {
        entityField = findEntityField(implementationClass, entityType);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw propagate(e);
    }

}
 
开发者ID:jelford,项目名称:richobjects,代码行数:19,代码来源:RichObjectRepositoryImpl.java

示例5: find

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
public CrudRepository<Object, Serializable> find(@NotNull String domainClassName) {
    try {
        return this.find(Class.forName(domainClassName));
    } catch (ClassNotFoundException e) {
        throw new RepositoryCouldNotBeFoundException("Could not find a Repository for Domain class: " + domainClassName);
    }
}
 
开发者ID:hmcts,项目名称:document-management-store-app,代码行数:8,代码来源:RepositoryFinder.java

示例6: doInitTestData

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
@Override
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.save(Arrays.asList(playstation, playstation2, superNES, nintendo64));
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:13,代码来源:AdvancedSolrRepositoryTests.java

示例7: run

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
@Override
public void run(String... arg0) throws Exception {

    for (final CrudRepository cr : repositories) {
        System.err.println(getRepositoryName(cr.getClass()) + " has  " + cr.count() + ". <<DBCountRunner>>");
    }

}
 
开发者ID:tvajjala,项目名称:interview-preparation,代码行数:9,代码来源:DBCountRunner.java

示例8: dataImport

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
@Override
public void dataImport(ApplicationContext applicationContext, Map<String, List<Serializable>> importData) {
	for (Entry<String, List<Serializable>> entry : importData.entrySet()) {

		@SuppressWarnings("unchecked")
		CrudRepository<Serializable, Serializable> crudDao = applicationContext.getBean(entry.getKey(), CrudRepository.class);

		crudDao.save(entry.getValue());
	}
}
 
开发者ID:ckwen,项目名称:jeet,代码行数:11,代码来源:BatchImportHandler.java

示例9: shouldCreate

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
@Test
public void shouldCreate() throws Exception {
  CrudRepository<T, UUID> repository = this.getRepository();

  T instance = this.generateInstance();
  Assert.assertNull(instance.getId());

  instance = repository.save(instance);
  assertInstance(instance);

  Assert.assertTrue(repository.exists(instance.getId()));
}
 
开发者ID:OpenLMIS,项目名称:openlmis-stockmanagement,代码行数:13,代码来源:BaseCrudRepositoryIntegrationTest.java

示例10: shouldFindOne

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
@Test
public void shouldFindOne() throws Exception {
  CrudRepository<T, UUID> repository = this.getRepository();

  T instance = this.generateInstance();

  instance = repository.save(instance);
  assertInstance(instance);

  UUID id = instance.getId();

  instance = repository.findOne(id);
  assertInstance(instance);
  Assert.assertEquals(id, instance.getId());
}
 
开发者ID:OpenLMIS,项目名称:openlmis-stockmanagement,代码行数:16,代码来源:BaseCrudRepositoryIntegrationTest.java

示例11: shouldDelete

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
@Test
public void shouldDelete() throws Exception {
  CrudRepository<T, UUID> repository = this.getRepository();

  T instance = this.generateInstance();
  assertNotNull(instance);

  instance = repository.save(instance);
  assertInstance(instance);

  UUID id = instance.getId();

  repository.delete(id);
  Assert.assertFalse(repository.exists(id));
}
 
开发者ID:OpenLMIS,项目名称:openlmis-stockmanagement,代码行数:16,代码来源:BaseCrudRepositoryIntegrationTest.java

示例12: run

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
/**
 * This method is part of CommandLineRunner and is called automatically by Spring.
 * @param args Main method arguments.
 */
public void run(String... args) {
  //Get all JaVers repositories.
  Map<String,Object> repositoryMap =
          applicationContext.getBeansWithAnnotation(JaversSpringDataAuditable.class);

  //For each one...
  for (Object object : repositoryMap.values()) {
    if (object instanceof PagingAndSortingRepository) {
      createSnapshots((PagingAndSortingRepository<?, ?>) object);
    } else if (object instanceof CrudRepository) {
      createSnapshots((CrudRepository<?, ?>) object);
    }
  }
}
 
开发者ID:OpenLMIS,项目名称:openlmis-template-service,代码行数:19,代码来源:AuditLogInitializer.java

示例13: safeGet

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
private <T extends ContentEntity> T safeGet(ContentDto s, CrudRepository<? extends T, UUID> repo, T newEntity) {
    try {
        T entity = repo.findOne(s.getId());
        return entity;
    } catch (Exception e) {
        return newEntity;
    }
}
 
开发者ID:lordoftheflies,项目名称:wonderjameeee,代码行数:9,代码来源:ContentManagementService.java

示例14: updateCollection

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
private <T extends BaseEntity, U> void updateCollection(Collection<T> currentValues,
                                                     Collection<U> updatedValues,
                                                     Supplier<T> newInstance,
                                                     Function<U, String> idFun,
                                                     Function<U, Function<T, T>> updateFunctionSupplier,
                                                     CrudRepository<T, String> repository) {
  Map<String, List<T>> valuesMap = currentValues.stream()
      .collect(Collectors.groupingBy(T::getId));

  List<String> newIds = updatedValues
      .stream()
      .map(newCollectionItem -> {
        Optional<T> existingItem = ofNullable(valuesMap.get(idFun.apply(newCollectionItem)))
            .flatMap(toFirst());

        if (existingItem.isPresent()) {
          return repository.save(updateFunctionSupplier.apply(newCollectionItem).apply(existingItem.get()));
        } else {
          T newItem = newInstance.get();
          repository.save(updateFunctionSupplier.apply(newCollectionItem).apply(newItem));
          currentValues.add(newItem);
          return newItem;
        }
      })
      .map(T::getId)
      .collect(Collectors.toList());

  currentValues
      .stream()
      .filter(notIn(newIds))
      .collect(Collectors.toList())
      .forEach(removeFrom(currentValues, repository));    
}
 
开发者ID:adrobisch,项目名称:putput,代码行数:34,代码来源:ContactService.java

示例15: setUpPerTestBase

import org.springframework.data.repository.CrudRepository; //导入依赖的package包/类
@Before
public final void setUpPerTestBase()
{
	MockitoAnnotations.initMocks(this);

	Map<Class<?>, Repository<?, ?>> repositoriesMap = new HashMap<>();
	repositoriesMap.put(User.class, userRepository);
	repositoriesMap.put(UserAnonymized.class, userAnonymizedRepository);
	repositoriesMap.putAll(getRepositories());
	Set<CrudRepository<?, ?>> crudRepositories = filterForCrudRepositories(repositoriesMap.values());
	crudRepositories.forEach(CrudRepository::deleteAll);
	crudRepositories.stream().filter(this::isMock).forEach(r -> JUnitUtil.setUpRepositoryMock(r));
	JUnitUtil.setUpRepositoryProviderMock(repositoriesMap);
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:15,代码来源:BaseSpringIntegrationTest.java


注:本文中的org.springframework.data.repository.CrudRepository类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。