Mapping API
The Datastax
Java driver provides a mapping API that helps to map our query results to Java classes. This API is provided as a separate artifact. We're using mapping API version 2.1.4 in our examples, below are dependency details:
// Maven Dependancy <dependency> <groupId>com.datastax.cassandra</groupId> <artifactId>cassandra-driver-mapping</artifactId> <version>2.1.4</version> </dependency> // Gradle Dependancy compile 'com.datastax.cassandra:Cassandra-driver-mapping:2.1.4'
The mapping API provides annotations to map a Java class to a Cassandra table. For example, our Status
class can be mapped to Cassandra table status_updates_by_user
, as in the following example of Status.java
, updated as per the mapping API:
package cassandra.cassandraclient.model; import java.util.Date; import java.util.UUID; import com.datastax.driver.mapping.annotations.Column; import com.datastax.driver.mapping.annotations.PartitionKey; import com...