use of com.couchbase.client.java.kv.GetResult in project ShedLock by lukas-krecan.
the class CouchbaseLockProviderIntegrationTest method assertLocked.
@Override
public void assertLocked(String lockName) {
GetResult result = bucket.defaultCollection().get(lockName);
JsonObject lockDocument = result.contentAsObject();
assertThat(parse((String) lockDocument.get(LOCK_UNTIL))).isAfter(now());
assertThat(parse((String) lockDocument.get(LOCKED_AT))).isBeforeOrEqualTo(now());
assertThat(lockDocument.get(LOCKED_BY)).asString().isNotEmpty();
}
use of com.couchbase.client.java.kv.GetResult in project couchbase-jvm-clients by couchbase.
the class EntityGetWithProjection method main.
public static void main(String... args) {
Cluster cluster = Cluster.connect("127.0.0.1", "Administrator", "password");
Bucket bucket = cluster.bucket("travel-sample");
Collection collection = bucket.defaultCollection();
String id = "p01";
GetResult result = collection.get(id, getOptions().project("name", "age", "attributes.hair"));
Person person = result.contentAs(Person.class);
System.out.println(person.name());
System.out.println(person.age());
System.out.println(person.attributes().hair());
}
use of com.couchbase.client.java.kv.GetResult in project couchbase-jvm-clients by couchbase.
the class EntityUpsertAndGet method main.
public static void main(String... args) {
/*
* Connect to the cluster and open a collection to work with.
*/
Cluster cluster = Cluster.connect("127.0.0.1", "Administrator", "password");
Bucket bucket = cluster.bucket("travel-sample");
Collection collection = bucket.defaultCollection();
final String id = "p01";
Person person = new Person("Joan Deere", 28, Arrays.asList("kitty", "puppy"), new Person.Attributes("brown", new Person.Dimensions(65, 120), Collections.singletonList(new Person.Hobby("winter", "Curling", new Person.Details(new Person.Location(37.338207, -121.886330))))));
collection.upsert(id, person, upsertOptions().expiry(Duration.ofDays(1)));
GetResult getResult = collection.get(id, getOptions().timeout(Duration.ofSeconds(10)));
Person read = getResult.contentAs(Person.class);
System.out.println("Person read: " + read);
}
use of com.couchbase.client.java.kv.GetResult in project couchbase-jvm-clients by couchbase.
the class Get method main.
public static void main(String... args) {
/*
* Connect to the cluster and open a collection to work with.
*/
Cluster cluster = Cluster.connect("127.0.0.1", "Administrator", "password");
Bucket bucket = cluster.bucket("travel-sample");
Collection collection = bucket.defaultCollection();
try {
System.out.println("Found Airport: " + collection.get("airport_1291"));
} catch (DocumentNotFoundException ex) {
System.out.println("Airport not found!");
}
// -------------------------------------------------------------------------------------
/*
* If only a couple fields of a document are needed (a projection), then this can be provided
* through the options.
*/
GetResult airline = collection.get("airline_10", getOptions().project("airportname", "country"));
System.out.println("Found airline with fields: " + airline);
// -------------------------------------------------------------------------------------
/*
* In the previous examples, the expiration field has always been empty on the GetResult.
* If you need to fetch the expiration time of a document, you can also pass it via the
* options.
*/
GetResult airline2 = collection.get("airline_10", getOptions().withExpiry(true));
System.out.println("Expiration is: " + airline2.expiry());
}
use of com.couchbase.client.java.kv.GetResult in project couchbase-jvm-clients by couchbase.
the class KeyValueErrorIntegrationTest method verifyUnlockCasMismatch.
/**
* Ignored for the mock because it still returns TMPFAIL (like the old servers)
*/
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void verifyUnlockCasMismatch() {
String id = UUID.randomUUID().toString();
collection.upsert(id, "foo");
GetResult result = collection.getAndLock(id, Duration.ofSeconds(5));
CasMismatchException thrown = assertThrows(CasMismatchException.class, () -> collection.unlock(id, result.cas() + 1));
assertNotNull(thrown.context());
}
Aggregations