use of com.couchbase.client.core.message.kv.subdoc.multi.Lookup in project try-cb-java by couchbaselabs.
the class Hotel method extractResultOrThrow.
/**
* Extract a FTS result or throw if there is an issue.
*/
private List<Map<String, Object>> extractResultOrThrow(SearchQueryResult result) {
if (!result.status().isSuccess()) {
LOGGER.warn("Query returned with errors: " + result.errors());
throw new DataRetrievalFailureException("Query error: " + result.errors());
}
List<Map<String, Object>> content = new ArrayList<Map<String, Object>>();
for (SearchQueryRow row : result) {
DocumentFragment<Lookup> fragment = bucket.lookupIn(row.id()).get("country").get("city").get("state").get("address").get("name").get("description").execute();
Map<String, Object> map = new HashMap<String, Object>();
String country = (String) fragment.content("country");
String city = (String) fragment.content("city");
String state = (String) fragment.content("state");
String address = (String) fragment.content("address");
StringBuilder fullAddr = new StringBuilder();
if (address != null)
fullAddr.append(address).append(", ");
if (city != null)
fullAddr.append(city).append(", ");
if (state != null)
fullAddr.append(state).append(", ");
if (country != null)
fullAddr.append(country);
if (fullAddr.length() > 2 && fullAddr.charAt(fullAddr.length() - 2) == ',')
fullAddr.delete(fullAddr.length() - 2, fullAddr.length() - 1);
map.put("name", fragment.content("name"));
map.put("description", fragment.content("description"));
map.put("address", fullAddr.toString());
content.add(map);
}
return content;
}
use of com.couchbase.client.core.message.kv.subdoc.multi.Lookup in project jans by JanssenProject.
the class ManualCouchbaseEntryManagerTest method sampleSessionId.
// manual
@Test(enabled = false)
public void sampleSessionId() throws IOException, SearchException {
CouchbaseEntryManager manager = createCouchbaseEntryManager();
try {
SessionId sessionId = createSessionId();
manager.persist(sessionId);
final String key = "sessions_" + sessionId.getId();
System.out.println("Key: " + key + ", ttl:" + sessionId.getTtl());
Bucket sessionBucket = manager.getOperationService().getConnectionProvider().getBucketMapping("sessions").getBucket();
final JsonDocument lookup = sessionBucket.get(key);
System.out.println("expiry: " + lookup.expiry());
DocumentFragment<Lookup> ttl = sessionBucket.lookupIn(key).get("$document.exptime", new SubdocOptionsBuilder().xattr(true)).execute();
System.out.println("ttl: " + ttl.content("$document.exptime"));
updateSession(sessionId);
manager.merge(sessionId);
final JsonDocument lookup2 = manager.getOperationService().getConnectionProvider().getBucketMapping("sessions").getBucket().get(key);
System.out.println("expiry after update: " + lookup2.expiry());
} finally {
manager.destroy();
}
}
Aggregations