question about java client

Paul Ingalls paul at fanzo.me
Tue Jul 30 17:37:11 EDT 2013


I figured out what I was doing.  I had a getter/setter for the fields in addition to the fields themselves, since they were private.  I had to JsonIgnore the getters/setters since I couldn't tag them with the riak annotations.  

Paul Ingalls
Founder & CEO Fanzo
paul at fanzo.me
@paulingalls
http://www.linkedin.com/in/paulingalls



On Jul 30, 2013, at 2:34 PM, Brian Roach <roach at basho.com> wrote:

> Paul,
> 
> The annotated fields are not included in the Serialization using the
> JSONConverter (at least, not in the current version of the client; I
> think I did some fixes around that way back in like v1.0.7). If they
> are, you've got something odd going on in your domain object.
> 
> Here's a (very basic) example:
> 
> public class App3
> {
> 
>    public static void main(String[] args) throws RiakException
>    {
>        IRiakClient client = RiakFactory.pbcClient();
>        Bucket b = client.fetchBucket("test_bucket").execute();
> 
>        MyPojo mp = new MyPojo();
>        mp.key = "key0";
>        mp.value = "This is my value";
> 
>        Set<RiakLink> links = new HashSet<RiakLink>();
>        for (int i = 1; i < 4; i++)
>        {
>            RiakLink link = new RiakLink("test_bucket", "key" + i, "myLinkTag");
>            links.add(link);
>        }
>        mp.links = links;
>        b.store(mp).execute();
> 
>        mp = b.fetch("key0", MyPojo.class).execute();
> 
>        System.out.println(mp.key);
>        System.out.println(mp.value);
>        for (RiakLink link : mp.links)
>        {
>            System.out.println(link.getKey());
>        }
> 
>        client.shutdown();
>    }
> 
> }
> 
> class MyPojo
> {
>    public @RiakKey String key;
>    public @RiakLinks Collection<RiakLink> links;
>    public String value;
> 
> }
> 
> -----------------------
> That outputs:
> 
> key0
> This is my value
> key2
> key3
> key1
> 
> Checking it with curl shows it as it should be:
> 
> roach$ curl -v localhost:8098/buckets/test_bucket/keys/key0
> * About to connect() to localhost port 8098 (#0)
> *   Trying ::1... Connection refused
> *   Trying 127.0.0.1... connected
> * Connected to localhost (127.0.0.1) port 8098 (#0)
>> GET /buckets/test_bucket/keys/key0 HTTP/1.1
>> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8x zlib/1.2.5
>> Host: localhost:8098
>> Accept: */*
>> 
> < HTTP/1.1 200 OK
> < X-Riak-Vclock: a85hYGBgzGDKBVIcypz/fga+nNWUwZTInMfK4Lcq5zRfFgA=
> < Vary: Accept-Encoding
> < Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
> < Link: </buckets/test_bucket/keys/key1>; riaktag="myLinkTag",
> </buckets/test_bucket/keys/key3>; riaktag="myLinkTag",
> </buckets/test_bucket/keys/key2>; riaktag="myLinkTag",
> </buckets/test_bucket>; rel="up"
> < Last-Modified: Tue, 30 Jul 2013 21:21:18 GMT
> < ETag: "1ikpRECrH40O93LxiTmnKz"
> < Date: Tue, 30 Jul 2013 21:21:57 GMT
> < Content-Type: application/json; charset=UTF-8
> < Content-Length: 28
> <
> * Connection #0 to host localhost left intact
> * Closing connection #0
> {"value":"This is my value"}
> 
> 
> 
> On Tue, Jul 30, 2013 at 2:38 PM, Paul Ingalls <paul at fanzo.me> wrote:
>> Hey Brian,
>> 
>> After a bit of messing around, I'm now dropping objects into the correct
>> bucket using the links annotation.  However,  I am noticing that the json is
>> including the metadata from the domain object, i.e. things tagged with
>> @RiakKey, @RiakIndex or @RiakLinks.  I was under the impression this data
>> would be left out.  I wouldn't care a whole lot, but when I'm getting data
>> back in via a fetch, the JSONConverter is crashing saying it doesn't know
>> how to convert the RiakLink object since there isn't an appropriate
>> constructor for it.
>> 
>> Do I need to specifically @JsonIgnore fields tagged with one of the Riak
>> tags?
>> 
>> Thanks!
>> 
>> Paul
>> 
>> 
>> Paul Ingalls
>> Founder & CEO Fanzo
>> paul at fanzo.me
>> @paulingalls
>> http://www.linkedin.com/in/paulingalls
>> 
>> 
>> 
>> On Jul 30, 2013, at 11:20 AM, Paul Ingalls <paul at fanzo.me> wrote:
>> 
>> Ok, thats perfect.  I totally missed the annotation for links…
>> 
>> Will give that a shot…
>> 
>> Thanks!
>> 
>> Paul Ingalls
>> Founder & CEO Fanzo
>> paul at fanzo.me
>> @paulingalls
>> http://www.linkedin.com/in/paulingalls
>> 
>> 
>> 
>> On Jul 30, 2013, at 11:16 AM, Brian Roach <roach at basho.com> wrote:
>> 
>> Paul,
>> 
>> I'm not quite sure I understand what you're asking.
>> 
>> If you do a fetch and have siblings each one is converted to your
>> domain object using the Converter and then passed as a Collection to
>> the ConflictResolver. Each sibling is going to include its links
>> and/or indexes as long as the Converter is injecting them into the
>> domain object and you can resolve them in the ConflictResolver.
>> 
>> The default JSONConverter, for example, injects them into your domain
>> object via annotations from the com.basho.riak.client.convert[1]
>> package.
>> 
>> Thanks,
>> Brian Roach
>> 
>> http://basho.github.io/riak-java-client/1.4.0/com/basho/riak/client/convert/package-summary.html
>> 
>> 
>> On Tue, Jul 30, 2013 at 11:41 AM, Paul Ingalls <paul at fanzo.me> wrote:
>> 
>> Newbie with Riak, and looking at the java client.
>> 
>> Specifically, I've been digging into the domain mapping apis.  Looking into
>> the code, it appears to me that, if I'm using links a bunch or even
>> secondary indexes, that I could lose some data during the conflict
>> resolution phase.  I see where links and other relevant user data gets
>> cached during the conversion phase from the fetch and then patched back in
>> during the conversion phase for the store.  However, it doesn't look like
>> you have the opportunity during the resolution phase to merge metadata.
>> Should I focus on using the raw client, or am I missing something?
>> 
>> Thanks!
>> 
>> Paul
>> 
>> 
>> 
>> 
>> Paul Ingalls
>> Founder & CEO Fanzo
>> paul at fanzo.me
>> @paulingalls
>> http://www.linkedin.com/in/paulingalls
>> 
>> 
>> 
>> 
>> _______________________________________________
>> riak-users mailing list
>> riak-users at lists.basho.com
>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>> 
>> 
>> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20130730/ae5c1db5/attachment.html>


More information about the riak-users mailing list