Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Table of
Contents...
Hide

Project Zero Developer’s Guide

Basic concepts
Core concepts overview
Event processing
Writing Java handlers
Writing Groovy handlers
Firing events
Global Context
Global Context reference
Application directory layout
Virtualized directories
Writing rich Web applications
Features and configuration
Configuration
Debugging
Dependencies
Packaging
Application Classpath
Logging and tracing
RESTful resources
Creating RESTful documentation
File serving
Response rendering
Validators and validation
HTTP error handling
Client programming with Dojo
Runtime Options
Deployment modifications
HTTP configuration
SSL configuration
Proxy configuration
Security
Security considerations
Authentication
Extending security
Security Tokens
Token support
Extending token support
Leveraging TAI
User service
File based user service
LDAP user service
Extending user service
Security Utilities
Leveraging XOREncoder
Assemble
Calling Out to a Remote Resource
Using the Connection API
Sending an email
Configuring destinations
Configuring protocols
Protocol reference
HTTP protocol
SMTP protocol
File protocol
Event protocol
Assemble Flows and Mediations
Using flows
Getting started with Assemble flow
Creating a simple feed flow
Creating a simple Assemble flow
Creating a simple extension
Problem determination
A Flow language example
Creating and running a new flow
Writing flows using a Groovy DSL
Creating new flow activities
Writing extensions in the flow language
Writing extensions in Groovy
Adding validation rule
Configuring the graphical tool
Using the GUI to work with flows
Feed perspective of the GUI tool
Advanced Features
Using the flow samples
Flow language reference
Flow language behavior and syntax
Running processes and activities
Built-in activities
Extension activities
Feed Operators
XML Operators
Using mediations
Configuring mediations
Creating new mediations
Supplied mediation steps
Static router
Java logger
XPath logger
REST2SOAP
Extensions
Atom support
Atom Enabling a Database
RSS support
JSON support
XMLEncoder
URIUtils
Developer Web tools
Data access
Common query patterns
Advanced query patterns
Update patterns
Local database transactions
Extending data access
Config vendor differences
PHP data access
Resource Model
Setup and configuration
Resource Model declaration
Programmatic Model API
HTTP REST API
Active content filtering support
Default filters
Custom filters
Other Extension Modules
Amazon E-Commerce Service
Reference
Zero command line interface
JavaDoc - Public API
JavaDoc - Public SPI
JavaDoc - All Classes
Samples and services
Samples
The Zero Zone Application
Services
Blogging service
Commenting service
File sharing service
Group service
Profile service
Rating service
Tagging service
Catalog Zero

 

Configuring data access

Data access has use cases that range from very simple to very complex; many developers pine for an API that is flexible enough to handle complex situations without making simple tasks cumbersome. "Make the common things easy and the hard things possible." The zero.data.Manager and zero.data.groovy.Manager classes provide an API that solves many common use cases while still allowing for very specific customizations.

The following sections of this article provide information about data access with zero.data:

tip There are two Manager implementations: one for Groovy (zero.data.groovy.Manager) and one for Java (zero.data.Manager). The Groovy implementation provides additional methods that make use of the dynamic nature of Groovy.

The following sections of this article provide information about configuring data access:

Adding zero.data to your application

If you are using data zero query within a Zero application, you need to resolve a dependency in order to install the required jar files. After creating your application, modify the config/ivy.xml file in your application to add the following line in the dependencies section:

<dependency org="zero" name="zero.data" rev="1.0+"/>

After adding the dependency, issue the resolve command using either Ant or Eclipse.

You can also pull in the jar files you need for database access. For example, adding the following to config/ivy.xml pulls in the Derby client jar file:

<dependency name="derbyclient" org="org.apache.derby" rev="10.2+"/>

Configuring zero.data.Manager and zero.data.groovy.Manager in Project Zero

zero.data.Manager, and its groovier friend, zero.data.groovy.Manager, can be initialized with either a javax.sql.DataSource or a java.sql.Connection as a constructor argument. If you are using the Project Zero zero.config configuration file, Manager.create(String) is a convenience method to create a new instance, allowing you to avoid any reference to JDBC APIs.

The following zero.config file snippet shows the configuration of two databases accessible from a Project Zero application:

# This config is for Apache Derby databases:
[/config/db/reviewDB/config]
class=org.apache.derby.jdbc.ClientDataSource
serverName=localhost
portNumber=1527
databaseName=./db/review
connectionAttributes=create=true

# This config is for MySQL databases:
[/config/db/votingDB/config]
class=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
serverName=db.example.org
portNumber=3306
databaseName=voting
user=root
password=<xor>Lz4sLCgwLTs=

Obfuscating passwords

The second example above, /config/db/votingDB/config, illustrates how to use the XOR encoded password to obfuscate the password. For more details on how to generate a password with this encoding, consult the XOR Encoder documentation. Taking this measure prevents the password from being shown in plain text. Although not secure with encryption or hash, this form of encoding simply keeps honest people honest.

Obtain a data manager

Two databases, reviewDB and votingDB, are configured in the zero.config example above. The former is a local network Derby client and the latter is a remote MySQL database. You can configure as many databases as your application needs.

With databases configured at /config/db/{database name}/config, an application developer can obtain a zero.data.Manager or zero.data.groovy.Manager as follows:

// Java code:
import zero.data.Manager;
...
Manager voteDB = Manager.create("votingDB");
List<Map<String, Object>> results = voteDB.queryList("SELECT * FROM votes WHERE numVotes > ?", 10);

// Groovy code:
def voteDB = zero.data.groovy.Manager.create('votingDB')
def numVotes = 10
def results = voteDB.queryList("SELECT * FROM votes WHERE numVotes > $numVotes")

r13 - 16 Jan 2008 - 19:12:09 - paynel
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site