Skip to content

Instantly share code, notes, and snippets.

@angrycub
Last active October 17, 2017 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save angrycub/853ff1266c059d86d63b to your computer and use it in GitHub Desktop.
Save angrycub/853ff1266c059d86d63b to your computer and use it in GitHub Desktop.
Using User Metadata on a Riak Object
// Build Test Data
IRiakObject cat = RiakObjectBuilder.newBuilder("Pets-Template", "Cat").
withValue("{\"sound\":\"Meow\",\"legs\":4}").
build();
rc.store(cat);
// Build User Metadata Map
Map<String, String> usermeta = new HashMap<String, String>();
usermeta.put("parentLinkBucket", "Pets-Template");
usermeta.put("parentLinkKey", "Cat");
// Store Object
IRiakObject stellaToStore = RiakObjectBuilder.newBuilder("Pets", "Stella").
withValue("{\"owner\":\"Charlie Voiselle\"}").
withUsermeta(usermeta).
build();
rc.store(stellaToStore);
// Fetch Object
IRiakObject pet = rc.fetch("Pets", "Stella").getRiakObjects()[0];
IRiakObject petTemplate = rc.fetch(
pet.getUsermeta("parentlinkbucket"),
pet.getUsermeta("parentlinkkey")).getRiakObjects()[0];
System.out.printf("Pet: %s%nTemplate: %s", pet.getValueAsString(),
petTemplate.getValueAsString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment