Database Reference
In-Depth Information
Hotel Application Code
In this section we walk through the code and show how to implement the given design. This is
useful because it illustrates several different API functions in action.
WARNING
The purpose of this sample application is to show how different ideas in Cassandra can be combined. It
is by no means the only way to transfer the relational design into this model. There is a lot of low-level
plumbing here that uses the Thrift API. Thrift is (probably) changing to Avro, so although the basic
ideas here work, you don't want to follow this example in a real application. Instead, check out Chapter 8
and use one of the many available third-party clients for Cassandra, depending on the language that your
application uses and other needs that you have.
The application we're building will do the following things:
1. Create the database structure.
2. Prepopulate the database with hotel and point of interest data. The hotels are stored in
standard column families, and the points of interest are in super column families.
3. Search for a list of hotels in a given city. This uses a secondary index.
4. Select one of the hotels returned in the search, and then search for a list of points of in-
terest near the chosen hotel.
5. Booking the hotel by doing an insert into the Reservation column family should be
straightforward at this point, and is left to the reader.
Space doesn't permit implementing the entire application. But we'll walk through the major parts,
and finishing the implementation is just a matter of creating a variation of what is shown.
Creating the Database
The first step is creating the schema definition. For this example, we'll define the schema in
YAML and then load it, although you could also use client code to define it.
The YAML file shown in Example 4-1 defines the necessary keyspace and column families.
Example4-1.Schema definition in cassandra.yaml
keyspaces:
- name: Hotelier
replica_placement_strategy: org.apache.cassandra.locator.RackUnawareStrategy
replication_factor: 1
Search WWH ::




Custom Search