Skip to end of metadata
Go to start of metadata

Description

The DataSource plugin enables access to multiple DataSources.

Installation

The current version of griffon-datasource is 0.2
To install just issue the following command

Usage

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

  • DataSource.groovy - contains the datasource and pool definitions. Its format is equal to GORM's requirements except that it adds a pool section where you can specify connection pool properties.

A new dynamic method named withSql 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'

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

JMX support

This plugin exposes the default dataSource if the JMX plugin is installed. The name used is :service=datasource.

Spring Support

The default dataSource bean is available under name dataSource if the Spring plugin is installed.

Weld Support

The default dataSource bean is available under name dataSource if the Weld plugin is installed.

Configuration

Dynamic method injection

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

Events

The following events will be triggered by this addon

  • DataSourceConnectStart[config, dataSourceName] - triggered before connecting to the datastore
  • DataSourceConnectEnd[dataSourceName, dataSource] - triggered after connecting to the datastore
  • DataSourceDisconnectStart[config, dataSourceName, dataSource] - triggered before disconnecting from the datastore
  • DataSourceDisconnectEnd[config, dataSourceName] - triggered after disconnecting from the datastore

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 dataSource block is used.

History

Version

Date

Notes

0.2

10-21-11

Release sync with Griffon 0.9.4

0.1

08-15-11

Initial release

  • No labels