use of org.springframework.data.couchbase.core.RemoveResult in project spring-data-couchbase by spring-projects.
the class CouchbaseRepositoryQueryIntegrationTests method saveNotBounded.
@Test
public void saveNotBounded() {
// save() followed by query with NOT_BOUNDED will result in not finding the document
Airport vie = new Airport("airports::vie", "vie", "low9");
Airport airport2 = null;
for (int i = 1; i <= 100; i++) {
// set version == 0 so save() will be an upsert, not a replace
Airport saved = airportRepository.save(vie.clearVersion());
try {
airport2 = airportRepository.iata(saved.getIata());
if (airport2 == null) {
break;
}
} catch (DataRetrievalFailureException drfe) {
//
airport2 = null;
} finally {
// airportRepository.delete(vie);
// instead of delete, use removeResult to test QueryOptions.consistentWith()
RemoveResult removeResult = couchbaseTemplate.removeById().one(vie.getId());
assertEquals(vie.getId(), removeResult.getId());
assertTrue(removeResult.getCas() != 0);
assertTrue(removeResult.getMutationToken().isPresent());
Airport airport3 = airportRepository.iata(vie.getIata());
assertNull(airport3, "should have been removed");
}
}
assertNull(airport2, "airport2 should have likely been null at least once");
Airport saved = airportRepository.save(vie.clearVersion());
couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).all();
airport2 = airportRepository.iata(vie.getIata());
RemoveResult removeResult = couchbaseTemplate.removeById().one(saved.getId());
assertNotNull(airport2, "airport2 should have been found");
}
use of org.springframework.data.couchbase.core.RemoveResult in project spring-data-couchbase by spring-projects.
the class CouchbaseRepositoryQueryIntegrationTests method saveNotBoundedRequestPlus.
@Test
public void saveNotBoundedRequestPlus() {
airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(REQUEST_PLUS)).deleteAll();
ApplicationContext ac = new AnnotationConfigApplicationContext(ConfigRequestPlus.class);
// the Config class has been modified, these need to be loaded again
CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
AirportRepository airportRepositoryRP = (AirportRepository) ac.getBean("airportRepository");
// save() followed by query with NOT_BOUNDED will result in not finding the document
Airport vie = new Airport("airports::vie", "vie", "low9");
Airport airport2 = null;
for (int i = 1; i <= 100; i++) {
// set version == 0 so save() will be an upsert, not a replace
Airport saved = airportRepositoryRP.save(vie.clearVersion());
try {
airport2 = airportRepositoryRP.iata(saved.getIata());
if (airport2 == null) {
break;
}
} catch (DataRetrievalFailureException drfe) {
//
airport2 = null;
} finally {
// airportRepository.delete(vie);
// instead of delete, use removeResult to test QueryOptions.consistentWith()
RemoveResult removeResult = couchbaseTemplateRP.removeById().one(vie.getId());
assertEquals(vie.getId(), removeResult.getId());
assertTrue(removeResult.getCas() != 0);
assertTrue(removeResult.getMutationToken().isPresent());
Airport airport3 = airportRepositoryRP.iata(vie.getIata());
assertNull(airport3, "should have been removed");
}
}
assertNotNull(airport2, "airport2 should have never been null");
Airport saved = airportRepositoryRP.save(vie.clearVersion());
List<Airport> airports = couchbaseTemplateRP.findByQuery(Airport.class).withConsistency(NOT_BOUNDED).all();
RemoveResult removeResult = couchbaseTemplateRP.removeById().one(saved.getId());
assertFalse(!airports.isEmpty(), "airports should have been empty");
}
use of org.springframework.data.couchbase.core.RemoveResult in project spring-data-couchbase by spring-projects.
the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method removeByQueryAll.
@Test
void removeByQueryAll() {
User user1 = new User(UUID.randomUUID().toString(), "user1", "user1");
User user2 = new User(UUID.randomUUID().toString(), "user2", "user2");
couchbaseTemplate.upsertById(User.class).inScope(scopeName).inCollection(collectionName).all(Arrays.asList(user1, user2));
assertTrue(couchbaseTemplate.existsById().inScope(scopeName).inCollection(collectionName).one(user1.getId()));
assertTrue(couchbaseTemplate.existsById().inScope(scopeName).inCollection(collectionName).one(user2.getId()));
List<RemoveResult> result = couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).all();
assertEquals(2, result.size(), "should have deleted user1 and user2");
assertNull(couchbaseTemplate.findById(User.class).inScope(scopeName).inCollection(collectionName).one(user1.getId()));
assertNull(couchbaseTemplate.findById(User.class).inScope(scopeName).inCollection(collectionName).one(user2.getId()));
}
use of org.springframework.data.couchbase.core.RemoveResult in project spring-data-couchbase by spring-projects.
the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method removeByQuery.
@Test
public void removeByQuery() {
// 8
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowe")).block();
List<RemoveResult> removeResults = template.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName).withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all().collectList().block();
assertEquals(saved.getId(), removeResults.get(0).getId());
}
use of org.springframework.data.couchbase.core.RemoveResult in project spring-data-couchbase by spring-projects.
the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method removeByQueryOther.
@Test
public void removeByQueryOther() {
// 8
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lown")).block();
List<RemoveResult> removeResults = template.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection).withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all().collectList().block();
assertEquals(saved.getId(), removeResults.get(0).getId());
}
Aggregations