Skip to end of metadata
Go to start of metadata

Description

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

Installation

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

Usage

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

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

Remember to make all calls to the database off the EDT otherwise your application may appear unresponsive when doing long computations
inside the EDT. The following dynamic methods will be added

  • withBerkeleyEnv { Environment env -> ... } - direct access to the current Berkeley DB environment.
  • withBerkeleyDB(Map args) { Database db, Transaction txn -> ... }
  • withBerkeleyCursor(Map args) { Cursor cursor, Transaction txn -> ... }
  • withEntityStore(Map args) { EntityStore store, Transaction txn -> ... }

The last 3 methods accept an optional Map argument that may contain the following keys:

  • id - name of a database or entityStore. Will pull configuration from BerlekeydbConfig if the id matches a configured database or entityStore.
  • txnConfig - a TransactionConfig instance that overrides any transaction settings available BerlekeydbConfig for a matching id.
  • cursorConfig - a CursorConfig instance that overrides any cursor settings available BerlekeydbConfig for a matching id.

All these methods are also accessible to any component through the singleton griffon.plugins.berkeleydb.BerkeleydbConnector. You can inject these methods to non-artifacts via metaclasses. Simply grab hold of a particular metaclass and call BerkeleydbConnector.enhance(metaClassInstance).

Scripts

This plugin provides the following scripts

  • create-berkeleydb-entity - creates a new class (and its Accessor) that be used with the EntityStore.

Configuration

Dynamic method injection

Dynamic methods 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

  • BerkeleydbConnectStart[config] - triggered before connecting to the datastore
  • BerkeleydbConnectEnd[env] - triggered after connecting to the datastore
  • BerkeleydbDisconnectStart[config, env] - triggered before disconnecting from the datastore
  • BerkeleydbDisconnectEnd[] - triggered after disconnecting from the datastore

Database Settings

The following BerlekeydbConfig.groovy exemplifies what you may configure

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

5. Create an entity class in src/main/sample/Person.groovy. Edit the class to add a property named 'lastname'

Java based templates are available too, just use -fileType=java at the command prompt.

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

5. Make sure BerkeleydbConfig.groovy has an entityStore named 'person'

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. 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/berkeleydb

History

Version

Date

Notes

0.5

10-21-11

Release sync with Griffon 0.9.4

0.4

08-15-11

Release sync with Griffon 0.9.3

0.3.1

11-08-10

Fix a metaclass problem when injecting dynamic methods

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-01-10

Initial release

  • No labels