Class ComplexKey

  extended by com.couchbase.client.protocol.views.ComplexKey

public final class ComplexKey
extends java.lang.Object

Allows simple definition of complex JSON keys for query inputs. If you use the ComplexKex class, the stored objects ultimately get converted into a JSON string. As a result, make sure your custom objects implement the "toString" method accordingly (unless you work with trivial types like Strings or numbers). Instead of using a constructor, use the static "of" method to generate your objects. You can also use a special empty object or array. Here are some simple examples: // generated JSON: [2012,9,7] ComplexKey.of(2012, 9, 7); // generated JSON: ["Hello","World",5.12] ComplexKey.of("Hello", "World", 5.12); // generated JSON: {} ComplexKey.of(ComplexKey.emptyObject()); // generated JSON: [] ComplexKey.of(ComplexKey.emptyArray()); This was inspired by the Ektorp project, which queries Apache CouchDB.

Method Summary
static java.lang.Object[] emptyArray()
          Returns an empty array of objects.
static java.lang.Object emptyObject()
          Returns a single empty object.
 ComplexKey forceArray(boolean force)
          Force the cast to a JSON array even when there is only one element.
static ComplexKey of(java.lang.Object... components)
          Generate a ComplexKey based on the input Object arguments (varargs).
 java.lang.String toJson()
          Generate a JSON string of the ComplexKey.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail


public static ComplexKey of(java.lang.Object... components)
Generate a ComplexKey based on the input Object arguments (varargs). This method is most often used along with the Query object and done when new a complex key is used as a query input. For example, to query with the array of integers 2012, 9, 5 (a common method of setting up reduceable date queries) one may do something like: ComplexKey.of(2012, 9, 5);

components - List of objects that should be converted
Returns a new instance of ComplexKey


public static java.lang.Object emptyObject()
Returns a single empty object.

Returns the empty object


public static java.lang.Object[] emptyArray()
Returns an empty array of objects.

Returns an empty array of objects


public ComplexKey forceArray(boolean force)
Force the cast to a JSON array even when there is only one element.

force - whether the ComplexKey should be forced to be an array or not.
the current ComplexKey instance.


public java.lang.String toJson()
Generate a JSON string of the ComplexKey. This method is responsible for processing and converting the complex key list and returning it as a JSON string. This string heavily depends on the structure of the stored objects.

the JSON of the underlying complex key

Copyright © 2006-2009 Dustin Sallings, 2009-2012 Couchbase, Inc.