com.basho.riak.client.operations
Class StoreObject<T>

java.lang.Object
  extended by com.basho.riak.client.operations.StoreObject<T>
All Implemented Interfaces:
RiakOperation<T>

public class StoreObject<T>
extends Object
implements RiakOperation<T>

Stores a given object into riak always fetches first.

Use Bucket.store(Object) methods to create a store operation. Also look at DomainBucket.store(Object).

TODO Should fetch first be optional? What about the vclock if not?

Author:
russell
See Also:
Bucket, DomainBucket

Constructor Summary
StoreObject(RawClient client, String bucket, String key, Retrier retrier)
          Create a new StoreObject operation for the object in bucket at key.
 
Method Summary
 StoreObject<T> basicQuorum(boolean basicQuorum)
          fail early if a quorum of error/notfounds are reached before a successful read (for the pre-store fetch)
 StoreObject<T> dw(int dw)
          The durable write quorum for this store operation
 StoreObject<T> dw(Quora dw)
          The durable write quorum for this store operation
 StoreObject<T> dw(Quorum dw)
          The durable write quorum for this store operation
 T execute()
          Fetches data from bucket/key, if item exists it is converted with Converter and any siblings resolved with ConflictResolver.
 StoreObject<T> ifNoneMatch(boolean ifNoneMatch)
          Default is false (i.e.
 StoreObject<T> ifNotModified(boolean ifNotModified)
          Default is false (i.e.
 StoreObject<T> notFoundOK(boolean notFoundOK)
          if notfound_ok counts towards r count (for the pre-store fetch)
 StoreObject<T> pr(int pr)
          The pr for the pre-store fetch
 StoreObject<T> pr(Quora pr)
          The pr for the pre-store fetch
 StoreObject<T> pr(Quorum pr)
          The pr for the pre-store fetch
 StoreObject<T> pw(int pw)
          Set the primary write quorum for the store operation, takes precedence over w.
 StoreObject<T> pw(Quora pw)
          Set the primary write quorum for the store operation, takes precedence over w.
 StoreObject<T> pw(Quorum pw)
          Set the primary write quorum for the store operation, takes precedence over w.
 StoreObject<T> r(int r)
          A store performs a fetch first (to get a vclock and resolve any conflicts), set the read quorum for the fetch
 StoreObject<T> r(Quora r)
          A store performs a fetch first (to get a vclock and resolve any conflicts), set the read quorum for the fetch
 StoreObject<T> r(Quorum r)
          A store performs a fetch first (to get a vclock and resolve any conflicts), set the read quorum for the fetch
 StoreObject<T> returnBody(boolean returnBody)
          Should the store operation return a response body?
 StoreObject<T> returnDeletedVClock(boolean returnDeletedVClock)
          If the object has just been deleted, there maybe a tombstone value vclock, set to true to have this returned in the pre-store fetch.
 StoreObject<T> w(int w)
          Set the write quorum for the store operation
 StoreObject<T> w(Quora w)
          Set the write quorum for the store operation
 StoreObject<T> w(Quorum w)
          Set the write quorum for the store operation
 StoreObject<T> withConverter(Converter<T> converter)
          The Converter to use
 StoreObject<T> withMutator(Mutation<T> mutation)
          The Mutation to apply to the value retrieved from the fetch operation
 StoreObject<T> withResolver(ConflictResolver<T> resolver)
          The ConflictResolver to use on any sibling results returned from the fetch (and store if returnBody is true) NOTE: since it is used for fetch and after store must be reusable.
 StoreObject<T> withRetrier(Retrier retrier)
          The Retrier to use for the fetch and store operations.
 StoreObject<T> withValue(T value)
          Creates a ClobberMutation that applies value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StoreObject

public StoreObject(RawClient client,
                   String bucket,
                   String key,
                   Retrier retrier)
Create a new StoreObject operation for the object in bucket at key.

Use Bucket to create a store operation.

Parameters:
client - the RawClient to use
bucket - location of data to store
key - location of data to store
retrier - the Retrier to use for this operation
Method Detail

execute

public T execute()
          throws RiakRetryFailedException,
                 UnresolvedConflictException,
                 ConversionException
Fetches data from bucket/key, if item exists it is converted with Converter and any siblings resolved with ConflictResolver. Mutation is applied to the result which is then converted back to IRiakObject and stored with the RawClient. If returnBody is true then the returned result is treated like a fetch (converted, conflict resolved) and the resultant object returned.

Specified by:
execute in interface RiakOperation<T>
Returns:
the result of the store if returnBody is true, null if returnBody is false
Throws:
RiakException
{@link - MatchFoundException} if a 'ifNoneMatch' conditional store fails because a match exists
RiakRetryFailedException
UnresolvedConflictException
ConversionException

r

public StoreObject<T> r(int r)
A store performs a fetch first (to get a vclock and resolve any conflicts), set the read quorum for the fetch

Parameters:
r - the read quorum for the pre-store fetch
Returns:
this

r

public StoreObject<T> r(Quora r)
A store performs a fetch first (to get a vclock and resolve any conflicts), set the read quorum for the fetch

Parameters:
r - the read quorum for the pre-store fetch
Returns:
this

r

public StoreObject<T> r(Quorum r)
A store performs a fetch first (to get a vclock and resolve any conflicts), set the read quorum for the fetch

Parameters:
r - the read quorum for the pre-store fetch
Returns:
this

pr

public StoreObject<T> pr(int pr)
The pr for the pre-store fetch

Parameters:
pr -
Returns:
See Also:
FetchObject.pr(int)

pr

public StoreObject<T> pr(Quora pr)
The pr for the pre-store fetch

Parameters:
pr -
Returns:
See Also:
FetchObject.pr(Quora)

pr

public StoreObject<T> pr(Quorum pr)
The pr for the pre-store fetch

Parameters:
pr -
Returns:
See Also:
FetchObject.pr(Quorum)

notFoundOK

public StoreObject<T> notFoundOK(boolean notFoundOK)
if notfound_ok counts towards r count (for the pre-store fetch)

Parameters:
notFoundOK -
Returns:
See Also:
FetchObject.notFoundOK(boolean)

basicQuorum

public StoreObject<T> basicQuorum(boolean basicQuorum)
fail early if a quorum of error/notfounds are reached before a successful read (for the pre-store fetch)

Parameters:
basicQuorum -
Returns:
See Also:
FetchObject.basicQuorum(boolean)

returnDeletedVClock

public StoreObject<T> returnDeletedVClock(boolean returnDeletedVClock)
If the object has just been deleted, there maybe a tombstone value vclock, set to true to have this returned in the pre-store fetch.

Parameters:
returnDeletedVClock -
Returns:
See Also:
FetchObject.returnDeletedVClock(boolean)

pw

public StoreObject<T> pw(int pw)
Set the primary write quorum for the store operation, takes precedence over w.

Parameters:
pw -
Returns:
this

pw

public StoreObject<T> pw(Quora pw)
Set the primary write quorum for the store operation, takes precedence over w.

Parameters:
pw -
Returns:
this

pw

public StoreObject<T> pw(Quorum pw)
Set the primary write quorum for the store operation, takes precedence over w.

Parameters:
pw -
Returns:
this

w

public StoreObject<T> w(int w)
Set the write quorum for the store operation

Parameters:
w -
Returns:
this

w

public StoreObject<T> w(Quora w)
Set the write quorum for the store operation

Parameters:
w -
Returns:
this

w

public StoreObject<T> w(Quorum w)
Set the write quorum for the store operation

Parameters:
w -
Returns:
this

dw

public StoreObject<T> dw(int dw)
The durable write quorum for this store operation

Parameters:
dw -
Returns:
this

dw

public StoreObject<T> dw(Quora dw)
The durable write quorum for this store operation

Parameters:
dw -
Returns:
this

dw

public StoreObject<T> dw(Quorum dw)
The durable write quorum for this store operation

Parameters:
dw -
Returns:
this

returnBody

public StoreObject<T> returnBody(boolean returnBody)
Should the store operation return a response body?

Parameters:
returnBody -
Returns:
this

ifNoneMatch

public StoreObject<T> ifNoneMatch(boolean ifNoneMatch)
Default is false (i.e. NOT a conditional store).

NOTE: This has different meanings depending on the underlying transport.

In the case of the PB interface it means: Only store if there is no bucket/key entry for this object in the database already.

For the HTTP API it means: Only store if there is no entity that matches some etags I provide you

To make this transparent the StoreOperation will pull the etag from the object returned in the pre-store fetch, and use that as supplementary data to the HTTP Store request.

If there is match (b/k or etag) then the operation is *not* retried by the retrier, to override this, provide a custom retrier.

Parameters:
ifNoneMatch - true if you want a conditional store, false otherwise, defaults to false.
Returns:
this

ifNotModified

public StoreObject<T> ifNotModified(boolean ifNotModified)
Default is false (i.e. NOT a conditional store).

NOTE: This has different meanings depending on the underlying transport.

In the case of the PB interface it means: Only store if the vclock provided with the store is the same as the one in Riak for this object (i.e. the object has not been modified since you last got it), of course, since this StoreObject does a fetch before a store the window for concurrent modification is minimized, but this is an extra guard, still.

For the HTTP API it means: Only store if there has been no modification since the provided timestamp.

To make this transparent the StoreOperation will pull the last modified date from the object returned in the pre-store fetch, and use that as supplementary data to the HTTP Store request.

Parameters:
ifNotModified - true if you want a conditional store, false otherwise, defaults to false.
Returns:
this

withRetrier

public StoreObject<T> withRetrier(Retrier retrier)
The Retrier to use for the fetch and store operations.

Parameters:
retrier - a Retrier
Returns:
this

withMutator

public StoreObject<T> withMutator(Mutation<T> mutation)
The Mutation to apply to the value retrieved from the fetch operation

Parameters:
mutation - a Mutation
Returns:
this

withResolver

public StoreObject<T> withResolver(ConflictResolver<T> resolver)
The ConflictResolver to use on any sibling results returned from the fetch (and store if returnBody is true) NOTE: since it is used for fetch and after store must be reusable.

Parameters:
resolver - a ConflictResolver
Returns:
this

withConverter

public StoreObject<T> withConverter(Converter<T> converter)
The Converter to use

Parameters:
converter - a Converter
Returns:
this

withValue

public StoreObject<T> withValue(T value)
Creates a ClobberMutation that applies value

Parameters:
value - new value
Returns:
this StoreObject


Copyright © 2012. All Rights Reserved.