The 1.1.0 release adds all features and tools neded to work against Couchbase Server 2.0 with Java.
This especially includes support for the brand-new view engine. The following list includes the major features and bugfixes compared to the 1.0.* releases. For more detailed release notes, see the developer preview and beta releases.
Also, the Getting Started Guide and the Tutorial have been updated and can be used together with the 1.1.0 release.
New Features and Behaviour Changes in 1.1.0
This release adds the possibility of providing a durability setting that allows to make sure data is replicated but not persisted. This may speed up operations while allowing to maintain a reasonable safety net at the same time (wait until the operation has been replicated to the given number of nodes). Also, every command takes either ReplicateTo, PersistTo or both.
Here is an usage example of an add operation which makes sure to replicate to at least one node:
// With ReplicateTo only client.add("mykey", 0, "value", ReplicateTo.ONE); // Identical to this client.add("mykey", 0, "value", PersistTo.ZERO, ReplicateTo.ONE);
Support for spatial view queries has been added to the SDK. Not that at this stage, spatial view queries are expermimental and should be treated as such. Since spatial queries differ a little bit from classic map/reduce ones, a new "bbox" param has been added to the Query object as well to accomodate the needs. Note that there has been taken lots of care not to break the current API by adding this feature. The main difference to normal map/reduce is to use the "getSpatialView" method instead of the "getView" method on the CouchbaseClient object. Here is a short example on how to use it:
SpatialView view = client.getSpatialView("my_design", "my_spatial_view"); Query query = new Query(); ViewResponse response = client.query(view, query); for(ViewRow row : response) { // Work with bbox data: row.getBbox(); // Work with geometry data: row.getGeometry(); // Work with the value: row.getValue(); }
Issues: JCBC-136
ComplexKey querying support has been enhanced and is now more flexible when it comes to Long values, nulls and others.
View Query Timeouts can now be configured through the
CouchbaseConnectionFactoryBuilder (using the
setViewTimeout() method).
Issues: JCBC-168
A new ComplexKey class has ben added as a utility to define view query options. This makes it possible to convert Java types into their corresponding JSON representations as easy as possible. Also, this avoids the need to encode the values by hand to encode them properly. Passing in a string does still work, but the ComplexKey approach is recommended when working with arrays or other more complex JSON structures.
Here is a short example on how to use it properly:
// JSON Result: 100 ComplexKey.of(100); // JSON Result: "Hello" ComplexKey.of("Hello"); // JSON Result: ["Hello", "World"] ComplexKey.of("Hello", "World"); // JSON Result: [1349360771542,1] ComplexKey.of(new Date().getTime(), 1);
When querying a view it looks like this:
long now = new Date().getTime(); long tomorrow = now + 86400; Query query = new Query(); query.setRange(ComplexKey.of(now), ComplexKey.of(tomorrow)); // Converts to: ?startkey=1349362647742&endkey=1349362734142
The Views functionality has been added to the Couchbase-client library. Views is available starting with Couchbase Server 2.0. For more details on this feature refer to Couchbase Server Manual.
The purpose of a view is take the structured data stored within your Couchbase Server database as JSON documents, extract the fields and information that is needed, and to produce an index of the selected information. The result is a view on the stored data.
The view that is created during this process can be iterated,
selected and queried with the information in the database from
the raw data objects that have been stored using Java objects
such as View, Query,
ViewFuture, ViewResponse
and ViewRow.
The following code fragment illustrates how to use the objects and access the view.
Query query = new Query(); query.setReduce(false); query.setIncludeDocs(true); query.setStale(Stale.FALSE); // Specify the design and document (by default production mode) View view = client.getView("chat", "messages"); if (view == null) { // Take corrective action } ViewResponse result = client.query(view, query); Iterator<ViewRow> itr = result.iterator(); ViewRow row; while (itr.hasNext()) { row = itr.next(); String doc = (String) row.getDocument(); // Do something for each row }
Starting from this beta release, it is now possible to manage design documents through the SDK as well. Design documents can be created, loaded and deleted through their corresponding methods from the CouchbaseClient class. Use the "createDesignDoc()" and "deleteDesignDoc()" methods for creating or deleting design documents as a whole. Here is a short example on how to use it:
List<ViewDesign> views = new ArrayList<ViewDesign>(); List<SpatialViewDesign> spviews = new ArrayList<SpatialViewDesign>(); ViewDesign view1 = new ViewDesign( "view1", "function(a, b) {}" ); views.add(view1); SpatialViewDesign spview = new SpatialViewDesign( "spatialfoo", "function(map) {}" ); spviews.add(spview); DesignDocument doc = new DesignDocument("mydesign", views, spviews); Boolean success = client.createDesignDoc(doc);
Note that creating design documents may take some time, so make sure to wait some time and poll with "getDesignDocument()" to see if it is already correctly loaded.
Issues: JCBC-63
When no replicas are defined in the cluster and a node fails (or more nodes fail at the same time than replicas are defined), then it is possible that there is no single master responsible for a given vbucket. This has been a problem in previous tests and is now handled that a RuntimeException is thrown which a explanatory message. Since the cluster may now be in a very bad state, it is up to the developer at the application level to ensure the correct behavior of the following operation (since this may be very different depending on the application requirements).
Issues: JCBC-123
Netty has been upgraded to 3.5.5.
Issues: JCBC-106
Operation Status message has been changed from hard coded value to be based on tunable parameters.
Issues: JCBC-107
When using memcache-type buckets instead of couchbase-type buckets, the reconfiguration should now work as expected. The client previously tried to compare the vbuckets all the time, but since memcache-type buckets don't contain vbuckets it failed (now only the server nodes themselves are compared).
Issues: JCBC-35
The flush() command now works over HTTP, but
is currently not working because of an open issue inside
Couchbase Server 2.0 (MB-7381). A workaround is to use the
ClusterManager with Administrator privileges in the meantime.
Issues: JCBC-144