org.ektorp
Interface CouchDbConnector

All Known Implementing Classes:
StdCouchDbConnector

public interface CouchDbConnector

Primary interface for working with Objects mapped as documents in CouchDb. Mapped Objects must have getters and setters for id and revision. public String getId() public void setId(String s) public String getRevision() public void setRevision(String s) Reflection is used to access these methods.

Author:
henrik lundgren

Method Summary
 boolean contains(java.lang.String id)
          Check if the database contains a document.
 void create(java.lang.Object o)
          Creates the Object as a document in the database.
 void create(java.lang.String id, org.codehaus.jackson.JsonNode json)
           
 java.lang.String createAttachment(java.lang.String docId, Attachment a)
          Creates both the document and the attachment
 java.lang.String createAttachment(java.lang.String docId, java.lang.String revision, Attachment a)
          Adds an attachment to the specified document id.
 void createDatabaseIfNotExists()
          Creates a database on the configured path if it does not exists.
 java.lang.String delete(java.lang.Object o)
          Deletes the Object in the database.
 java.lang.String delete(java.lang.String id, java.lang.String revision)
          Deletes the document in the database.
 java.lang.String deleteAttachment(java.lang.String docId, java.lang.String revision, java.lang.String attachmentId)
           
<T> T
get(java.lang.Class<T> c, java.lang.String id)
           
 java.util.List<java.lang.String> getAllDocIds()
           
 java.io.InputStream getAsStream(java.lang.String docId)
           
 Attachment getAttachment(java.lang.String id, java.lang.String attachmentId)
           
 java.lang.String getDatabaseName()
           
 java.util.List<Revision> getRevisions(java.lang.String id)
           
 java.lang.String path()
           
 java.io.InputStream queryForStream(ViewQuery query)
           
 ViewResult queryView(ViewQuery query)
           
<T> java.util.List<T>
queryView(ViewQuery query, java.lang.Class<T> type)
          This method requires the view result values to be document ids.
 void update(java.lang.Object o)
          Updates the document.
 

Method Detail

create

void create(java.lang.String id,
            org.codehaus.jackson.JsonNode json)
Parameters:
id -
The - document in the form of an Jackson JsonNode.

create

void create(java.lang.Object o)
Creates the Object as a document in the database. If the id is not set it will be generated by the database. The Object's revision field will be updated through the setRevision(String s) method.

Parameters:
o -

update

void update(java.lang.Object o)
Updates the document. The Object's revision field will be updated through the setRevision(String s) method.

Parameters:
o -

delete

java.lang.String delete(java.lang.Object o)
Deletes the Object in the database.

Parameters:
o -
Returns:
the revision of the deleted document

delete

java.lang.String delete(java.lang.String id,
                        java.lang.String revision)
Deletes the document in the database.

Parameters:
id -
revision -
Returns:
the revision of the deleted document

get

<T> T get(java.lang.Class<T> c,
          java.lang.String id)
Type Parameters:
T -
Parameters:
c - the target class to map to.
id - the id of the document in the database.
Returns:
the document mapped as the specified class.

contains

boolean contains(java.lang.String id)
Check if the database contains a document.

Parameters:
id -
Returns:
true if a document with the id exists in the database

getAsStream

java.io.InputStream getAsStream(java.lang.String docId)
Parameters:
docId -
Returns:
the document as an InputStream, don't forget to close the stream when finished.

getRevisions

java.util.List<Revision> getRevisions(java.lang.String id)
Parameters:
id -
Returns:

getAttachment

Attachment getAttachment(java.lang.String id,
                         java.lang.String attachmentId)
Parameters:
id -
attachmentId -
Returns:

createAttachment

java.lang.String createAttachment(java.lang.String docId,
                                  Attachment a)
Creates both the document and the attachment

Parameters:
docId -
a - - the data to be saved as an attachment
Returns:
revision of the created attachment document

createAttachment

java.lang.String createAttachment(java.lang.String docId,
                                  java.lang.String revision,
                                  Attachment a)
Adds an attachment to the specified document id.

Parameters:
docId -
revision -
a - - the data to be saved as an attachment
Returns:
the new revision of the document

deleteAttachment

java.lang.String deleteAttachment(java.lang.String docId,
                                  java.lang.String revision,
                                  java.lang.String attachmentId)
Parameters:
docId -
revision -
attachmentId -
Returns:
the new revision of the document

getAllDocIds

java.util.List<java.lang.String> getAllDocIds()
Returns:
all document ids in the database including design document ids.

queryView

<T> java.util.List<T> queryView(ViewQuery query,
                                java.lang.Class<T> type)
This method requires the view result values to be document ids. {"_id":"_design/ExampleDoc", "views":{ "all": {"map": "function(doc) { emit(null, doc._id);}"}, "by_name": {"map": "function(doc) { emit(doc.name, doc._id);}"} } }

Type Parameters:
T -
Parameters:
query -
type - the type to map the result to
Returns:
the view result mapped as the specified class.

queryView

ViewResult queryView(ViewQuery query)
Parameters:
query -
Returns:

queryForStream

java.io.InputStream queryForStream(ViewQuery query)
Parameters:
view -
keys -
Returns:
the view result as a raw InputStream.

createDatabaseIfNotExists

void createDatabaseIfNotExists()
Creates a database on the configured path if it does not exists.


getDatabaseName

java.lang.String getDatabaseName()
Returns:
name

path

java.lang.String path()
Returns:


Copyright © 2010. All Rights Reserved.