Permalink
Browse files

Initial usage updated

  • Loading branch information...
1 parent b5dac83 commit 66c05999a1e28af827e4be8e3204fe2f19686568 @wolpert committed Mar 12, 2010
Showing with 60 additions and 4 deletions.
  1. +24 −1 README
  2. +13 −3 grails-app/services/codehead/CassandraService.groovy
  3. +23 −0 plugin.xml
View
25 README
@@ -6,7 +6,7 @@ Grails: 1.2.1
-RELEASE INFO
+DISCLAIMER: NOT READY FOR PRIME TIME!
This code is still highly in development. Expect lots of changes. When the
code is considered stable, this disclaimer will be removed.
@@ -48,6 +48,29 @@ servers running, and default requests to the 'GeneralKeyspace' named Keyspace.
+EXAMPLES
+
+import java.util.Date
+class CassandraLookupController {
+ def cassandraService
+ def index = {
+ def now = new Date().toString()
+ def old_value = cassandraService.setColumnPathValue("Users","login_date","2",now)
+ def new_value = cassandraService.columnPathValue("Users","login_date","2")
+ def str = "Login date was $old_value and now is $new_value"
+ render(str)
+ }
+}
+
+
+TODO
+Some tasks in progress
+ - Make use of super columns
+ - Simplify default access pattern more
+ - Create CassandraHashMap that can use supercolumns
+
+
+
THANKS
Thanks to iMemories for allowing me to open-source this code.
@@ -18,10 +18,7 @@ class CassandraService {
def execute(keyspaceName=defaultKeyspace,block){
CassandraClientPool pool = CassandraClientPoolFactory.INSTANCE.get();
- //CassandraClient client = pool.borrowClient("localhost", 9160);
CassandraClient client = pool.borrowClient(servers);
- // A load balanced version would look like this:
- // CassandraClient client = pool.borrowClient(new String[] {"cas1:9160", "cas2:9160", "cas3:9160"});
try {
Keyspace keyspace = client.getKeyspace(keyspaceName)
@@ -38,4 +35,17 @@ class CassandraService {
}
}
+ // sets the new value for this column path, returning the old one
+ // if there was one
+ def setColumnPathValue(cf,name,key,value){
+ def cp = new ColumnPath(cf,null,bytes(name))
+ return execute{ keyspace ->
+ def old_value = null
+ try {old_value = string(keyspace.getColumn(key,cp).getValue())} catch(Throwable t) {} // TODO, only catch not found
+ keyspace.insert(key, cp, bytes(value))
+ old_value
+ }
+
+ }
+
}
View
@@ -0,0 +1,23 @@
+<plugin name='cassandra' version='0.0.1' grailsVersion='1.2.1 &gt; *'>
+ <author>Ned Wolpert</author>
+ <authorEmail>ned.wolpert@imemories.com</authorEmail>
+ <title>Cassandra access</title>
+ <description>\
+Provides access to Cassandra as a service, simplfying its usage. This is not
+a GORM layer.
+</description>
+ <documentation>http://github.com/wolpert/grails-cassandra</documentation>
+ <resources>
+ <resource>BuildConfig</resource>
+ <resource>DataSource</resource>
+ <resource>UrlMappings</resource>
+ <resource>spring.resources</resource>
+ <resource>codehead.CassandraService</resource>
+ </resources>
+ <dependencies>
+ <resolvers>
+ <resolver type='grailsPlugins' name='grailsPlugins' />
+ </resolvers>
+ </dependencies>
+ <behavior />
+</plugin>

0 comments on commit 66c0599

Please sign in to comment.