本文整理匯總了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;
}
示例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);
}
}
示例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");
}
示例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);
}
}
示例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);
}
}
示例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));
}
示例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>>");
}
}
示例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());
}
}
示例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()));
}
示例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());
}
示例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));
}
示例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);
}
}
}
示例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;
}
}
示例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));
}
示例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);
}