INTRODUCTION

Apache Cassandra is a wide-column data store. Cassandra is a non-relational database, also called a NoSQL database. Cassandra is based on a flexible schema. The top-level container of Cassandra is called a keyspace, which is equivalent to a schema in a relational database. The top-level data structure for storing data is called a column family or a table. A column family (or table) consists of columns, a column being the smallest increment of data. A Cassandra table is similar to a relational database table in that both have rows and columns. What makes Cassandra different is that the table structure is flexible— that is, not fixed, as in a relational database. Different rows may have different columns. While column metadata for the different columns in a table can be specified in a table definition, the actual data contained in a table is determined by the client application. The schema is flexible in that a row may not contain a particular column or any column at all. Or, a row may include columns not defined in the column’s specification. Cassandra is ranked first among wide-column data stores.

Cassandra is a NoSQL data store based on the wide-column data model. NoSQL databases are increasingly replacing relational databases because of their inherent advantages of a flexible schema, ease of use, integration with Web applications, scalability, and integration with Apache Hadoop. Cassandra is ranked second among NoSQL databases. Cassandra is ranked 10th among all databases (relational or non-relational).

While several books on Cassandra administration are available, none are available that cover Cassandra development. This book is about Apache Cassandra Web development. It discusses all aspects of using Cassandra in applications. Java, PHP, Ruby, and JavaScript are the most commonly used programming/scripting languages, and this book discusses using these languages to access Cassandra. This book also discusses migrating MongoDB server and Couchbase server, two other NoSQL databases, to Cassandra.

The objective of this book is to discuss how a Web developer would develop Web applications with Apache Cassandra. This book covers all aspects of application development, including the following:

Images Setting the environment for an application

Images Creating sample data

Images Running a sample application

WHAT THIS BOOK COVERS

In Chapter 1, “Using Cassandra with Hector,” you learn how to use the Hector Java client to access Cassandra and create a CRUD (create, read, update, delete) application in the Eclipse IDE.

Chapter 2, “Querying Cassandra with CQL,” introduces the Cassandra Query Language (CQL), which is similar in syntax to SQL. It discusses the INSERT, SELECT, UPDATE, WHERE, BATCH, and DELETE clauses in CQL, with an example. Chapter 2 is based on CQL 2.

Chapter 3, “Using Cassandra with DataStax Java Driver,” discusses using CQL 3 with the Datastax Java client in the Eclipse IDE. In addition to CRUD, it discusses the support for running an Async query and a prepared statement query.

In Chapter 4, “Using Apache Cassandra with PHP,” you learn to use a PHP library for Cassandra called phpcassa to connect to Cassandra from a PHP application. You will create a keyspace and column family and add data to the table with PHP. The chapter also discusses adding data in a batch. You will fetch data using the different PHP functions for getting data as multiple columns, column slices, and ranges of columns. The chapter also discusses updating and deleting Cassandra data in a PHP application.

In Chapter 5, “Using a Ruby Client with Cassandra,” you will use a Ruby client with Cassandra to create a keyspace and table (column family) and to add data to the table, including adding data in a batch. You will fetch data in various modes—in single row, in multiple rows, and in a range of rows. The chapter also introduces the ordered partitioner before discussion updating and deleting data and updating or dropping a column family and a keyspace.

Chapter 6, “Using Node.js with Cassandra,” discusses the Node.js driver for Cassandra for connecting to Cassandra and running CRUD operations. It discusses filtering a query and running a prepared query. It also discusses the support for streaming a field and streaming the complete result to a text file.

Chapter 7, “Migrating MongoDB to Cassandra,” discusses migrating a MongoDB document store to Cassandra. MongoDB is a BSON (binary JSON) based document model. First, you will create a document in MongoDB. Then you will use a MongoDB Java client to access MongoDB, fetch data, and migrate the data to Cassandra using the Hector Java client.

Chapter 8, “Migrating Couchbase to Cassandra,” discusses migrating data from Couchbase Server to Cassandra. Couchbase Server is based on the JSON document model. First, you will create a JSON document in Couchbase using the Couchbase Administration Console. Then you will access Couchbase Server using the Couchbase Java client and migrate Couchbase data to Cassandra using the Hector Java client.

Chapter 9, “Using Cassandra with Kundera,” introduces Kundera, a JPA 2.0–complaint object–data store mapping library for NoSQL data stores. In this chapter, you will create a JPA project, a JPA entity class, and a JPA client class in the Eclipse IDE. Then you will configure the object–data store mapping in the persistence.xml file. Finally, you will run CRUD operations on Cassandra using the JPA application.

In Chapter 10, “Using Spring Data with Cassandra,” you will use Apache Cassandra with the Spring Data project. You will create a Maven project in the Eclipse IDE to run CRUD operations on Cassandra with Spring Data.

WHAT YOU NEED FOR THIS BOOK

This book uses Apache Cassandra 2.04. You can download Apache Cassandra 2 from http://cassandra.apache.org/download/. The latest Cassandra version may be used instead of the version in this book. This book also uses the Eclipse IDE for Java EE developers, which you can download from https://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/lunar.

Apart from Apache Cassandra, which is used in all the chapters, and the Eclipse IDE, which is used for Java-based applications, the other software required is chapter specific. For example, for migrating Couchbase Server data, Couchbase Server is required.

This book uses the Windows operating system, but if you have Linux installed, this book may still be used (though the source code and samples have not been tested with Linux). Slight modifications may be required with the Linux install. For example, the directory paths on Linux would be different from the Windows directory paths used in this book.

You also need to install Java for Java-based chapters. Java SE 7 is used in this book.

WHO THIS BOOK IS FOR

This book’s target audience is NoSQL Web developers who want to learn about using Apache Cassandra as a data store. This book is suitable for professional NoSQL developers as well as beginners. This book is also suitable for an intermediate-level or advanced-level course in NoSQL Web development with Cassandra. The target audience is expected to have prior, albeit beginner-level to intermediate-level, knowledge about the languages (Java, PHP, Ruby, and JavaScript) and technologies (Node.js, JPA, Spring Data) used in this book. This book also requires some familiarity with the Eclipse IDE.

COMPANION WEBSITE DOWNLOADS

You may download the companion website files from www.cengageptr.com/downloads.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.22.164