Configuring the Zero Resource Model

An application using the Zero Resource Model consists of the database configuration, resource model declaration, and the resource event handler.

Obtaining ZRM

The Zero Resource model (ZRM) 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.0.0, 2.0.0.0["/>

Database configuration

Currently ZRM is supported on Derby 10.3.2.1, DB2 9.5, and MySQL 5.0, and Oracle 10g database engines. To accept the default embedded Derby configuration for convenience of developing, no additional configuration is necessary. However, to configure the database you can do so by specifying the database connection properties in the {app_root}/config/zero.config file of your application and override the default configuration with a dbKey of zero-resource or specify a global context dbKey.

Overriding configuration

To override the default configuration, assign properties as shown in the following example at the zero-resource key:

/config/db/zero-resource = {
    "class" : "com.ibm.db2.jcc.DB2SimpleDataSource",
    "driverType" : 4,
    "serverName" : "myserver",
    "portNumber" : 50000,
    "databaseName" : "MYDB",
    "user" : "db2inst1",
    "password" : "mypassword"
}

Pointing to configuration

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/db/my-database = {
    "class" : "com.mysql.jdbc.jdbc2.optional.MysqlDataSource",
    "serverName" : "myserver",
    "portNumber" : 3306,
    "databaseName" : "MY1STDB",
    "user" : "root",
    "password" : "mypassword"
}

/config/resource/dbKey = "my-database"

Resource Model declaration

You declare resource models in separate JSON files in the {app_root}/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 definition, ZRM will create the requisite database tables using the model sync CLI task.

A basic employees Zero Resource Model definition might look like the following example in {app_root}/app/models/employees.json:

{
    "fields" : {
        "name": {"type": "string", "max_length":50},
        "birthdate": {"type": "date",
        "state": {"type": "string", "format": "region"},
        "phone": {"type": "string", "format": "phone"}
    }
}

The resource model declaration documentation has more details on how to declare resource models.

Enabling the HTTP API

ZRM provides a robust set of REST HTTP APIs to resource models, but not by default. You can enable HTTP access to the ZRM-based resources by introducing a resource event handler in the {app_root}/app/resources/employees.groovy file as shown in the following example:

ZRM.delegate()

Version 1.1.0.0.21442