當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。