Database Reference
In-Depth Information
Mutation zipMut = new Mutation();
zipMut.column_or_supercolumn = zipCosc;
//set up the batch
Map<byte[], Map<String, List<Mutation>>> cambriaMutationMap =
new HashMap<byte[], Map<String, List<Mutation>>>();
Map<String, List<Mutation>> cambriaMuts =
new HashMap<String, List<Mutation>>();
List<Mutation> cambriaCols = new ArrayList<Mutation>();
cambriaCols.add(nameMut);
cambriaCols.add(phoneMut);
cambriaCols.add(addressMut);
cambriaCols.add(cityMut);
cambriaCols.add(stateMut);
cambriaCols.add(zipMut);
cambriaMuts.put(columnFamily, cambriaCols);
//outer map key is a row key
//inner map key is the column family name
cambriaMutationMap.put(cambriaKey.getBytes(), cambriaMuts);
return cambriaMutationMap;
}
}
This is a rather long example, but it attempts to show something more than “hello, world”—there
are a number of insert and batch_mutate operations shown with standard column families
and super column families. I have also included multiple rows for each type so that more soph-
isticated queries are required.
This class is the first to execute in our sample application, and once the prepopulate method is
complete, your database will have all the data that the search functions need to work with.
The Search Application
Example 4-7 is the Java class with the main method that you should execute. It relies on Log4J,
so you'll want to point to your log4j.propertiesile when you run it. All you have to do is run
this class, and the database gets prepopulated with all of the hotel and point of interest informa-
tion; then, it allows the user to search for hotels in a given city. The user picks one hotel, and the
application fetches the nearby points of interest. You can then implement the remaining parts of
the application to book a reservation if you like.
Example4-7.HotelApp.java
Search WWH ::




Custom Search