Skip to end of metadata
Go to start of metadata


The ActiveJdbc plugin enables lightweight access to MySql, Postgres, Oracle and H2 datasources using ActiveJdbc. This plugin does NOT provide domain classes nor dynamic finders like GORM does.


The current version of griffon-activejdbc is 0.3
To install just issue the following command


Upon installation the plugin will generate the following artifacts at $appdir/griffon-app/conf:

  • DataSource.groovy - contains the datasource and pool definitions. Its format is equal to GORM's requirements. Additional configuration for this artifact is explained in the DataSource Plugin.
  • BootstrapActivejdbc.groovy - defines init/destroy hooks for data to be manipulated during app startup/shutdown.

The dynamic method withActivejdbc will be injected into all controllers. 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'

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


This plugin provides the following scripts

  • activejdbc-instrument - collects information of model classes and enhances their bytecode with ActiveJdbc specific calls.

This script must be called explicitly before running the application at least once. If any of the model classes is updated then you must clean your sources and call this script again.


Don't forget to instrument the code, otherwise the model classes will not be picked up by ActiveJdbc.


Dynamic method injection

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


The following events will be triggered by this addon

  • ActivejdbcConnectStart[config] - triggered before connecting to the datasource
  • ActivejdbcConnectEnd[config, dataSource] - triggered after connecting to the datasource
  • ActivejdbcDisconnectStart[config, dataSource] - triggered before disconnecting from the datasource
  • ActivejdbcDisconnectEnd[] - triggered after disconnecting from the datasource


Follow these steps to create a simple application that displays data stored inside a database.

1. Create a new application named 'sample'


Following steps must be executed inside the application's directory

2. Install the Activejdbc plugin

3. Setup the database. Create the file griffon-app/resources/schema.ddl with the following content

DataBase Specific Content


The schema.ddl file must contain RDBMS specific DDL statements

It's paramount for the application's sake that you define an ID property for each model class and set it to be auto incremented.

4. Create a model class in src/main/sample/

5. Setup bootstrapping data. Edit griffon-app/conf/BootstrapActivejdbc.groovy (We'll use the Griffon's team roster, feel free to input your own data)

6. Download a copy of GlazedLists' latest stable release. Place it under $appdir/lib. Or install the Glazedlists Plugin (recommended!).

7. Edit griffon-app/models/sample/SampleModel.groovy by adding a personList property.

GlazedLists' EventList simplifies working with JList, JTable and their models as you will soon find out.

8. Edit griffon-app/views/sample/SampleView.groovy. We'll add a scrollPane and a table. The Table's model will be tied to model.people.

9. Finally edit griffon-app/controllers/sample/SampleController.groovy. The controller will react to an application event, load the data into a temporary List then update model.people inside the EDT.

10. Instrument the code by running the instrumentation script

11. Run the application by typing

Full source code for this sample application can be found at







Release sync with Griffon 0.9.4



Added dependency to Datasource plugin



Initial release

  • No labels