Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
* <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
* <p>
* A BigIntIndexQuery is used when you are using integers for your 2i keys. The
* parameters are provided as BigInteger values. Use this query if your
* 2i key values exceed that
* which can be stored in a (64 bit) long,
* parameters are provided as BigInteger values. Use this query if your
* 2i key values exceed that
* which can be stored in a (64 bit) long,
* </p>
* <pre class="prettyprint">
* {@code
Expand All @@ -54,7 +54,7 @@ protected IndexConverter<BigInteger> getConverter()
{
return converter;
}

protected BigIntIndexQuery(Init<BigInteger,?> builder)
{
super(builder);
Expand All @@ -78,19 +78,19 @@ public BinaryValue convert(BigInteger input)
}
};
}

@Override
protected RiakFuture<Response, BigIntIndexQuery> executeAsync(RiakCluster cluster)
{
RiakFuture<SecondaryIndexQueryOperation.Response, SecondaryIndexQueryOperation.Query> coreFuture =
executeCoreAsync(cluster);

BigIntQueryFuture future = new BigIntQueryFuture(coreFuture);
coreFuture.addListener(future);
return future;

}

protected final class BigIntQueryFuture extends CoreFutureAdapter<Response, BigIntIndexQuery, SecondaryIndexQueryOperation.Response, SecondaryIndexQueryOperation.Query>
{
public BigIntQueryFuture(RiakFuture<SecondaryIndexQueryOperation.Response, SecondaryIndexQueryOperation.Query> coreFuture)
Expand All @@ -110,7 +110,7 @@ protected BigIntIndexQuery convertQueryInfo(SecondaryIndexQueryOperation.Query c
return BigIntIndexQuery.this;
}
}

protected static abstract class Init<S, T extends Init<S,T>> extends SecondaryIndexQuery.Init<S,T>
{

Expand All @@ -135,7 +135,7 @@ public T withRegexTermFilter(String filter)
throw new IllegalArgumentException("Cannot use term filter with _int query");
}
}

/**
* Builder used to construct a BigIntIndexQuery.
*/
Expand All @@ -151,7 +151,7 @@ public static class Builder extends Init<BigInteger, Builder>
* @param indexName The name of the index in Riak.
* @param coverContext cover context.
*/
public Builder(Namespace namespace, String indexName, byte[] coverContext)
public Builder(Namespace namespace, String indexName, byte[] coverContext)
{
super(namespace, indexName, coverContext);
}
Expand All @@ -160,7 +160,7 @@ public Builder(Namespace namespace, String indexName, byte[] coverContext)
* Construct a Builder for a BigIntIndexQuery with a range.
* <p>
* Note that your index name should not include the Riak {@literal _int} or
* {@literal _bin} extension.
* {@literal _bin} extension.
* <p>
* @param namespace The namespace in Riak to query.
* @param indexName The name of the index in Riak.
Expand All @@ -176,7 +176,7 @@ public Builder(Namespace namespace, String indexName, BigInteger start, BigInteg
* Construct a Builder for a BigIntIndexQuery with a single 2i key.
* <p>
* Note that your index name should not include the Riak {@literal _int} or
* {@literal _bin} extension.
* {@literal _bin} extension.
* <p>
* @param namespace The namespace in Riak to query.
* @param indexName The name of the index in Riak.
Expand All @@ -202,14 +202,14 @@ public BigIntIndexQuery build()
return new BigIntIndexQuery(this);
}
}

public static class Response extends SecondaryIndexQuery.Response<BigInteger>
{
protected Response(Namespace queryLocation, SecondaryIndexQueryOperation.Response coreResponse, IndexConverter<BigInteger> converter)
{
super(queryLocation, coreResponse, converter);
}

@Override
public List<Entry> getEntries()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.basho.riak.client.core.operations.SecondaryIndexQueryOperation;
import com.basho.riak.client.core.query.Location;
import com.basho.riak.client.core.query.Namespace;
import com.basho.riak.client.core.query.indexes.IndexNames;
import com.basho.riak.client.core.util.BinaryValue;
import com.basho.riak.client.core.util.DefaultCharset;

Expand Down Expand Up @@ -120,17 +121,28 @@ protected static abstract class Init<S, T extends Init<S, T>> extends SecondaryI

public Init(Namespace namespace, String indexName, S start, S end)
{
super(namespace, indexName + Type._BIN, start, end);
super(namespace, generateIndexName(indexName), start, end);
}

public Init(Namespace namespace, String indexName, S match)
{
super(namespace, indexName + Type._BIN, match);
super(namespace, generateIndexName(indexName), match);
}

public Init(Namespace namespace, String indexName, byte[] coverContext)
{
super(namespace, indexName + Type._BIN, coverContext);
super(namespace, generateIndexName(indexName), coverContext);
}

private static String generateIndexName(String baseIndexName)
{
if(IndexNames.BUCKET.equalsIgnoreCase(baseIndexName) ||
IndexNames.KEY.equalsIgnoreCase(baseIndexName))
{
return baseIndexName;
}

return baseIndexName + Type._BIN;
}

T withCharacterSet(Charset charset)
Expand Down Expand Up @@ -278,6 +290,10 @@ public String convert(BinaryValue input)
@Override
public BinaryValue convert(String input)
{
if (input == null )
{
return null;
}
return BinaryValue.create(input, charset);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.basho.riak.client.core.operations.SecondaryIndexQueryOperation;
import com.basho.riak.client.core.query.Namespace;
import com.basho.riak.client.core.query.indexes.IndexNames;
import com.basho.riak.client.core.util.BinaryValue;

/**
Expand All @@ -19,18 +20,23 @@
* @author Alex Moore <amoore at basho dot com>
* @since 2.0.7
*/
public class BucketIndexQuery extends RawIndexQuery
public class BucketIndexQuery extends BinIndexQuery
{
private BucketIndexQuery(Init<BinaryValue, Builder> builder)
private BucketIndexQuery(Init<String, Builder> builder)
{
super(builder);
}

public static class Builder extends SecondaryIndexQuery.Init<BinaryValue, Builder>
public static class Builder extends BinIndexQuery.Init<String, Builder>
{
public Builder(Namespace namespace)
{
super(namespace, "$bucket", namespace.getBucketName());
super(namespace, IndexNames.BUCKET, namespace.getBucketName().toStringUtf8());
}

public Builder(Namespace namespace, byte[] coverContext)
{
super(namespace, IndexNames.BUCKET, coverContext);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ protected RiakFuture<Response, IntIndexQuery> executeAsync(RiakCluster cluster)
{
RiakFuture<SecondaryIndexQueryOperation.Response, SecondaryIndexQueryOperation.Query> coreFuture =
executeCoreAsync(cluster);

IntQueryFuture future = new IntQueryFuture(coreFuture);
coreFuture.addListener(future);
return future;

}

protected final class IntQueryFuture extends CoreFutureAdapter<Response, IntIndexQuery, SecondaryIndexQueryOperation.Response, SecondaryIndexQueryOperation.Query>
Expand All @@ -96,7 +96,7 @@ public IntQueryFuture(RiakFuture<SecondaryIndexQueryOperation.Response, Secondar
{
super(coreFuture);
}

@Override
protected Response convertResponse(SecondaryIndexQueryOperation.Response coreResponse)
{
Expand All @@ -109,7 +109,7 @@ protected IntIndexQuery convertQueryInfo(SecondaryIndexQueryOperation.Query core
return IntIndexQuery.this;
}
}

protected static abstract class Init<S, T extends Init<S,T>> extends SecondaryIndexQuery.Init<S,T>
{

Expand All @@ -127,7 +127,7 @@ public Init(Namespace namespace, String indexName, S match)
{
super(namespace, indexName + Type._INT, match);
}

@Override
public T withRegexTermFilter(String filter)
{
Expand Down Expand Up @@ -160,7 +160,7 @@ public Builder(Namespace namespace, String indexName, byte[] coverContext)
* Construct a Builder for a IntIndexQuery with a range.
* <p>
* Note that your index name should not include the Riak {@literal _int} or
* {@literal _bin} extension.
* {@literal _bin} extension.
* <p>
* @param namespace The namespace in Riak to query.
* @param indexName The name of the index in Riak.
Expand All @@ -176,7 +176,7 @@ public Builder(Namespace namespace, String indexName, Long start, Long end)
* Construct a Builder for a IntIndexQuery with a single 2i key.
* <p>
* Note that your index name should not include the Riak {@literal _int} or
* {@literal _bin} extension.
* {@literal _bin} extension.
* <p>
* @param namespace The namespace in Riak to query.
* @param indexName The name of the index in Riak.
Expand All @@ -202,14 +202,14 @@ public IntIndexQuery build()
return new IntIndexQuery(this);
}
}

public static class Response extends SecondaryIndexQuery.Response<Long>
{
protected Response(Namespace queryLocation, SecondaryIndexQueryOperation.Response coreResponse, IndexConverter<Long> converter)
{
super(queryLocation, coreResponse, converter);
}

@Override
public List<Entry> getEntries()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.basho.riak.client.core.operations.SecondaryIndexQueryOperation;
import com.basho.riak.client.core.query.Namespace;
import com.basho.riak.client.core.query.indexes.IndexNames;
import com.basho.riak.client.core.util.BinaryValue;
import com.basho.riak.client.core.util.DefaultCharset;

Expand Down Expand Up @@ -39,7 +40,7 @@ public Builder(Namespace namespace, String start, String end)

public Builder(Namespace namespace, BinaryValue start, BinaryValue end)
{
super(namespace, "$key", start, end);
super(namespace, IndexNames.KEY, start, end);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public abstract static class Response<T>
final protected IndexConverter<T> converter;
final protected SecondaryIndexQueryOperation.Response coreResponse;
final protected Namespace queryLocation;

protected Response(Namespace queryLocation,
SecondaryIndexQueryOperation.Response coreResponse,
IndexConverter<T> converter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.basho.riak.client.core.operations.SecondaryIndexQueryOperation;
import com.basho.riak.client.core.query.Location;
import com.basho.riak.client.core.query.Namespace;
import com.basho.riak.client.core.query.indexes.IndexNames;
import com.basho.riak.client.core.util.BinaryValue;
import com.google.protobuf.ByteString;

Expand Down Expand Up @@ -109,12 +110,12 @@ private static class BuilderFullBucketRead2i extends SecondaryIndexQuery.Init<B
{
public BuilderFullBucketRead2i(Namespace namespace)
{
super(namespace, "$bucket", BinaryValue.create(ByteString.EMPTY.toByteArray()));
super(namespace, IndexNames.BUCKET, namespace.getBucketName());
}

public BuilderFullBucketRead2i(Namespace namespace, byte[] coverageContext)
{
super(namespace, "$bucket", coverageContext);
super(namespace, IndexNames.BUCKET, coverageContext);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.basho.riak.client.core.FutureOperation;
import com.basho.riak.client.core.RiakMessage;
import com.basho.riak.client.core.query.Namespace;
import com.basho.riak.client.core.query.indexes.IndexNames;
import com.basho.riak.client.core.util.BinaryValue;
import com.basho.riak.protobuf.RiakMessageCodes;
import com.basho.riak.protobuf.RiakKvPB;
Expand Down Expand Up @@ -83,7 +84,7 @@ protected SecondaryIndexQueryOperation.Response convert(List<Object> rawResponse
* Also, the $key index queries just ignore return_terms altogether.
*/

if (pbReq.getReturnTerms() && !query.indexName.toString().equalsIgnoreCase("$key"))
if (pbReq.getReturnTerms() && !query.indexName.toString().equalsIgnoreCase(IndexNames.KEY))
{
convertTerms(responseBuilder, pbEntry);
}
Expand Down Expand Up @@ -227,7 +228,7 @@ public Builder(Query query)
.setIndex(ByteString.copyFrom(query.indexName.unsafeGetValue()))
.setReturnTerms(query.returnKeyAndIndex)
.setReturnBody(query.returnBody);

if (query.indexKey != null)
{
pbReqBuilder.setKey(ByteString.copyFrom(query.indexKey.unsafeGetValue()))
Expand All @@ -246,7 +247,7 @@ else if(query.getRangeStart() != null)

pbReqBuilder.setCoverContext(ByteString.copyFrom(query.coverageContext))
.setKey(ByteString.EMPTY)
.setIndex(ByteString.copyFromUtf8("$bucket"))
.setIndex(ByteString.copyFromUtf8(IndexNames.BUCKET))
.clearReturnTerms()
.setQtype(RiakKvPB.RpbIndexReq.IndexQueryType.eq);
}
Expand Down Expand Up @@ -445,7 +446,7 @@ public static class Builder
private Integer timeout;
private byte[] coverageContext;
private boolean returnBody;

/**
* Constructs a builder for a (2i) Query.
* The index name must be the complete name with the _int or _bin suffix.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.basho.riak.client.core.query.indexes;

/**
* Collection of Built-in Riak Secondary Index Names
*/
public class IndexNames
{
/*
The $bucket index name, used to fetch all the keys in a certain bucket.
*/
public static final String BUCKET = "$bucket";

/*
The $key index name, used to fetch a range of keys in a certain bucket.
*/
public static final String KEY = "$key";
}
Loading