Permalink
Browse files

initial checkpoint

  • Loading branch information...
wolpert committed Mar 12, 2010
0 parents commit b5dac8350a7fd1deab4100f9690c10db450652a3
@@ -0,0 +1,14 @@
+<classpath>
+ <classpathentry kind="src" path="src/java"/>
+ <classpathentry kind="src" path="src/groovy"/>
+ <classpathentry kind="src" path="grails-app/conf"/>
+ <classpathentry kind="src" path="grails-app/controllers"/>
+ <classpathentry kind="src" path="grails-app/domain"/>
+ <classpathentry kind="src" path="grails-app/services"/>
+ <classpathentry kind="src" path="grails-app/taglib"/>
+ <classpathentry kind="src" path="test/integration"/>
+ <classpathentry kind="src" path="test/unit"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="com.springsource.sts.grails.core.CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="web-app/WEB-INF/classes"/>
+</classpath>
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>cassandra</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.springsource.sts.grails.core.nature</nature>
+ <nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,3 @@
+#Created by grails
+eclipse.preferences.version=1
+groovy.dont.generate.class.files=true
@@ -0,0 +1,51 @@
+class CassandraGrailsPlugin {
+ // the plugin version
+ def version = "0.0.1"
+ // the version or versions of Grails the plugin is designed for
+ def grailsVersion = "1.2.1 > *"
+ // the other plugins this plugin depends on
+ def dependsOn = [:]
+ // resources that are excluded from plugin packaging
+ def pluginExcludes = [
+ "grails-app/views/error.gsp",
+ "grails-app/conf/spring/resources.groovy"
+ ]
+
+ def author = "Ned Wolpert"
+ def authorEmail = "ned.wolpert@imemories.com"
+ def title = "Cassandra access"
+ def description = '''\\
+Provides access to Cassandra as a service, simplfying its usage. This is not
+a GORM layer.
+'''
+
+ // URL to the plugin's documentation
+ def documentation = "http://github.com/wolpert/grails-cassandra"
+
+ def doWithWebDescriptor = { xml ->
+ // TODO Implement additions to web.xml (optional), this event occurs before
+ }
+
+ def doWithSpring = {
+ // TODO Implement runtime spring config (optional)
+ }
+
+ def doWithDynamicMethods = { ctx ->
+ // TODO Implement registering dynamic methods to classes (optional)
+ }
+
+ def doWithApplicationContext = { applicationContext ->
+ // TODO Implement post initialization spring config (optional)
+ }
+
+ def onChange = { event ->
+ // TODO Implement code that is executed when any artefact that this plugin is
+ // watching is modified and reloaded. The event contains: event.source,
+ // event.application, event.manager, event.ctx, and event.plugin.
+ }
+
+ def onConfigChange = { event ->
+ // TODO Implement code that is executed when the project configuration changes.
+ // The event is the same as for 'onChange'.
+ }
+}
@@ -0,0 +1,25 @@
+Copyright (c) 2010, Ned Wolpert <ned.wolpert@imemories.com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of iMemories nor the names of its contributors may be
+ used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 README
@@ -0,0 +1,54 @@
+License: http://www.opensource.org/licenses/bsd-license.php
+
+Cassandra Version: 0.5.1
+Hector Version: 0.5.0-6
+Grails: 1.2.1
+
+
+
+RELEASE INFO
+
+This code is still highly in development. Expect lots of changes. When the
+code is considered stable, this disclaimer will be removed.
+
+
+
+ABOUT
+
+This grails plugins provides a service to enable easy access to Cassandra
+from within grails. It is not intended to be a GORM mapping layer.
+
+It specifically wraps the Hector (http://github.com/rantav/hector) API which
+makes it easy to connect to Cassandra without dealing with the thrift layer.
+Hector also provides for connection pooling, etc.
+
+Goals:
+
+Primary goals of this project is to have a service that provides easy access
+to Cassandra. This includes simplify lookup and setting of Cassandra values,
+and optionally hiding 'NotFound' exceptions. (The ruby Cassandra plugin
+returns an empty hash if a searched for value does not exist. Java plugin
+throws an exception.)
+
+Usage:
+
+By default, this plugin will connect to Cassandra running at localhost:9160
+using the keyspace 'Keyspace1' for all queries. To change this, setup in
+your grails-app/conf/spring/resources.groovy file:
+
+beans = {
+ cassandraService(codehead.CassandraService){
+ servers=["localhost:9160","192.168.2.1:9160"]
+ defaultKeyspace="GeneralKeyspace"
+ }
+}
+
+The above configuration will allow for server fail-over to multiple Cassandra
+servers running, and default requests to the 'GeneralKeyspace' named Keyspace.
+
+
+
+THANKS
+
+Thanks to iMemories for allowing me to open-source this code.
+
@@ -0,0 +1,6 @@
+#Grails Metadata file
+#Fri Mar 12 10:41:05 MST 2010
+app.grails.version=1.2.1
+app.name=cassandra
+plugins.hibernate=1.2.1
+plugins.tomcat=1.2.1
@@ -0,0 +1,31 @@
+grails.project.class.dir = "target/classes"
+grails.project.test.class.dir = "target/test-classes"
+grails.project.test.reports.dir = "target/test-reports"
+//grails.project.war.file = "target/${appName}-${appVersion}.war"
+grails.project.dependency.resolution = {
+ // inherit Grails' default dependencies
+ inherits( "global" ) {
+ // uncomment to disable ehcache
+ // excludes 'ehcache'
+ }
+ log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
+ repositories {
+ grailsPlugins()
+ grailsHome()
+
+ // uncomment the below to enable remote dependency resolution
+ // from public Maven repositories
+ //mavenLocal()
+ //mavenCentral()
+ //mavenRepo "http://snapshots.repository.codehaus.org"
+ //mavenRepo "http://repository.codehaus.org"
+ //mavenRepo "http://download.java.net/maven/2/"
+ //mavenRepo "http://repository.jboss.com/maven2/"
+ }
+ dependencies {
+ // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
+
+ // runtime 'mysql:mysql-connector-java:5.1.5'
+ }
+
+}
@@ -0,0 +1,32 @@
+dataSource {
+ pooled = true
+ driverClassName = "org.hsqldb.jdbcDriver"
+ username = "sa"
+ password = ""
+}
+hibernate {
+ cache.use_second_level_cache=true
+ cache.use_query_cache=true
+ cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
+}
+// environment specific settings
+environments {
+ development {
+ dataSource {
+ dbCreate = "create-drop" // one of 'create', 'create-drop','update'
+ url = "jdbc:hsqldb:mem:devDB"
+ }
+ }
+ test {
+ dataSource {
+ dbCreate = "update"
+ url = "jdbc:hsqldb:mem:testDb"
+ }
+ }
+ production {
+ dataSource {
+ dbCreate = "update"
+ url = "jdbc:hsqldb:file:prodDb;shutdown=true"
+ }
+ }
+}
@@ -0,0 +1,11 @@
+class UrlMappings {
+ static mappings = {
+ "/$controller/$action?/$id?"{
+ constraints {
+ // apply constraints here
+ }
+ }
+ "/"(view:"/index")
+ "500"(view:'/error')
+ }
+}
@@ -0,0 +1,7 @@
+
+beans = {
+ cassandraService(codehead.CassandraService){
+ servers=["localhost:9160"] // add more servers as needed
+ defaultKeyspace="NedTest"
+ }
+}
@@ -0,0 +1,41 @@
+package codehead;
+
+import me.prettyprint.cassandra.service.CassandraClientPool
+import me.prettyprint.cassandra.service.CassandraClientPoolFactory
+import me.prettyprint.cassandra.service.CassandraClient
+import me.prettyprint.cassandra.service.Keyspace
+import org.apache.cassandra.service.Column;
+import org.apache.cassandra.service.ColumnPath;
+
+import static me.prettyprint.cassandra.utils.StringUtils.bytes;
+import static me.prettyprint.cassandra.utils.StringUtils.string;
+class CassandraService {
+
+ boolean transactional = true
+
+ def servers=["localhost:9160"]
+ def defaultKeyspace="Keyspace1"
+
+ 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)
+ return block(keyspace)
+ } finally {
+ pool.releaseClient(client);
+ }
+ }
+
+ def columnPathValue(cf,name,key){
+ def cp = new ColumnPath(cf,null,bytes(name))
+ return execute{ keyspace ->
+ string(keyspace.getColumn(key,cp).getValue())
+ }
+ }
+
+}
@@ -0,0 +1,54 @@
+<html>
+ <head>
+ <title>Grails Runtime Exception</title>
+ <style type="text/css">
+ .message {
+ border: 1px solid black;
+ padding: 5px;
+ background-color:#E9E9E9;
+ }
+ .stack {
+ border: 1px solid black;
+ padding: 5px;
+ overflow:auto;
+ height: 300px;
+ }
+ .snippet {
+ padding: 5px;
+ background-color:white;
+ border:1px solid black;
+ margin:3px;
+ font-family:courier;
+ }
+ </style>
+ </head>
+
+ <body>
+ <h1>Grails Runtime Exception</h1>
+ <h2>Error Details</h2>
+
+ <div class="message">
+ <strong>Error ${request.'javax.servlet.error.status_code'}:</strong> ${request.'javax.servlet.error.message'.encodeAsHTML()}<br/>
+ <strong>Servlet:</strong> ${request.'javax.servlet.error.servlet_name'}<br/>
+ <strong>URI:</strong> ${request.'javax.servlet.error.request_uri'}<br/>
+ <g:if test="${exception}">
+ <strong>Exception Message:</strong> ${exception.message?.encodeAsHTML()} <br />
+ <strong>Caused by:</strong> ${exception.cause?.message?.encodeAsHTML()} <br />
+ <strong>Class:</strong> ${exception.className} <br />
+ <strong>At Line:</strong> [${exception.lineNumber}] <br />
+ <strong>Code Snippet:</strong><br />
+ <div class="snippet">
+ <g:each var="cs" in="${exception.codeSnippet}">
+ ${cs?.encodeAsHTML()}<br />
+ </g:each>
+ </div>
+ </g:if>
+ </div>
+ <g:if test="${exception}">
+ <h2>Stack Trace</h2>
+ <div class="stack">
+ <pre><g:each in="${exception.stackTraceLines}">${it.encodeAsHTML()}<br/></g:each></pre>
+ </div>
+ </g:if>
+ </body>
+</html>
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,10 @@
+//
+// This script is executed by Grails after plugin was installed to project.
+// This script is a Gant script so you can use all special variables provided
+// by Gant (such as 'baseDir' which points on project base dir). You can
+// use 'ant' to access a global instance of AntBuilder
+//
+// For example you can create directory under project tree:
+//
+// ant.mkdir(dir:"${basedir}/grails-app/jobs")
+//
@@ -0,0 +1,5 @@
+//
+// This script is executed by Grails when the plugin is uninstalled from project.
+// Use this script if you intend to do any additional clean-up on uninstall, but
+// beware of messing up SVN directories!
+//
@@ -0,0 +1,10 @@
+//
+// This script is executed by Grails during application upgrade ('grails upgrade'
+// command). This script is a Gant script so you can use all special variables
+// provided by Gant (such as 'baseDir' which points on project base dir). You can
+// use 'ant' to access a global instance of AntBuilder
+//
+// For example you can create directory under project tree:
+//
+// ant.mkdir(dir:"${basedir}/grails-app/jobs")
+//
Oops, something went wrong.

0 comments on commit b5dac83

Please sign in to comment.