DATACOUCH-305 - Adapt to API changes in repository interfaces.

This commit is contained in:
Oliver Gierke
2017-05-03 15:03:14 +02:00
parent 78bfd771b1
commit 22205678ef
18 changed files with 90 additions and 102 deletions

View File

@@ -79,8 +79,8 @@ public class N1qlCouchbaseRepositoryTests {
@After
public void cleanUp() {
try { itemRepository.delete(KEY_ITEM); } catch (DataRetrievalFailureException e) {}
try { partyRepository.delete(KEY_PARTY); } catch (DataRetrievalFailureException e) {}
try { itemRepository.deleteById(KEY_ITEM); } catch (DataRetrievalFailureException e) {}
try { partyRepository.deleteById(KEY_PARTY); } catch (DataRetrievalFailureException e) {}
}
@Test

View File

@@ -75,9 +75,9 @@ public class N1qlCrudRepositoryTests {
@After
public void cleanUp() {
try { itemRepository.delete(KEY_ITEM); } catch (DataRetrievalFailureException e) {}
try { partyRepository.delete(KEY_PARTY); } catch (DataRetrievalFailureException e) {}
try { partyRepository.delete(KEY_PARTY_KEYWORD); } catch (DataRetrievalFailureException e) {}
try { itemRepository.deleteById(KEY_ITEM); } catch (DataRetrievalFailureException e) {}
try { partyRepository.deleteById(KEY_PARTY); } catch (DataRetrievalFailureException e) {}
try { partyRepository.deleteById(KEY_PARTY_KEYWORD); } catch (DataRetrievalFailureException e) {}
}
@Test

View File

@@ -53,7 +53,7 @@ public class QueryDerivationConversionTests {
@Test
public void testConvertsDateParameterInN1qlQuery() {
Optional<Party> partyApril = repository.findOne("testparty-3");
Optional<Party> partyApril = repository.findById("testparty-3");
assertTrue(partyApril.isPresent());
Calendar cal = Calendar.getInstance();

View File

@@ -71,8 +71,8 @@ public class ReactiveN1qlCouchbaseRepositoryTests {
@After
public void cleanUp() {
try { itemRepository.delete(KEY_ITEM); } catch (DataRetrievalFailureException e) {}
try { partyRepository.delete(KEY_PARTY); } catch (DataRetrievalFailureException e) {}
try { itemRepository.deleteById(KEY_ITEM); } catch (DataRetrievalFailureException e) {}
try { partyRepository.deleteById(KEY_PARTY); } catch (DataRetrievalFailureException e) {}
}
@Test

View File

@@ -16,12 +16,14 @@
package org.springframework.data.couchbase.repository;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.error.CASMismatchException;
import com.couchbase.client.java.error.DocumentDoesNotExistException;
import com.couchbase.client.java.view.Stale;
import com.couchbase.client.java.view.ViewQuery;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
@@ -35,7 +37,6 @@ import org.springframework.data.annotation.Version;
import org.springframework.data.couchbase.IntegrationTestApplicationConfig;
import org.springframework.data.couchbase.core.AsyncUtils;
import org.springframework.data.couchbase.core.CouchbaseQueryExecutionException;
import org.springframework.data.couchbase.core.CouchbaseTemplateTests;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping;
import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactory;
@@ -45,15 +46,12 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
import static org.junit.Assert.*;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.error.CASMismatchException;
import com.couchbase.client.java.error.DocumentDoesNotExistException;
import com.couchbase.client.java.view.Stale;
import com.couchbase.client.java.view.ViewQuery;
/**
* @author Michael Nitschinger
@@ -99,19 +97,19 @@ public class SimpleCouchbaseRepositoryTests {
User instance = new User(key, "foobar", 22);
repository.save(instance);
Optional<User> found = repository.findOne(key);
Optional<User> found = repository.findById(key);
assertTrue(found.isPresent());
found.ifPresent(actual -> {
assertEquals(instance.getKey(), actual.getKey());
assertEquals(instance.getUsername(), actual.getUsername());
assertTrue(repository.exists(key));
assertTrue(repository.existsById(key));
repository.delete(actual);
});
assertFalse(repository.findOne(key).isPresent());
assertFalse(repository.exists(key));
assertFalse(repository.findById(key).isPresent());
assertFalse(repository.existsById(key));
}
@Test
@@ -220,7 +218,7 @@ public class SimpleCouchbaseRepositoryTests {
versionedDataRepository.save(initial);
assertNotEquals(0L, initial.version);
Optional<VersionedData> fetch1 = versionedDataRepository.findOne(key);
Optional<VersionedData> fetch1 = versionedDataRepository.findById(key);
assertTrue(fetch1.isPresent());
fetch1.ifPresent(actual -> {
@@ -267,7 +265,7 @@ public class SimpleCouchbaseRepositoryTests {
boolean updated = false;
while(!updated) {
long counterValue = counter.incrementAndGet();
VersionedData messageData = versionedDataRepository.findOne(key).get();
VersionedData messageData = versionedDataRepository.findById(key).get();
messageData.data = "value-" + counterValue;
try {
versionedDataRepository.save(messageData);
@@ -281,7 +279,7 @@ public class SimpleCouchbaseRepositoryTests {
};
AsyncUtils.executeConcurrently(5, task);
assertNotEquals(initial.data, versionedDataRepository.findOne(key).get().data);
assertNotEquals(initial.data, versionedDataRepository.findById(key).get().data);
assertEquals(5, updatedCounter.intValue());
}

View File

@@ -15,32 +15,31 @@
*/
package org.springframework.data.couchbase.repository;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.error.DocumentDoesNotExistException;
import com.couchbase.client.java.view.Stale;
import com.couchbase.client.java.view.ViewQuery;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.couchbase.IntegrationTestApplicationConfig;
import org.springframework.data.couchbase.ReactiveIntegrationTestApplicationConfig;
import org.springframework.data.couchbase.core.CouchbaseQueryExecutionException;
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping;
import org.springframework.data.couchbase.repository.support.ReactiveCouchbaseRepositoryFactory;
import org.springframework.data.couchbase.repository.support.IndexManager;
import org.springframework.data.couchbase.repository.support.ReactiveCouchbaseRepositoryFactory;
import org.springframework.data.repository.core.support.ReactiveRepositoryFactorySupport;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.error.DocumentDoesNotExistException;
import com.couchbase.client.java.view.Stale;
import com.couchbase.client.java.view.ViewQuery;
/**
* @author Subhashni Balakrishnan
@@ -83,15 +82,15 @@ public class SimpleReactiveCouchbaseRepositoryTests {
ReactiveUser instance = new ReactiveUser(key, "foobar", 22);
repository.save(instance).block();
ReactiveUser found = repository.findOne(key).block();
ReactiveUser found = repository.findById(key).block();
assertEquals(instance.getKey(), found.getKey());
assertEquals(instance.getUsername(), found.getUsername());
assertTrue(repository.exists(key).block());
assertTrue(repository.existsById(key).block());
repository.delete(found).block();
assertNull(repository.findOne(key).block());
assertFalse(repository.exists(key).block());
assertNull(repository.findById(key).block());
assertFalse(repository.existsById(key).block());
}
@Test

View File

@@ -36,13 +36,13 @@ public class AuditingTests {
@Test
public void testCreationEventIsRegistered() {
assertFalse(repository.exists(KEY));
assertFalse(repository.existsById(KEY));
Date start = new Date();
AuditedItem item = new AuditedItem(KEY, "creation");
auditorAware.setAuditor("auditor");
repository.save(item);
Optional<AuditedItem> persisted = repository.findOne(KEY);
Optional<AuditedItem> persisted = repository.findById(KEY);
assertTrue(persisted.isPresent());
@@ -64,7 +64,7 @@ public class AuditingTests {
@Test
public void testUpdateEventIsRegistered() {
assertFalse(repository.exists(KEY));
assertFalse(repository.existsById(KEY));
String expectedCreator = "user1";
String expectedUpdater = "user2";
@@ -72,11 +72,11 @@ public class AuditingTests {
auditorAware.setAuditor(expectedCreator);
repository.save(item);
AuditedItem created = repository.findOne(KEY).orElse(null);
AuditedItem created = repository.findById(KEY).orElse(null);
auditorAware.setAuditor(expectedUpdater);
repository.save(item);
AuditedItem updated = repository.findOne(KEY).orElse(null);
AuditedItem updated = repository.findById(KEY).orElse(null);
assertNotNull("expected entity to be persisted", updated);
assertNotNull("expected creation date audit trail", updated.getCreationDate());

View File

@@ -88,9 +88,9 @@ public class CdiRepositoryTests {
repository.save(bean);
assertTrue(repository.exists(bean.getId()));
assertTrue(repository.existsById(bean.getId()));
Optional<Person> retrieved = repository.findOne(bean.getId());
Optional<Person> retrieved = repository.findById(bean.getId());
assertTrue(retrieved.isPresent());
retrieved.ifPresent(actual -> {
assertEquals(bean.getName(), actual.getName());
@@ -110,9 +110,9 @@ public class CdiRepositoryTests {
qualifiedPersonRepository.save(bean);
assertTrue(qualifiedPersonRepository.exists(bean.getId()));
assertTrue(qualifiedPersonRepository.existsById(bean.getId()));
Optional<Person> retrieved = qualifiedPersonRepository.findOne(bean.getId());
Optional<Person> retrieved = qualifiedPersonRepository.findById(bean.getId());
assertTrue(retrieved.isPresent());
retrieved.ifPresent(actual -> {
assertEquals(bean.getName(), actual.getName());

View File

@@ -85,13 +85,13 @@ public class RepositoryCustomMethodTest {
@Before
public void initData() {
try { repository.delete(KEY); } catch (Exception e) { }
try { repository.deleteById(KEY); } catch (Exception e) { }
repository.save(new MyItem(KEY, "new item for custom count"));
}
@After
public void clearData() {
repository.delete(KEY);
repository.deleteById(KEY);
}
@Test

View File

@@ -174,12 +174,12 @@ public class IndexedRepositoryTests {
repository.save(foo2);
int count = 0;
for (Object o : repository.findAll(Arrays.asList("foo1", "foo2"))) {
for (Object o : repository.findAllById(Arrays.asList("foo1", "foo2"))) {
count++;
}
assertEquals(2L, count);
count = 0;
for (Object o : repository.findAll(Arrays.asList("foo1", "foo3"))) {
for (Object o : repository.findAllById(Arrays.asList("foo1", "foo3"))) {
count++;
}
assertEquals(1L, count);

View File

@@ -128,9 +128,9 @@ public class RepositoryTemplateWiringTests {
assertNotNull(repositoryB);
assertNotNull(repositoryC);
boolean existA = repositoryA.exists("testA");
boolean existB = repositoryB.exists("testB");
Optional<Misc> valueC = repositoryC.findOne("toto");
boolean existA = repositoryA.existsById("testA");
boolean existB = repositoryB.existsById("testB");
Optional<Misc> valueC = repositoryC.findById("toto");
assertTrue(existA);
assertFalse(existB);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013, 2014 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,19 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.couchbase.repository.query;
import org.springframework.data.repository.core.EntityInformation;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import java.io.Serializable;
/**
* Marker interface for the Couchbase Entity Information.
*
* @author Michael Nitschinger
* @author Oliver Gierke
*/
public interface CouchbaseEntityInformation<T, ID extends Serializable> extends EntityInformation<T, ID> {
}
public interface CouchbaseEntityInformation<T, ID> extends EntityInformation<T, ID> {}

View File

@@ -111,7 +111,7 @@ public class CouchbaseRepositoryFactory extends RepositoryFactorySupport {
* @return entity information for that domain class.
*/
@Override
public <T, ID extends Serializable> CouchbaseEntityInformation<T, ID> getEntityInformation(final Class<T> domainClass) {
public <T, ID> CouchbaseEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
CouchbasePersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
return new MappingCouchbaseEntityInformation<T, ID>((CouchbasePersistentEntity<T>) entity);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.couchbase.repository.support;
import java.io.Serializable;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
import org.springframework.data.couchbase.repository.query.CouchbaseEntityInformation;
import org.springframework.data.repository.core.support.PersistentEntityInformation;
@@ -26,18 +23,17 @@ import org.springframework.data.repository.core.support.PersistentEntityInformat
* Entity Information container.
*
* @author Michael Nitschinger
* @author Oliver Grieke
* @author Oliver Gierke
*/
public class MappingCouchbaseEntityInformation<T, ID extends Serializable>
extends PersistentEntityInformation<T, ID>
implements CouchbaseEntityInformation<T, ID> {
public class MappingCouchbaseEntityInformation<T, ID> extends PersistentEntityInformation<T, ID>
implements CouchbaseEntityInformation<T, ID> {
/**
* Create a new Information container.
*
* @param entity the entity of the container.
*/
public MappingCouchbaseEntityInformation(final CouchbasePersistentEntity<T> entity) {
public MappingCouchbaseEntityInformation(CouchbasePersistentEntity<T> entity) {
super(entity);
}
}

View File

@@ -97,7 +97,7 @@ public class ReactiveCouchbaseRepositoryFactory extends ReactiveRepositoryFactor
* @return entity information for that domain class.
*/
@Override
public <T, ID extends Serializable> CouchbaseEntityInformation<T, ID> getEntityInformation(final Class<T> domainClass) {
public <T, ID> CouchbaseEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
CouchbasePersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
return new MappingCouchbaseEntityInformation<T, ID>((CouchbasePersistentEntity<T>) entity);

View File

@@ -89,7 +89,7 @@ public class SimpleCouchbaseRepository<T, ID extends Serializable> implements Co
}
@Override
public <S extends T> Iterable<S> save(Iterable<S> entities) {
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
Assert.notNull(entities, "The given Iterable of entities must not be null!");
List<S> result = new ArrayList<S>();
@@ -101,19 +101,19 @@ public class SimpleCouchbaseRepository<T, ID extends Serializable> implements Co
}
@Override
public Optional<T> findOne(ID id) {
public Optional<T> findById(ID id) {
Assert.notNull(id, "The given id must not be null!");
return Optional.ofNullable(couchbaseOperations.findById(id.toString(), entityInformation.getJavaType()));
}
@Override
public boolean exists(ID id) {
public boolean existsById(ID id) {
Assert.notNull(id, "The given id must not be null!");
return couchbaseOperations.exists(id.toString());
}
@Override
public void delete(ID id) {
public void deleteById(ID id) {
Assert.notNull(id, "The given id must not be null!");
couchbaseOperations.remove(id.toString());
}
@@ -125,7 +125,7 @@ public class SimpleCouchbaseRepository<T, ID extends Serializable> implements Co
}
@Override
public void delete(Iterable<? extends T> entities) {
public void deleteAll(Iterable<? extends T> entities) {
Assert.notNull(entities, "The given Iterable of entities must not be null!");
for (T entity : entities) {
couchbaseOperations.remove(entity);
@@ -142,7 +142,7 @@ public class SimpleCouchbaseRepository<T, ID extends Serializable> implements Co
}
@Override
public Iterable<T> findAll(final Iterable<ID> ids) {
public Iterable<T> findAllById(final Iterable<ID> ids) {
final ResolvedView resolvedView = determineView();
ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName());
query.reduce(false);

View File

@@ -101,14 +101,14 @@ public class SimpleReactiveCouchbaseRepository<T, ID extends Serializable> imple
@SuppressWarnings("unchecked")
@Override
public <S extends T> Flux<S> save(Iterable<S> entities) {
public <S extends T> Flux<S> saveAll(Iterable<S> entities) {
Assert.notNull(entities, "The given Iterable of entities must not be null!");
return mapFlux(operations.save(entities));
}
@SuppressWarnings("unchecked")
@Override
public <S extends T> Flux<S> save(Publisher<S> entityStream) {
public <S extends T> Flux<S> saveAll(Publisher<S> entityStream) {
Assert.notNull(entityStream, "The given Iterable of entities must not be null!");
return Flux.from(entityStream)
.flatMap(object -> save(object));
@@ -116,7 +116,7 @@ public class SimpleReactiveCouchbaseRepository<T, ID extends Serializable> imple
@SuppressWarnings("unchecked")
@Override
public Mono<T> findOne(ID id) {
public Mono<T> findById(ID id) {
Assert.notNull(id, "The given id must not be null!");
return mapMono(operations.findById(id.toString(), entityInformation.getJavaType()).toSingle())
.onErrorResume(throwable -> {
@@ -130,24 +130,24 @@ public class SimpleReactiveCouchbaseRepository<T, ID extends Serializable> imple
@SuppressWarnings("unchecked")
@Override
public Mono<T> findOne(Mono<ID> mono) {
public Mono<T> findById(Mono<ID> mono) {
Assert.notNull(mono, "The given mono must not be null!");
return mono.flatMap(
this::findOne);
this::findById);
}
@SuppressWarnings("unchecked")
@Override
public Mono<Boolean> exists(ID id) {
public Mono<Boolean> existsById(ID id) {
Assert.notNull(id, "The given id must not be null!");
return mapMono(operations.exists(id.toString()).toSingle());
}
@SuppressWarnings("unchecked")
@Override
public Mono<Boolean> exists(Mono<ID> mono) {
public Mono<Boolean> existsById(Mono<ID> mono) {
return mono.flatMap(
this::exists);
this::existsById);
}
@SuppressWarnings("unchecked")
@@ -162,7 +162,7 @@ public class SimpleReactiveCouchbaseRepository<T, ID extends Serializable> imple
@SuppressWarnings("unchecked")
@Override
public Flux<T> findAll(final Iterable<ID> ids) {
public Flux<T> findAllById(final Iterable<ID> ids) {
final ResolvedView resolvedView = determineView();
ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName());
query.reduce(false);
@@ -177,15 +177,15 @@ public class SimpleReactiveCouchbaseRepository<T, ID extends Serializable> imple
@SuppressWarnings("unchecked")
@Override
public Flux<T> findAll(Publisher<ID> entityStream) {
public Flux<T> findAllById(Publisher<ID> entityStream) {
Assert.notNull(entityStream, "The given entityStream must not be null!");
return Flux.from(entityStream)
.flatMap(entity -> findOne(entity));
.flatMap(entity -> findById(entity));
}
@SuppressWarnings("unchecked")
@Override
public Mono<Void> delete(ID id) {
public Mono<Void> deleteById(ID id) {
Assert.notNull(id, "The given id must not be null!");
return mapMono(operations.remove(id.toString()).map(res -> Observable.<Void>empty()).toSingle());
}
@@ -199,7 +199,7 @@ public class SimpleReactiveCouchbaseRepository<T, ID extends Serializable> imple
@SuppressWarnings("unchecked")
@Override
public Mono<Void> delete(Iterable<? extends T> entities) {
public Mono<Void> deleteAll(Iterable<? extends T> entities) {
Assert.notNull(entities, "The given Iterable of entities must not be null!");
return mapMono(operations
.remove(entities)
@@ -209,7 +209,7 @@ public class SimpleReactiveCouchbaseRepository<T, ID extends Serializable> imple
@Override
public Mono<Void> delete(Publisher<? extends T> entityStream) {
public Mono<Void> deleteAll(Publisher<? extends T> entityStream) {
Assert.notNull(entityStream, "The given publisher of entities must not be null!");
return Flux.from(entityStream)
.flatMap(entity -> delete(entity)).single();

View File

@@ -88,7 +88,7 @@ public class RepositoryIndexUsageTest {
@Test
public void testFindAllKeysUsesViewWithConfiguredConsistency() {
String expectedQueryParams = "ViewQuery(string/all){params=\"reduce=false&stale=false\", keys=\"[\"someKey\"]\"}";
repository.findAll(Collections.singleton("someKey"));
repository.findAllById(Collections.singleton("someKey"));
verify(couchbaseOperations, never()).queryView(any(ViewQuery.class));
verify(couchbaseOperations, never()).findByN1QL(any(N1qlQuery.class), any(Class.class));