org.ektorp.impl
Class StdCouchDbConnector

java.lang.Object
  extended by org.ektorp.impl.StdCouchDbConnector
All Implemented Interfaces:
CouchDbConnector

public class StdCouchDbConnector
extends java.lang.Object
implements CouchDbConnector

Author:
henrik lundgren

Constructor Summary
StdCouchDbConnector(java.lang.String databaseName, CouchDbInstance dbInstance)
           
StdCouchDbConnector(java.lang.String databaseName, CouchDbInstance dbi, org.codehaus.jackson.map.ObjectMapper om)
           
 
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 node)
           
 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 id)
           
 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 setDatabaseName(java.lang.String s)
           
 void update(java.lang.Object o)
          Updates the document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StdCouchDbConnector

public StdCouchDbConnector(java.lang.String databaseName,
                           CouchDbInstance dbInstance)

StdCouchDbConnector

public StdCouchDbConnector(java.lang.String databaseName,
                           CouchDbInstance dbi,
                           org.codehaus.jackson.map.ObjectMapper om)
Method Detail

path

public java.lang.String path()
Specified by:
path in interface CouchDbConnector
Returns:

setDatabaseName

public void setDatabaseName(java.lang.String s)

create

public void create(java.lang.Object o)
Description copied from interface: CouchDbConnector
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.

Specified by:
create in interface CouchDbConnector

create

public void create(java.lang.String id,
                   org.codehaus.jackson.JsonNode node)
Specified by:
create in interface CouchDbConnector

contains

public boolean contains(java.lang.String id)
Description copied from interface: CouchDbConnector
Check if the database contains a document.

Specified by:
contains in interface CouchDbConnector
Returns:
true if a document with the id exists in the database

createAttachment

public java.lang.String createAttachment(java.lang.String docId,
                                         Attachment a)
Description copied from interface: CouchDbConnector
Creates both the document and the attachment

Specified by:
createAttachment in interface CouchDbConnector
a - - the data to be saved as an attachment
Returns:
revision of the created attachment document

createAttachment

public java.lang.String createAttachment(java.lang.String docId,
                                         java.lang.String revision,
                                         Attachment a)
Description copied from interface: CouchDbConnector
Adds an attachment to the specified document id.

Specified by:
createAttachment in interface CouchDbConnector
a - - the data to be saved as an attachment
Returns:
the new revision of the document

getAttachment

public Attachment getAttachment(java.lang.String id,
                                java.lang.String attachmentId)
Specified by:
getAttachment in interface CouchDbConnector
Returns:

delete

public java.lang.String delete(java.lang.Object o)
Description copied from interface: CouchDbConnector
Deletes the Object in the database.

Specified by:
delete in interface CouchDbConnector
Returns:
the revision of the deleted document

get

public <T> T get(java.lang.Class<T> c,
                 java.lang.String id)
Specified by:
get in interface CouchDbConnector
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.

getRevisions

public java.util.List<Revision> getRevisions(java.lang.String id)
Specified by:
getRevisions in interface CouchDbConnector
Returns:

getAsStream

public java.io.InputStream getAsStream(java.lang.String id)
Specified by:
getAsStream in interface CouchDbConnector
Returns:
the document as an InputStream, don't forget to close the stream when finished.

update

public void update(java.lang.Object o)
Description copied from interface: CouchDbConnector
Updates the document. The Object's revision field will be updated through the setRevision(String s) method.

Specified by:
update in interface CouchDbConnector

delete

public java.lang.String delete(java.lang.String id,
                               java.lang.String revision)
Description copied from interface: CouchDbConnector
Deletes the document in the database.

Specified by:
delete in interface CouchDbConnector
Returns:
the revision of the deleted document

getAllDocIds

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

createDatabaseIfNotExists

public void createDatabaseIfNotExists()
Description copied from interface: CouchDbConnector
Creates a database on the configured path if it does not exists.

Specified by:
createDatabaseIfNotExists in interface CouchDbConnector

getDatabaseName

public java.lang.String getDatabaseName()
Specified by:
getDatabaseName in interface CouchDbConnector
Returns:
name

queryView

public <T> java.util.List<T> queryView(ViewQuery query,
                                       java.lang.Class<T> type)
Description copied from interface: CouchDbConnector
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);}"} } }

Specified by:
queryView in interface CouchDbConnector
type - the type to map the result to
Returns:
the view result mapped as the specified class.

queryView

public ViewResult queryView(ViewQuery query)
Specified by:
queryView in interface CouchDbConnector
Returns:

queryForStream

public java.io.InputStream queryForStream(ViewQuery query)
Specified by:
queryForStream in interface CouchDbConnector
Returns:
the view result as a raw InputStream.

deleteAttachment

public java.lang.String deleteAttachment(java.lang.String docId,
                                         java.lang.String revision,
                                         java.lang.String attachmentId)
Specified by:
deleteAttachment in interface CouchDbConnector
Returns:
the new revision of the document


Copyright © 2010. All Rights Reserved.