Book Image

Apache Cassandra Essentials

By : Nitin Padalia
Book Image

Apache Cassandra Essentials

By: Nitin Padalia

Overview of this book

Apache Cassandra Essentials takes you step-by-step from from the basics of installation to advanced installation options and database design techniques. It gives you all the information you need to effectively design a well distributed and high performance database. You’ll get to know about the steps that are performed by a Cassandra node when you execute a read/write query, which is essential to properly maintain of a Cassandra cluster and to debug any issues. Next, you’ll discover how to integrate a Cassandra driver in your applications and perform read/write operations. Finally, you’ll learn about the various tools provided by Cassandra for serviceability aspects such as logging, metrics, backup, and recovery.
Table of Contents (14 chapters)
Apache Cassandra Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...