com.fourspaces.couchdb
Class Database

java.lang.Object
  extended by com.fourspaces.couchdb.Database

public class Database
extends Object

This represents a particular database on the CouchDB server

Using this object, you can get/create/update/delete documents. You can also call views (named and adhoc) to query the underlying database.

Author:
mbreese

Method Summary
 ViewResults adhoc(AdHocView view)
          Runs an ad-hoc view from an AdHocView object.
 ViewResults adhoc(String function)
          Runs an ad-hoc view from a string
 void bulkSaveDocuments(Document[] documents)
           
 boolean deleteDocument(Document d)
          Deletes a document
 ViewResults getAllDocuments()
          Runs the standard "_all_docs" view on this database
 ViewResults getAllDocuments(int revision)
          Runs "_all_docs_by_update_seq?startkey=revision" view on this database
 ViewResults getAllDocumentsWithCount(int count)
          Runs the standard "_all_docs" view on this database, with count
 Document getDocument(String id)
          Retrieves a document from the CouchDB database
 Document getDocument(String id, String revision)
          Retrieves a specific document revision
 Document getDocument(String id, String revision, boolean showRevisions)
          Retrieves a specific document revision and (optionally) asks for a list of all revisions
 int getDocumentCount()
          The number of documents in the database at the time that it was retrieved from the session This number probably isn't accurate after the initial load...
 Document getDocumentWithRevisions(String id)
          Retrieves a document from the database and asks for a list of it's revisions.
 String getName()
          The name of the database
 int getUpdateSeq()
          The update seq from the initial database load.
 void saveDocument(Document doc)
          Save a document w/o specifying an id (can be null)
 void saveDocument(Document doc, String docId)
          Save a document at the given _id
 ViewResults view(String fullname)
          Runs a named view Not currently working in CouchDB code
 ViewResults view(View view)
          Runs a named view on the database This will run a view and apply any filtering that is requested (reverse, startkey, etc).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getName

public String getName()
The name of the database

Returns:

getDocumentCount

public int getDocumentCount()
The number of documents in the database at the time that it was retrieved from the session This number probably isn't accurate after the initial load... so if you want an accurate assessment, call Session.getDatabase() again to reload a new database object.

Returns:

getUpdateSeq

public int getUpdateSeq()
The update seq from the initial database load. The update sequence is the 'revision id' of an entire database. Useful for getting all documents in a database since a certain revision

Returns:
See Also:
getAllDocuments()

getAllDocuments

public ViewResults getAllDocuments()
Runs the standard "_all_docs" view on this database

Returns:
ViewResults - the results of the view... this can be iterated over to get each document.

getAllDocumentsWithCount

public ViewResults getAllDocumentsWithCount(int count)
Runs the standard "_all_docs" view on this database, with count

Returns:
ViewResults - the results of the view... this can be iterated over to get each document.

getAllDocuments

public ViewResults getAllDocuments(int revision)
Runs "_all_docs_by_update_seq?startkey=revision" view on this database

Returns:
ViewResults - the results of the view... this can be iterated over to get each document.

view

public ViewResults view(View view)
Runs a named view on the database This will run a view and apply any filtering that is requested (reverse, startkey, etc).

Parameters:
view -
Returns:

view

public ViewResults view(String fullname)
Runs a named view Not currently working in CouchDB code

Parameters:
name - - the fullname (including the document name) ex: foodoc:viewname
Returns:

adhoc

public ViewResults adhoc(String function)
Runs an ad-hoc view from a string

Parameters:
function - - the Javascript function to use as the filter.
Returns:
results

adhoc

public ViewResults adhoc(AdHocView view)
Runs an ad-hoc view from an AdHocView object. You probably won't use this much, unless you want to add filtering to the view (reverse, startkey, etc...)

Parameters:
view -
Returns:

saveDocument

public void saveDocument(Document doc,
                         String docId)
                  throws IOException
Save a document at the given _id

if the docId is null or empty, then this performs a POST to the database and retrieves a new _id.

Otherwise, a PUT is called.

Either way, a new _id and _rev are retrieved and updated in the Document object

Parameters:
doc -
docId -
Throws:
IOException

saveDocument

public void saveDocument(Document doc)
                  throws IOException
Save a document w/o specifying an id (can be null)

Parameters:
doc -
Throws:
IOException

bulkSaveDocuments

public void bulkSaveDocuments(Document[] documents)
                       throws IOException
Throws:
IOException

getDocument

public Document getDocument(String id)
                     throws IOException
Retrieves a document from the CouchDB database

Parameters:
id -
Returns:
Throws:
IOException

getDocumentWithRevisions

public Document getDocumentWithRevisions(String id)
                                  throws IOException
Retrieves a document from the database and asks for a list of it's revisions. The list of revision keys can be retrieved from Document.getRevisions();

Parameters:
id -
Returns:
Throws:
IOException

getDocument

public Document getDocument(String id,
                            String revision)
                     throws IOException
Retrieves a specific document revision

Parameters:
id -
revision -
Returns:
Throws:
IOException

getDocument

public Document getDocument(String id,
                            String revision,
                            boolean showRevisions)
                     throws IOException
Retrieves a specific document revision and (optionally) asks for a list of all revisions

Parameters:
id -
revision -
showRevisions -
Returns:
the document
Throws:
IOException

deleteDocument

public boolean deleteDocument(Document d)
                       throws IOException
Deletes a document

Parameters:
d -
Returns:
was the delete successful?
Throws:
IllegalArgumentException - for blank document id
IOException


Copyright © 2012. All Rights Reserved.