| | |
|
|
|
Configuring ZRM
A Project Zero resource model (ZRM) application consists of the database configuration, resource model declaration, and the resource event handler. You can find an example ZRM application in the employee.resource.demo package in the Project Zero samples.
Obtaining the Project Zero resource model
The Project Zero resource model is contained in the zero.resource model. To use it in your application, declare a dependency in your ${app_root}/config/ivy.xml file as shown in the following example:
<dependency name="zero.resource" org="zero" rev="1.0+"/>
Database configuration
Currently ZRM is only supported on the Derby database engine. To accept the default embedded Derby configuration, no additional configuration is necessary. However, to configure the database (if you already had a database configured, for example) you can do so by specifying the configure in the config/zero.config file of your application. You can either override the existing configuration or specify a global context dbKey.
To override the default configuration assign properties as shown in the following example:
/config/db/zero-resource = {
"class" : "org.apache.derby.jdbc.EmbeddedDataSource",
"databaseName" : "db/resource",
"createDatabase" : "create"
}
If you already have database configuration, you can override the ZRM database by specifying the global context dbKey as shown in the following example:
/config/resource/dbKey = "my-database"
Resource Model declaration
Declare Project Zero resource models in separate Groovy files in the app/models folder of the application. These model files describe a resource type's data shape and validation constraints to the ZRM engine. From this metadata, ZRM can intelligently and dynamically create artifacts and modify runtime behavior.
A basic employees Zero Resource Model definition might look like the following example code in app/models/employees.groovy:
// Resource Model declaration
// File: /app/models/employees.groovy
fields = [
name: [type: 'CharField', max_length:50],
birthdate: [type: 'DateField'],
state: [type: 'USStateField'],
phone: [type: 'USPhoneField'],
]
Enabling HTTP
ZRM provides a robust set of REST HTTP APIs to resource models, but not by default. You can enable HTTP access to the Resource Model by introducing a resource event handler in the app/resources folder as shown in the following example:
// File: /app/resources/employees.groovy
ZRM.delegate()
|
|
r13 - 09 Feb 2008 - 17:54:53 - paynel
|
|
|
| | |