CompanyJuly 5, 2016

DataStax Enterprise Java Driver: 1.0.0 released!

DataStax Enterprise Java Driver: 1.0.0 released!

In this post we are going to focus on the DataStax Enterprise Java Driver 1.0.0.

Overview

The DataStax Enterprise Java Driver 1.0.0 is built on top of the "core" driver and supports additional features provided by DSE 5.0, such as Unified Authentication, Geospatial types, and Graph (more on these below).

From an API perspective, the most noticeable additions in the DataStax Enterprise Java Driver are the dedicated Cluster and Session wrappers, namely, DseCluster and DseSession.

These specialized versions have a few additional capabilities (but they will certainly be enhanced with many more DSE-specific features yet to come):

  1. DseSession can execute graph statements (see below);
  2. DseCluster will by default enable geospatial types (see below);
  3. DseCluster will by default use a special load balancing policy, DseLoadBalancingPolicy, which optimizes query plans for Graph OLAP queries.

Below is an example of how to create a DseCluster and a DseSession:

import com.datastax.driver.dse.DseCluster;
import com.datastax.driver.dse.DseSession;

DseCluster dseCluster = null;
try {
   dseCluster = DseCluster.builder()
           .addContactPoint("127.0.0.1")
           .build();
   DseSession dseSession = dseCluster.connect();

   Row row = dseSession.execute("select release_version from system.local").one();
   System.out.println(row.getString("release_version"));
} finally {
   if (dseCluster != null) dseCluster.close();
}

Upgrading from older DSE drivers

For previous versions of DSE, specific extensions were published as a sub-module of the core Java driver, under the coordinates com.datastax.cassandra:cassandra-driver-dse.

These extensions are now deprecated and will not be maintained anymore. Starting with DSE 5.0, they are superseded by the DataStax Enterprise Java Driver 1.0.0, which is now a standalone project, published under new coordinates: com.datastax.cassandra:dse-driver, and with an independent versioning. It is also compatible with older versions of DSE.

If you were using the legacy driver extensions for DSE, you should now migrate your existing applications to use DataStax Enterprise Java Driver 1.0.0. Please read the Upgrade guide for further instructions.

DSE Unified Authentication

For clients connecting to a DSE cluster secured with DSE Unified Authentication, two authentication providers are included:

  1. DsePlainTextAuthProvider: plain-text authentication;
  2. DseGSSAPIAuthProvider: GSSAPI authentication.

Here is an example of DSE authentication using DseGSSAPIAuthProvider:

import com.datastax.driver.dse.auth.DseGSSAPIAuthProvider;

DseCluster dseCluster = DseCluster.builder()
           .addContactPoint("127.0.0.1")
           .withAuthProvider(new DseGSSAPIAuthProvider())
           .build();

See the javadocs of each implementation for more details.

Geospatial types

DataStax Enterprise 5.0 comes with a set of additional types to represent geospatial data: PointType, LineStringType, and PolygonType. Here is an example of a table containg a column of type PointType:

CREATE TABLE points_of_interest(name text PRIMARY KEY, coords 'PointType');

The CQL literal representing a geospatial type is simply its Well-known Text (WKT) form. Inserting a row into the table above using plain CQL is as easy as:

INSERT INTO points_of_interest (name, coords) VALUES ('Eiffel Tower', 'POINT(48.8582 2.2945)');

Of course, you are not limited to string literals to manipulate geospatial types; the DataStax Enterprise Java Driver 1.0.0 also includes Java representations of these types, which can be sent as query parameters, or retrieved back from query results:

import com.datastax.driver.dse.geometry.Point;

Row row = dseSession.execute("SELECT coords FROM points_of_interest WHERE name = 'Eiffel Tower'").one();
Point coords = row.get("coords", Point.class);
System.out.println(coords.X());

dseSession.execute("INSERT INTO points_of_interest (name, coords) VALUES (?, ?)",
    "Washington Monument", new Point(38.8895, 77.0352));

Please refer to both the DSE 5.0 Geospatial Search documentation and the driver documentation on geospatial types for more details.

DSE Graph

The DataStax Enterprise Java Driver 1.0.0 now supports two different query languages: CQL for interacting with standard Cassandra tables, and Gremlin, the graph traversal language that allows you to interact with DSE Graph.

DseSession has dedicated methods to execute graph queries. These methods accept GraphStatement instances and return a GraphResultSet, which, in turn, can be seen as a tree-like structure where each node is a GraphNode.

Here is a simple example of some graph queries:

import com.datastax.driver.dse.graph.GraphStatement;
import com.datastax.driver.dse.graph.SimpleGraphStatement;

GraphStatement s1 = new SimpleGraphStatement("g.addV(label, 'test_vertex')");
dseSession.executeGraph(s1);

GraphResultSet rs = dseSession.executeGraph("g.V().hasLabel('test_vertex')");
GraphNode n = rs.one();
Vertex vertex = n.asVertex();

Please refer to both the DSE 5.0 Graph documentation and the driver documentation on graph for further information about graph queries.

Getting the driver

The DataStax Enterprise Java Driver binaries are available from Maven Central. If you use Maven, simply add the following dependency to your project:

<dependency>
   <groupId>com.datastax.cassandra</groupId>
   <artifactId>dse-driver</artifactId>
   <version>1.0.0</version>
</dependency>

Beware that the DataStax Enterprise Java Driver is published under specific license terms that allow its usage solely in conjunction with DataStax Enterprise software.

Documentation for the the DataStax Enterprise Java Driver can be found at the following locations:

Note that, for convenience, the API reference includes combined javadocs for both the DataStax Enterprise Java Driver and the core Java Driver for Apache Cassandra.

Share

One-stop Data API for Production GenAI

Astra DB gives JavaScript developers a complete data API and out-of-the-box integrations that make it easier to build production RAG apps with high relevancy and low latency.