The Ebean plugin enables lightweight access to datasources using Ebean. This plugin does NOT provide domain classes nor dynamic finders like GORM does.
The current version of griffon-ebean is 0.2
To install just issue the following command
Upon installation the plugin will generate the following artifacts at
- 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.
- BootstrapEbean.groovy - defines init/destroy hooks for data to be manipulated during app startup/shutdown.
The dynamic method
withEbean 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.ebean.EbeanConnector. You can inject these methods to non-artifacts via metaclasses. Simply grab hold of a particular metaclass and call
Dynamic method injection
withEbean() dynamic method will be added to controllers by default. You can change this setting by adding a configuration flag in
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.
The following events will be triggered by this addon
- EbeanConnectStart[config, dataSourceName] - triggered before connecting to the datasource
- EbeanConnectEnd[dataSourceName, ebeanServer] - triggered after connecting to the datasource
- EbeanDisconnectStart[dataSourceName, ebeanServer] - triggered before disconnecting from the datasource
- EbeanDisconnectEnd[dataSourceName] - 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'
2. Install the Ebean plugin
4. Create a model class in
src/ebean/sample/Person.groovy. Don't forget to annotate it with JPA annotations
4. Setup bootstrapping data. Edit
griffon-app/conf/BootstrapEbean.groovy (We'll use the Griffon's team roster, feel free to input your own data)
griffon-app/models/sample/SampleModel.groovy by adding a
GlazedLists' EventList simplifies working with JList, JTable and their models as you will soon find out.
griffon-app/views/sample/SampleView.groovy. We'll add a scrollPane and a table. The Table's model will be tied to
8. 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.
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/ebean
Release sync with Griffon 0.9.4