All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.basho.riak.client.api.commands.StoreSchema Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package com.basho.riak.client.api.commands;

import com.basho.riak.client.api.RiakCommand;
import com.basho.riak.client.core.RiakCluster;
import com.basho.riak.client.core.RiakFuture;
import com.basho.riak.client.core.operations.YzPutSchemaOperation;
import com.basho.riak.client.core.query.search.YokozunaSchema;

import java.util.concurrent.ExecutionException;

 /*
 * @author Dave Rusek 
 * @since 2.0
 */
public final class StoreSchema extends RiakCommand
{
	private final YokozunaSchema schema;

	StoreSchema(Builder builder)
	{
		this.schema = builder.schema;
	}

	@Override
    protected RiakFuture executeAsync(RiakCluster cluster)
    {
        RiakFuture coreFuture =
            cluster.execute(buildCoreOperation());
        
        CoreFutureAdapter future =
            new CoreFutureAdapter(coreFuture)
            {
                @Override
                protected Void convertResponse(Void coreResponse)
                {
                    return coreResponse;
                }

                @Override
                protected YokozunaSchema convertQueryInfo(YokozunaSchema coreQueryInfo)
                {
                    return coreQueryInfo;
                }
            };
        coreFuture.addListener(future);
        return future;
    }

    private YzPutSchemaOperation buildCoreOperation()
    {
        return new YzPutSchemaOperation.Builder(schema).build();
    }

    public static class Builder
	{
		private final YokozunaSchema schema;

		public Builder(YokozunaSchema schema)
		{
			this.schema = schema;
		}

		public StoreSchema build()
		{
			return new StoreSchema(this);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy