-
-
Save binarytemple/cc54ae75ea23b3909bdb59286011d980 to your computer and use it in GitHub Desktop.
Using User Metadata on a Riak Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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