Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0


The Cassandra plugin enables lightweight access to Cassandra datastores using JDBC + CQL. This plugin does NOT provide domain classes nor dynamic finders like GORM does.


The current version of griffon-cassandra is 0.1
To install just issue the following command

Code Block
griffon install-plugin cassandra


Upon installation the plugin will generate the following artifact in $appdir/griffon-app/conf:

  • CassandraConfig.groovy - contains the datasource definitions.
  • BootstrapCassandra.groovy - defines init/destroy hooks for data to be manipulated during app startup/shutdown.

A new dynamic method named withCql will be injected into all controllers, giving you access to a groovy.sql.Sql object, with which you'll be able to make calls to the database. Remember to make all calls to the database off the EDT otherwise your application may appear unresponsive when doing long computations inside the EDT.
This method is aware of multiple datasources. If no datasourceName is specified when calling it then the default dataSource will be selected. Here are two example usages, the first queries against the default datasource while the second queries a datasource whose name has been configured as 'internal'

Code Block
package sample
class SampleController {
    def queryAllDataSources = {
        withCql { dsName, sql -> ... }
        withCql('internal') { dsName, sql -> ... }

This method is also accessible to any component through the singleton griffon.plugins.cassandra.CassandraConnector. You can inject these methods to non-artifacts via metaclasses. Simply grab hold of a particular metaclass and call CassandraConnector.enhance(metaClassInstance).


Dynamic method injection

The withCql() dynamic method will be added to controllers by default. You can change this setting by adding a configuration flag in Config.groovy

Code Block
griffon.cassandra.injectInto = ["controller", "service"]


The following events will be triggered by this addon

  • CassandraConnectStart[config, dataSourceName] - triggered before connecting to the datastore
  • CassandraConnectEnd[dataSourceName, dataSource] - triggered after connecting to the datastore
  • CassandraDisconnectStart[config, dataSourceName, dataSource] - triggered before disconnecting from the datastore
  • CassandraDisconnectEnd[config, dataSourceName] - triggered after disconnecting from the datastore

Multiple DataSources

The config file CassandraConfig.groovy defines a default dataSource block. As the name implies this is the dataSource used by default, however you can configure named dataSources by adding a new config block. For example connecting to a dataSource whose name is 'internal' can be done in this way

Code Block
dataSources {
    internal {
	    driverClassName = 'org.apache.cassandra.cql.jdbc.CassandraDriver'
		dbCreate = 'create'
		url = 'jdbc:cassandra://localhost:9160/internal'
	    pool {
	        maxWait = 60000
	        maxIdle = 5
	        maxActive = 8

This block can be used inside the environments() block in the same way as the default datasource block is used.


A trivial sample application can be found at







Initial release