use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class CouchbaseArraySet method remove.
@Override
public boolean remove(Object t) {
enforcePrimitive(t);
for (int i = 0; i < arraySetOptions.casMismatchRetries(); i++) {
try {
GetResult result = collection.get(id);
JsonArray current = result.contentAsArray();
long cas = result.cas();
int index = 0;
boolean found = false;
for (Object next : current) {
if (safeEquals(next, t)) {
found = true;
break;
}
index++;
}
String path = "[" + index + "]";
if (!found) {
return false;
} else {
collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(path)), arraySetOptions.mutateInOptions().cas(cas));
return true;
}
} catch (CasMismatchException e) {
// retry
} catch (DocumentNotFoundException ex) {
return false;
}
}
throw new CouchbaseException("CouchbaseArraySet remove failed", new RetryExhaustedException("Couldn't perform remove in less than " + arraySetOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class CouchbaseMap method remove.
@Override
public E remove(Object key) {
String idx = checkKey(key);
for (int i = 0; i < mapOptions.casMismatchRetries(); i++) {
try {
LookupInResult current = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(idx)), lookupInOptions);
long returnCas = current.cas();
E result = current.contentAs(0, entityTypeClass);
collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(idx)), mapOptions.mutateInOptions().cas(returnCas));
return result;
} catch (DocumentNotFoundException | PathNotFoundException e) {
return null;
} catch (CasMismatchException ex) {
// will have to retry get-and-remove
}
}
throw new CouchbaseException("CouchbaseMap remove failed", new RetryExhaustedException("Couldn't perform remove in less than " + mapOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class CouchbaseMap method put.
@Override
public E put(String key, E value) {
checkKey(key);
for (int i = 0; i < mapOptions.casMismatchRetries(); i++) {
try {
long returnCas = 0;
E result = null;
try {
LookupInResult current = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(key)), lookupInOptions);
returnCas = current.cas();
if (current.exists(0)) {
result = current.contentAs(0, entityTypeClass);
}
} catch (PathNotFoundException e) {
// that's ok, we will just upsert anyways, and return null
} catch (DocumentNotFoundException e) {
// we will create an empty doc and remember the cas
returnCas = createEmpty();
}
collection.mutateIn(id, Collections.singletonList(MutateInSpec.upsert(key, value)), mapOptions.mutateInOptions().cas(returnCas));
return result;
} catch (CasMismatchException ex) {
// will need to retry get-and-set
}
}
throw new CouchbaseException("CouchbaseMap put failed", new RetryExhaustedException("Couldn't perform put in less than " + mapOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class CouchbaseQueue method poll.
@Override
public E poll() {
// FIFO queue as offer uses ARRAY_PREPEND
String idx = "[-1]";
for (int i = 0; i < queueOptions.casMismatchRetries(); i++) {
try {
LookupInResult result = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(idx)), lookupInOptions);
E current = result.contentAs(0, entityTypeClass);
long returnCas = result.cas();
collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(idx)), queueOptions.mutateInOptions().cas(returnCas));
return current;
} catch (DocumentNotFoundException | PathNotFoundException ex) {
return null;
} catch (CasMismatchException ex) {
// will have to retry get-and-remove
}
}
throw new CouchbaseException("CouchbaseQueue poll failed", new RetryExhaustedException("Couldn't perform poll in less than " + queueOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class EnhancedPreparedStatementStrategy method prepareAndExecute.
private Mono<QueryResponse> prepareAndExecute(QueryRequest request) {
return // auto-execute!
executeAdhoc(request.toPrepareRequest(true, requestTracer())).flatMap(queryResponse -> {
// intercept the response and pluck out the prepared statement name
String preparedName = queryResponse.header().prepared().orElse(null);
if (preparedName == null) {
return Mono.error(new CouchbaseException("Failed to locate prepared statement name in query response; this is a query bug!"));
}
cache.put(request.statement(), PreparedStatement.enhanced(preparedName));
return Mono.just(queryResponse);
});
}
Aggregations