Skip to end of metadata
Go to start of metadata

Description

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

Installation

The current version of griffon-neodatis is 0.4
To install just issue the following command

Usage

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

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

A new dynamic method named withOdb will be injected into all controllers, giving you access to a org.neodatis.odb.ODB 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.neodatis.NeodatisConnector. You can inject these methods to non-artifacts via metaclasses. Simply grab hold of a particular metaclass and call NeodatisConnector.enhance(metaClassInstance).

Configuration

Dynamic method injection

The withOdb() 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

  • NeodatisConnectStart[config, databaseName] - triggered before connecting to the datastore
  • NeodatisConnectEnd[databaseName, odb] - triggered after connecting to the datastore
  • NeodatisDisconnectStart[config, databaseName, odb] - triggered before disconnecting from the datastore
  • NeodatisDisconnectEnd[config, databaseName] - triggered after disconnecting from the datastore

Multiple DataSources

The config file NeodatisConfig.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 database block is used.

Example

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

1. Create a new application named 'sample'

Icon

Following steps must be executed inside the application's directory

2. Install the Neodatis plugin

3. Create a bean class

src/main/Person.groovy

4. Setup bootstrapping data. Edit griffon-app/conf/BootstrapNeodatis.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 https://github.com/aalmiray/griffon_sample_apps/tree/master/persistence/neodatis

History

Version

Date

Notes

0.4

10-21-11

Release sync with Griffon 0.9.4

0.3.2

11-08-10

Fix a metaclass problem when injecting dynamic methods

0.3.1

10-31-10

Fixes GRIFFON-266

0.3

10-27-10

Release sync with Griffon 0.9.1

0.2

07-22-10

Release sync with Griffon 0.9

0.1

03-06-10

Initial release

  • No labels