Book Image

Apache Karaf Cookbook

By : Jamie Goodyear, Johan Edstorm, Achim Nierbeck, Heath J Kesler
Book Image

Apache Karaf Cookbook

By: Jamie Goodyear, Johan Edstorm, Achim Nierbeck, Heath J Kesler

Overview of this book

Table of Contents (17 chapters)
Apache Karaf Cookbook
About the Authors
About the Reviewers

Modeling data with Apache Cassandra

Before we start writing a bundle using Apache Cassandra, let's look a little at how we model data in Cassandra using CQL 3.x.

Getting ready

Let's define a very simple schema, and as we are using CQL, Cassandra isn't schema-less from a client perspective even if the data storage internally works slightly differently.

We can reuse the RecipeService class from the previous chapter. We will just modify it slightly for our Cassandra integration. The original entity (and by virtue of using JPA) provides a basic table definition, which is as follows:

@Column(nullable = false)
private String title;

private String ingredients;

So, we have two fields in this table: an ID field named title and a data field we call ingredients for consistency and simplicity.

First, we need a place to store this. Cassandra partitions data in keyspaces at the top level. Think of a keyspace as a map containing tables and their rules.

How to do it…

We'll need to perform...