Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2013 Basho Technologies Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.basho.riak.client.api.commands.kv;
import com.basho.riak.client.api.RiakCommand;
import com.basho.riak.client.api.cap.VClock;
import com.basho.riak.client.api.commands.ListenableFuture;
import com.basho.riak.client.api.convert.ConversionException;
import com.basho.riak.client.api.convert.reflection.AnnotationUtil;
import com.basho.riak.client.core.RiakCluster;
import com.basho.riak.client.core.RiakFuture;
import com.basho.riak.client.core.RiakFutureListener;
import com.basho.riak.client.core.query.Location;
import com.basho.riak.client.core.query.RiakObject;
import com.fasterxml.jackson.core.type.TypeReference;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* Perform an full cycle update of a Riak value: fetch, resolve, modify, store.
*
*
* The UpdateValue command completely encapsulates the typical read/modify/write
* cycle used with data in Riak.
*
*
The object specified by the given {@link com.basho.riak.client.core.query.Location}
* will be fetched from Riak and have the {@link com.basho.riak.client.api.cap.ConflictResolver} stored in
* the {@link com.basho.riak.client.api.cap.ConflictResolverFactory} applied. The resolved
* object is then passed to your {@link com.basho.riak.client.api.commands.kv.UpdateValue.Update}
* and the result stored back into Riak.
*
*
* To create the mutation you wish to perform, you extend the
* {@link com.basho.riak.client.api.commands.kv.UpdateValue.Update} class:
*
*
* {@code
* class AppendUpdate extends UpdateValue.Update
* {
* private final String update;
*
* public AppendUpdate(String update)
* {
* this.update = update;
* }
*
* {@literal @Override}
* public MyPojo apply(MyPojo original)
* {
* if (original == null)
* {
* original = new MyPojo();
* }
*
* original.value += update;
* return original;
* }
* }
*
* Namespace ns = new Namespace("my_type", "my_bucket");
* Location loc = new Location(ns, "my_key");
* AppendUpdate update = new AppendUpdate("append this string");
*
* UpdateValue uv =
* new UpdateValue.Builder(loc).withUpdate(update).build();
*
* UpdateValue.Response response = client.execute(uv);}
*
* @author Dave Rusek
* @since 2.0
*/
public final class UpdateValue extends RiakCommand
{
private final Location location;
private final Update> update;
private final TypeReference> typeReference;
private final Map, Object> fetchOptions = new HashMap<>();
private final Map, Object> storeOptions = new HashMap<>();
UpdateValue(Builder builder)
{
this.location = builder.location;
this.update = builder.update;
this.typeReference = builder.typeReference;
this.fetchOptions.putAll(builder.fetchOptions);
this.storeOptions.putAll(builder.storeOptions);
}
@SuppressWarnings("unchecked")
@Override
protected RiakFuture executeAsync(final RiakCluster cluster)
{
final UpdateValueFuture updateFuture = new UpdateValueFuture(location);
FetchValue.Builder fetchBuilder = new FetchValue.Builder(location);
for (Map.Entry, Object> optPair : fetchOptions.entrySet())
{
fetchBuilder.withOption((FetchValue.Option