Usage

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

BlueprintsConfig.groovy - contains the database definitions.

BootstrapBlueprints.groovy - defines init/destroy hooks for data to be manipulated during app startup/shutdown.

A new dynamic method named withBlueprints will be injected into all controllers, giving you access to a com.tinkerpop.blueprints.Graph object, with which you'll be able to make calls to the database. Remember to make all database calls off the UI thread otherwise your application may appear unresponsive when doing long computations inside the UI thread.

This method is aware of multiple databases. If no graphName is specified when calling it then the default database will be selected. Here are two example usages, the first queries against the default database while the second queries a database whose name has been configured as 'internal'

These methods are also accessible to any component through the singleton griffon.plugins.blueprints.BlueprintsConnector. You can inject these methods to non-artifacts via metaclasses. Simply grab hold of a particular metaclass and call BlueprintsEnhancer.enhance(metaClassInstance, blueprintsProviderInstance).

Configuration

BlueprintsAware AST Transformation

The preferred way to mark a class for method injection is by annotating it with @griffon.plugins.blueprints.BlueprintsAware. This transformation injects the griffon.plugins.blueprints.BlueprintsContributionHandler interface and default behavior that fulfills the contract.

Dynamic method injection

Dynamic methods will be added to controllers by default. You can change this setting by adding a configuration flag in griffon-app/conf/Config.groovy

griffon.blueprints.injectInto = ['controller', 'service']

Dynamic method injection will be skipped for classes implementing griffon.plugins.blueprints.BlueprintsContributionHandler.

Events

The following events will be triggered by this addon

BlueprintsConnectStart[config, graphName] - triggered before connecting to the database

BlueprintsConnectEnd[graphName, database] - triggered after connecting to the database

BlueprintsDisconnectStart[config, graphName, database] - triggered before disconnecting from the database

BlueprintsDisconnectEnd[config, graphName] - triggered after disconnecting from the database

Multiple Databases

The config file BlueprintsConfig.groovy defines a default graph block. As the name implies this is the database used by default, however you can configure named databases by adding a new config block. For example connecting to a database 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 graph block is used. The value of the factory key must be fully qualified classname of a class implementing griffon.plugins.blueprints.factory.GraphFactory. The default configuration instantiates a com.tinkerpop.blueprints.impls.tg.TinkerGraph.

Configuration Storage

The plugin will load and store the contents of BlueprintsConfig.groovy inside the application's configuration, under the pluginConfig namespace. You may retrieve and/or update values using

app.config.pluginConfig.blueprints

Connect at Startup

The plugin will attempt a connection to the default database at startup. If this behavior is not desired then specify the following configuration flag in Config.groovy

griffon.blueprints.connect.onstartup = false

Example

Testing

Dynamic methods will not be automatically injected during unit testing, because addons are simply not initialized for this kind of tests. However you can use BlueprintsEnhancer.enhance(metaClassInstance, blueprintsProviderInstance) where blueprintsProviderInstance is of type griffon.plugins.blueprints.BlueprintsProvider. The contract for this interface looks like this

On the other hand, if the service is annotated with @BlueprintsAware then usage of BlueprintsEnhancer should be avoided at all costs. Simply set blueprintsProviderInstance on the service instance directly, like so, first the service definition

Tool Support

DSL Descriptors

This plugin provides DSL descriptors for Intellij IDEA and Eclipse (provided you have the Groovy Eclipse plugin installed). These descriptors are found inside the griffon-blueprints-compile-x.y.z.jar, with locations

dsdl/blueprints.dsld

gdsl/blueprints.gdsl

Lombok Support

Rewriting Java AST in a similar fashion to Groovy AST transformations is possible thanks to the lombok plugin.

JavaC

Support for this compiler is provided out-of-the-box by the command line tools. There's no additional configuration required.

Eclipse

Follow the steps found in the Lombok plugin for setting up Eclipse up to number 5.

Go to the path where the lombok.jar was copied. This path is either found inside the Eclipse installation directory or in your local settings. Copy the following file from the project's working directory