Skip to end of metadata
Go to start of metadata


The Db4o plugin enables lightweight access to database functionality using db4o. This plugin does NOT provide domain classes nor dynamic finders like GORM does.


The current version of griffon-db4o is 0.5
To install just issue the following command


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

  • Db4oConfig.groovy - contains the datasource definition.
  • BootstrapDb4o.groovy - defines init/destroy hooks for data to be manipulated during app startup/shutdown.

A new dynamic method named withDb4o will be injected into all controllers, giving you access to a com.db4o.ObjectContainer 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 db4os. If no db4oName is specified when calling it then the default dataSource will be selected. Here are two example usages, the first queries against the default db4o while the second queries a db4o whose name has been configured as 'internal'

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


Dynamic method injection

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


  • - defines the name of the db file to use
  • dataSource.delete - will delete the db file upon application shutdown if true

If the default configuration settings prove to be inadequate for your needs you still have a chance to tweak the configuration programmatically by implementing


The following events will be triggered by this addon

  • Db4oConnectStart[config, dataSourceName] - triggered before connecting to the objectContainer
  • Db4oConnectEnd[dataSourceName, objectContainer] - triggered after connecting to the objectContainer
  • Db4oDisconnectStart[config, dataSourceName, objectContainer] - triggered before disconnecting from the objectContainer
  • Db4oDisconnectEnd[confing, dataSourceName] - triggered after disconnecting from the objectContainer

Multiple DataSources

The config file DataSource.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

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


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 Db4o plugin

3. Create a bean class


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

5. Download a copy of GlazedLists' latest stable release. Place it under $appdir/lib. Or install the Glazedlists Plugin.

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

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

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

If you installed the Glazedlists plugin then the view code can be simplified further

8. Finally edit griffon-app/controllers/SampleController.groovy. The controller will react to an application event, load the data into a temporal List then update model.personsList inside the EDT. Application event handlers are guaranteed to run outside of the EDT.

9. Run the application by typing

Full source code for this sample application can be found at







Release sync with Griffon 0.9.4



GRIFFON-385 Add configuration flag for optionally deleting db file



GRIFFON-258 Add pre/post trigger events



Release sync with Griffon 0.9



Initial release

  • No labels