Skip to content
bustardcelly edited this page Sep 14, 2010 · 2 revisions

The CouchDatabase, CouchDocument and CouchSession models are base classes intended to be extended with custom annotations based on the requirements of your application that is interacting with a CouchDB instance. These base classes themselves, extend CouchModel which contains a CouchModelEntity used to auto-wire the business layer for CouchDB requests, so custom database, document, and session models can be interacted with directly, similar to Data Access Object pattern.

CouchModelEntity attempts to auto-wire Business Object models by parsing metadata related to the target database and its location, and resolving the concrete implementations of the Service Mediator and Request Type objects. As such, there are three custom annotations that need to be declared on any custom extension to CouchDatabase. These metadata are:

  1. DocumentService
  2. ServiceMediator
  3. RequestType

DocumentService

The DocumentService metadata declares to the url of the CouchDB and the target Database name.
In the following example, the url points to the localhost at port 5984 (the default for CouchDB) and the database ‘contacts’. Any requests made will be perfomed on the ‘contacts’ database at the CouchDB location.

[DocumentService(url="http://127.0.0.1:5984", name="contacts")]

ServiceMediator

The ServiceMediator metadata declares the mediating class between a model and the service. The name argument takes a fully qualified classname of the concrete IServiceMediator implementation. CouchDatabaseActionMediator is available from the as3couchdb library and can be used, or extended as seen fit.

[ServiceMediator(name="com.custardbelly.as3couchdb.mediator.CouchDatabaseActionMediator")]

RequestType

The RequestType metadata delcares the interfacing request class with the service. The ICouchRequest implementation is handed to the Service Mediator in order to establish the proper handling of requests from the service.

The main purpose of the RequestType is to handle multiple runtimes and there URLRequest restrictions. The Flash Player for AIR supports PUT and DELETE requests, but such requests are not available in the web-based Flash Player. As such, HTTPCouchRequest is available in as3couchdb and uses the as3httpclientlib library to make the requests over a socket. Other implementation are ExInCouchRequest which uses ExternalInterface, and CouchRequest which makes requests without a proxy.

[RequestType(name="com.custardbelly.as3couchdb.service.HTTPCouchRequest")]