Loren Curtis
2013-12-17 10:39:20 UTC
I recently created a Java CQL 3.0 based client library to make it easier to
develop against Cassandra. I created the library as part of a Cassandra
based web framework that I was creating so that I could abstract out all of
the schema management and just have my code work with simple objects. This
freed me up from having to manually create column families, add columns,
add indexes, etc. I also had a need to be able to search against
multi-valued properties so I added that functionality as well.
If anyone here is interested in taking a look at what I've done I would
love some feedback. Even if that feedback is that you hate it and think I
should delete it all immediately I'd still love to hear why.
You can find the full project page with the source and examples on github
at:
https://github.com/lorenc/Fido
Javadoc can be found at:
http://lorenc.github.io/Fido/
A few simple examples are below. None of the examples require any
columns/indexes/keyspaces be defined ahead of time in the database. In
general the usage is very similar to what AppEngine created for DB access
(one of the goals was to let me use the same code to talk to AppEngine or
Cassandra).
Again if you have any feedback I'd love to hear it.
Thank you for your time.
Examples:
- Create, Update, and Get:
DataStore.setContactPoint("127.0.0.1");
DataStore.setKeyspace("dogBreeds");
Key sheepDogKey = new Key("dog", "sheepdog"); // every item is identified
by a Key which contains a "Kind" and a "Name". Very similar to the
approach used by AppEngine (in fact this works as a replacement).
Entity sheepDog = new Entity(sheepDogKey);
sheepDog.setProperty("color", "brown");
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
service.put(sheepDog); // saves the new item to the store
Entity sheepDog2 = service.get(sheepDogKey); // gets the item back from the
store
- Searching For A Multi-Valued Property:
...
Entity poodle = new Entity(new Key("dog", "poodle"));
List<String> propertyValues = new ArrayList<String>();
propertyValues.add("smart");
propertyValues.add("obedient");
propertyValues.add("fast");
poodle.setProperty("characteristics", propertyValues);
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
service.put(poodle);
Query q = new Query("dog");
q.addFilter("characteristics", FilterOperator.EQUAL, "smart");
service.prepare(q);
List<Entity> smartDogs = service.asList(new FetchOptions());
develop against Cassandra. I created the library as part of a Cassandra
based web framework that I was creating so that I could abstract out all of
the schema management and just have my code work with simple objects. This
freed me up from having to manually create column families, add columns,
add indexes, etc. I also had a need to be able to search against
multi-valued properties so I added that functionality as well.
If anyone here is interested in taking a look at what I've done I would
love some feedback. Even if that feedback is that you hate it and think I
should delete it all immediately I'd still love to hear why.
You can find the full project page with the source and examples on github
at:
https://github.com/lorenc/Fido
Javadoc can be found at:
http://lorenc.github.io/Fido/
A few simple examples are below. None of the examples require any
columns/indexes/keyspaces be defined ahead of time in the database. In
general the usage is very similar to what AppEngine created for DB access
(one of the goals was to let me use the same code to talk to AppEngine or
Cassandra).
Again if you have any feedback I'd love to hear it.
Thank you for your time.
Examples:
- Create, Update, and Get:
DataStore.setContactPoint("127.0.0.1");
DataStore.setKeyspace("dogBreeds");
Key sheepDogKey = new Key("dog", "sheepdog"); // every item is identified
by a Key which contains a "Kind" and a "Name". Very similar to the
approach used by AppEngine (in fact this works as a replacement).
Entity sheepDog = new Entity(sheepDogKey);
sheepDog.setProperty("color", "brown");
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
service.put(sheepDog); // saves the new item to the store
Entity sheepDog2 = service.get(sheepDogKey); // gets the item back from the
store
- Searching For A Multi-Valued Property:
...
Entity poodle = new Entity(new Key("dog", "poodle"));
List<String> propertyValues = new ArrayList<String>();
propertyValues.add("smart");
propertyValues.add("obedient");
propertyValues.add("fast");
poodle.setProperty("characteristics", propertyValues);
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
service.put(poodle);
Query q = new Query("dog");
q.addFilter("characteristics", FilterOperator.EQUAL, "smart");
service.prepare(q);
List<Entity> smartDogs = service.asList(new FetchOptions());