public abstract class CouchDbClientBase
extends java.lang.Object
CouchDbClient
,
CouchDbClientAndroid
Modifier and Type | Method and Description |
---|---|
void |
batch(java.lang.Object object)
Saves a document with batch=ok query param.
|
java.util.List<Response> |
bulk(java.util.List<?> objects,
boolean newEdits)
Performs bulk documents create and update request.
|
Changes |
changes()
Provides access to Change Notifications API.
|
boolean |
contains(java.lang.String id)
Checks if a document exist in the database.
|
CouchDbContext |
context()
Provides access to DB server APIs.
|
CouchDbDesign |
design()
Provides access to CouchDB Design Documents.
|
org.apache.http.HttpResponse |
executeRequest(org.apache.http.client.methods.HttpRequestBase request)
Executes a HTTP request.
|
<T> T |
find(java.lang.Class<T> classType,
java.lang.String id)
Finds an Object of the specified type.
|
<T> T |
find(java.lang.Class<T> classType,
java.lang.String id,
Params params)
Finds an Object of the specified type.
|
<T> T |
find(java.lang.Class<T> classType,
java.lang.String id,
java.lang.String rev)
Finds an Object of the specified type.
|
java.io.InputStream |
find(java.lang.String id)
Finds a document and return the result as
InputStream . |
java.io.InputStream |
find(java.lang.String id,
java.lang.String rev)
Finds a document given id and revision and returns the result as
InputStream . |
<T> T |
findAny(java.lang.Class<T> classType,
java.lang.String uri)
This method finds any document given a URI.
|
<T> java.util.List<T> |
findDocs(java.lang.String jsonQuery,
java.lang.Class<T> classOfT)
Find documents using a declarative JSON querying syntax.
|
java.net.URI |
getBaseUri() |
java.net.URI |
getDBUri() |
com.google.gson.Gson |
getGson() |
java.lang.String |
invokeUpdateHandler(java.lang.String updateHandlerUri,
java.lang.String docId,
Params params)
Invokes an Update Handler.
|
Response |
post(java.lang.Object object)
Saves an object in the database using HTTP POST request.
|
Response |
remove(java.lang.Object object)
Removes a document from the database.
|
Response |
remove(java.lang.String id,
java.lang.String rev)
Removes a document from the database given both a document
_id and _rev values. |
Replication |
replication()
Provides access to CouchDB replication APIs.
|
Replicator |
replicator()
Provides access to the replicator database.
|
Response |
save(java.lang.Object object)
Saves an object in the database, using HTTP PUT request.
|
Response |
saveAttachment(java.io.InputStream in,
java.lang.String name,
java.lang.String contentType)
Saves an attachment to a new document with a generated UUID as the document id.
|
Response |
saveAttachment(java.io.InputStream in,
java.lang.String name,
java.lang.String contentType,
java.lang.String docId,
java.lang.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 as
null . |
void |
setGsonBuilder(com.google.gson.GsonBuilder gsonBuilder)
Sets a
GsonBuilder to create Gson instance. |
void |
syncDesignDocsWithDb()
Synchronize all design documents with the database.
|
Response |
update(java.lang.Object object)
Updates an object in the database, the object must have the correct
_id and _rev values. |
View |
view(java.lang.String viewId)
Provides access to CouchDB View APIs.
|
public CouchDbContext context()
CouchDbContext
public CouchDbDesign design()
CouchDbDesign
public View view(java.lang.String viewId)
viewId
- The view id.View
public Replication replication()
Replication
public Replicator replicator()
Replicator
public <T> T find(java.lang.Class<T> classType, java.lang.String id)
T
- Object type.classType
- The class of type T.id
- The document id.NoDocumentException
- If the document is not found in the database.public <T> T find(java.lang.Class<T> classType, java.lang.String id, Params params)
T
- Object type.classType
- The class of type T.id
- The document id.params
- Extra parameters to append.NoDocumentException
- If the document is not found in the database.public <T> T find(java.lang.Class<T> classType, java.lang.String id, java.lang.String rev)
T
- Object type.classType
- The class of type T.id
- The document _id field.rev
- The document _rev field.NoDocumentException
- If the document is not found in the database.public <T> T findAny(java.lang.Class<T> classType, java.lang.String uri)
The URI must be URI-encoded.
T
- The class type.classType
- The class of type T.uri
- The URI as string.public java.io.InputStream find(java.lang.String id)
InputStream
.
Note: The stream must be closed after use to release the connection.
id
- The document _id field.InputStream
NoDocumentException
- If the document is not found in the database.find(String, String)
public java.io.InputStream find(java.lang.String id, java.lang.String rev)
InputStream
.
Note: The stream must be closed after use to release the connection.
id
- The document _id field.rev
- The document _rev field.InputStream
NoDocumentException
- If the document is not found in the database.public <T> java.util.List<T> findDocs(java.lang.String jsonQuery, java.lang.Class<T> classOfT)
T
- The class type.jsonQuery
- The JSON query string.classOfT
- The class of type T.List<T>
CouchDbException
- If the query failed to execute or the request is invalid.public boolean contains(java.lang.String id)
id
- The document _id field.public Response save(java.lang.Object object)
If the object doesn't have an _id
value, the code will assign a UUID
as the document id.
object
- The object to saveResponse
DocumentConflictException
- If a conflict is detected during the save.public Response post(java.lang.Object object)
The database will be responsible for generating the document id.
object
- The object to saveResponse
public void batch(java.lang.Object object)
object
- The object to save.public Response update(java.lang.Object object)
_id
and _rev
values.object
- The object to updateResponse
DocumentConflictException
- If a conflict is detected during the update.public Response remove(java.lang.Object object)
The object must have the correct _id
and _rev
values.
object
- The document to remove as object.Response
NoDocumentException
- If the document is not found in the database.public Response remove(java.lang.String id, java.lang.String rev)
_id
and _rev
values.id
- The document _id field.rev
- The document _rev field.Response
NoDocumentException
- If the document is not found in the database.public java.util.List<Response> bulk(java.util.List<?> objects, boolean newEdits)
objects
- The List
of documents objects.newEdits
- If false, prevents the database from assigning documents new revision IDs.List<Response>
Containing the resulted entries.public Response saveAttachment(java.io.InputStream in, java.lang.String name, java.lang.String contentType)
To retrieve an attachment, see find(String)
.
in
- The InputStream
holding the binary data.name
- The attachment name.contentType
- The attachment "Content-Type".Response
public Response saveAttachment(java.io.InputStream in, java.lang.String name, java.lang.String contentType, java.lang.String docId, java.lang.String docRev)
null
.
To retrieve an attachment, see find(String)
.
in
- The InputStream
holding the binary data.name
- The attachment name.contentType
- The attachment "Content-Type".docId
- The document id to save the attachment under, or null
to save under a new document.docRev
- The document revision to save the attachment under, or null
when saving to a new document.Response
public java.lang.String invokeUpdateHandler(java.lang.String updateHandlerUri, java.lang.String docId, Params params)
Params params = new Params() .addParam("field", "foo") .addParam("value", "bar"); String output = dbClient.invokeUpdateHandler("designDoc/update1", "docId", params);
updateHandlerUri
- The Update Handler URI, in the format: designDoc/update1
docId
- The document id to update.params
- The query parameters as Params
.public org.apache.http.HttpResponse executeRequest(org.apache.http.client.methods.HttpRequestBase request)
Note: The response must be closed after use to release the connection.
request
- The HTTP request to execute.HttpResponse
public void syncDesignDocsWithDb()
public void setGsonBuilder(com.google.gson.GsonBuilder gsonBuilder)
GsonBuilder
to create Gson
instance.
Useful for registering custom serializers/deserializers, such as JodaTime classes.
gsonBuilder
- The GsonBuilder
public java.net.URI getBaseUri()
public java.net.URI getDBUri()
public com.google.gson.Gson getGson()
Copyright © 2011-2017. All Rights Reserved.