Last active
August 29, 2015 14:01
-
-
Save angrycub/eedca543b0c41339da0e to your computer and use it in GitHub Desktop.
Nonexistent versus Unmodified Objects with the Riak Java Client RawClient
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
| package test; | |
| import java.io.IOException; | |
| import java.util.Date; | |
| import com.basho.riak.client.IRiakObject; | |
| import com.basho.riak.client.RiakException; | |
| import com.basho.riak.client.builders.RiakObjectBuilder; | |
| import com.basho.riak.client.http.RiakClient; | |
| import com.basho.riak.client.raw.FetchMeta; | |
| import com.basho.riak.client.raw.RawClient; | |
| import com.basho.riak.client.raw.RiakResponse; | |
| import com.basho.riak.client.raw.StoreMeta; | |
| import com.basho.riak.client.raw.http.HTTPClientAdapter; | |
| public class App | |
| { | |
| public static void main(String[] args) throws RiakException, IOException { | |
| RiakClient httpClient = new RiakClient("http://127.0.0.1:8098/riak"); | |
| RawClient rc = new HTTPClientAdapter(httpClient); | |
| // Build a sample object | |
| IRiakObject cat = RiakObjectBuilder.newBuilder("Pets", "Cat"). | |
| withValue("Meow").build(); | |
| StoreMeta returnBodyStoreMeta = new StoreMeta.Builder().returnBody(true).build(); | |
| RiakResponse storedCatResponse = rc.store(cat, returnBodyStoreMeta); | |
| Date lastModified = storedCatResponse.getRiakObjects()[0].getLastModified(); | |
| // Fetch the object to see if updated (Should not fetch anything) | |
| FetchMeta myFetchMeta = new FetchMeta.Builder(). | |
| modifiedSince(lastModified).build(); | |
| RiakResponse fetchedCat = rc.fetch("Pets", "Cat", myFetchMeta); | |
| // Try to fetch a nonexistent object | |
| RiakResponse fetchedLemur= rc.fetch("Pets", "Lemur", myFetchMeta); | |
| System.out.printf("fetchedCat.getRiakObjects().length:%d unmodified:%s%n", | |
| fetchedCat.getRiakObjects().length, | |
| fetchedCat.isUnmodified() ); // Unmodified object | |
| System.out.printf("fetchedLemur.getRiakObjects().length:%d unmodified:%s%n", | |
| fetchedLemur.getRiakObjects().length, | |
| fetchedLemur.isUnmodified() ); // Nonexistent 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
| fetchedCat.getRiakObjects().length:0 unmodified:true | |
| fetchedLemur.getRiakObjects().length:0 unmodified:false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1