Class CouchDbClientBase
java.lang.Object
org.lightcouch.CouchDbClientBase
- Direct Known Subclasses:
CouchDbClient, CouchDbClientAndroid
Contains a client Public API implementation.
- Author:
- Ahmed Yehia
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidSaves a document with batch=ok query param.Performs bulk documents create and update request.changes()Provides access to Change Notifications API.booleanChecks if a document exist in the database.context()Provides access to DB server APIs.design()Provides access to CouchDB Design Documents.org.apache.http.HttpResponseexecuteRequest(org.apache.http.client.methods.HttpRequestBase request) Executes a HTTP request.<T> TFinds an Object of the specified type.<T> TFinds an Object of the specified type.<T> TFinds an Object of the specified type.Finds a document and return the result asInputStream.Finds a document given id and revision and returns the result asInputStream.<T> TThis method finds any document given a URI.<T> List<T> Find documents using a declarative JSON querying syntax.getDBUri()com.google.gson.GsongetGson()invokeUpdateHandler(String updateHandlerUri, String docId, Params params) Invokes an Update Handler.Saves an object in the database using HTTP POST request.Removes a document from the database.Removes a document from the database given both a document_idand_revvalues.Provides access to CouchDB replication APIs.Provides access to the replicator database.Saves an object in the database, using HTTP PUT request.saveAttachment(InputStream in, String name, String contentType) Saves an attachment to a new document with a generated UUID as the document id.saveAttachment(InputStream in, String name, String contentType, String docId, String docRev) Saves an attachment to an existing document given both a document id and revision, or save to a new document given only the id, and rev asnull.voidsetGsonBuilder(com.google.gson.GsonBuilder gsonBuilder) Sets aGsonBuilderto createGsoninstance.voidSynchronize all design documents with the database.Updates an object in the database, the object must have the correct_idand_revvalues.Provides access to CouchDB View APIs.
-
Method Details
-
context
-
design
-
view
-
replication
-
replicator
-
changes
-
find
Finds an Object of the specified type.- Type Parameters:
T- Object type.- Parameters:
classType- The class of type T.id- The document id.- Returns:
- An object of type T.
- Throws:
NoDocumentException- If the document is not found in the database.
-
find
Finds an Object of the specified type.- Type Parameters:
T- Object type.- Parameters:
classType- The class of type T.id- The document id.params- Extra parameters to append.- Returns:
- An object of type T.
- Throws:
NoDocumentException- If the document is not found in the database.
-
find
Finds an Object of the specified type.- Type Parameters:
T- Object type.- Parameters:
classType- The class of type T.id- The document _id field.rev- The document _rev field.- Returns:
- An object of type T.
- Throws:
NoDocumentException- If the document is not found in the database.
-
findAny
-
find
Finds a document and return the result asInputStream.Note: The stream must be closed after use to release the connection.
- Parameters:
id- The document _id field.- Returns:
- The result as
InputStream - Throws:
NoDocumentException- If the document is not found in the database.- See Also:
-
find
Finds a document given id and revision and returns the result asInputStream.Note: The stream must be closed after use to release the connection.
- Parameters:
id- The document _id field.rev- The document _rev field.- Returns:
- The result as
InputStream - Throws:
NoDocumentException- If the document is not found in the database.
-
findDocs
Find documents using a declarative JSON querying syntax.- Type Parameters:
T- The class type.- Parameters:
jsonQuery- The JSON query string.classOfT- The class of type T.- Returns:
- The result of the query as a
List<T> - Throws:
CouchDbException- If the query failed to execute or the request is invalid.
-
contains
Checks if a document exist in the database.- Parameters:
id- The document _id field.- Returns:
- true If the document is found, false otherwise.
-
save
Saves an object in the database, using HTTP PUT request.If the object doesn't have an
_idvalue, the code will assign aUUIDas the document id.- Parameters:
object- The object to save- Returns:
Response- Throws:
DocumentConflictException- If a conflict is detected during the save.
-
post
-
batch
Saves a document with batch=ok query param.- Parameters:
object- The object to save.
-
update
Updates an object in the database, the object must have the correct_idand_revvalues.- Parameters:
object- The object to update- Returns:
Response- Throws:
DocumentConflictException- If a conflict is detected during the update.
-
remove
Removes a document from the database.The object must have the correct
_idand_revvalues.- Parameters:
object- The document to remove as object.- Returns:
Response- Throws:
NoDocumentException- If the document is not found in the database.
-
remove
Removes a document from the database given both a document_idand_revvalues.- Parameters:
id- The document _id field.rev- The document _rev field.- Returns:
Response- Throws:
NoDocumentException- If the document is not found in the database.
-
bulk
Performs bulk documents create and update request.- Parameters:
objects- TheListof documents objects.newEdits- If false, prevents the database from assigning documents new revision IDs.- Returns:
List<Response>Containing the resulted entries.
-
saveAttachment
Saves an attachment to a new document with a generated UUID as the document id.To retrieve an attachment, see
find(String).- Parameters:
in- TheInputStreamholding the binary data.name- The attachment name.contentType- The attachment "Content-Type".- Returns:
Response
-
saveAttachment
public Response saveAttachment(InputStream in, String name, String contentType, String docId, String docRev) Saves an attachment to an existing document given both a document id and revision, or save to a new document given only the id, and rev asnull.To retrieve an attachment, see
find(String).- Parameters:
in- TheInputStreamholding the binary data.name- The attachment name.contentType- The attachment "Content-Type".docId- The document id to save the attachment under, ornullto save under a new document.docRev- The document revision to save the attachment under, ornullwhen saving to a new document.- Returns:
Response
-
invokeUpdateHandler
Invokes an Update Handler.Params params = new Params() .addParam("field", "foo") .addParam("value", "bar"); String output = dbClient.invokeUpdateHandler("designDoc/update1", "docId", params);- Parameters:
updateHandlerUri- The Update Handler URI, in the format:designDoc/update1docId- The document id to update.params- The query parameters asParams.- Returns:
- The output of the request.
-
executeRequest
public org.apache.http.HttpResponse executeRequest(org.apache.http.client.methods.HttpRequestBase request) Executes a HTTP request.Note: The response must be closed after use to release the connection.
- Parameters:
request- The HTTP request to execute.- Returns:
HttpResponse
-
syncDesignDocsWithDb
public void syncDesignDocsWithDb()Synchronize all design documents with the database. -
setGsonBuilder
public void setGsonBuilder(com.google.gson.GsonBuilder gsonBuilder) Sets aGsonBuilderto createGsoninstance.Useful for registering custom serializers/deserializers, such as JodaTime classes.
- Parameters:
gsonBuilder- TheGsonBuilder
-
getBaseUri
- Returns:
- The base URI.
-
getDBUri
- Returns:
- The database URI.
-
getGson
public com.google.gson.Gson getGson()- Returns:
- The Gson instance.
-