public abstract class CouchDbClientBase extends Object
CouchDbClient
,
CouchDbClientAndroid
Modifier and Type | Method and Description |
---|---|
void |
batch(Object object)
Saves a document with batch=ok query param.
|
List<Response> |
bulk(List<?> objects,
boolean allOrNothing)
Performs a Bulk Documents insert request.
|
Changes |
changes()
Provides access to Change Notifications API.
|
boolean |
contains(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(Class<T> classType,
String id)
Finds an Object of the specified type.
|
<T> T |
find(Class<T> classType,
String id,
Params params)
Finds an Object of the specified type.
|
<T> T |
find(Class<T> classType,
String id,
String rev)
Finds an Object of the specified type.
|
InputStream |
find(String id)
Finds a document and return the result as
InputStream . |
InputStream |
find(String id,
String rev)
Finds a document given id and revision and returns the result as
InputStream . |
<T> T |
findAny(Class<T> classType,
String uri)
This method finds any document given a URI.
|
URI |
getBaseUri() |
URI |
getDBUri() |
com.google.gson.Gson |
getGson() |
String |
invokeUpdateHandler(String updateHandlerUri,
String docId,
Params params)
Invokes an Update Handler.
|
String |
invokeUpdateHandler(String updateHandlerUri,
String docId,
String query)
Invokes an Update Handler.
|
Response |
post(Object object)
Saves an object in the database using HTTP POST request.
|
Response |
remove(Object object)
Removes a document from the database.
|
Response |
remove(String id,
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(Object object)
Saves an object in the database, using HTTP PUT request.
|
Response |
saveAttachment(InputStream in,
String name,
String contentType)
Saves an attachment to a new document with a generated UUID as the document id.
|
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 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(Object object)
Updates an object in the database, the object must have the correct
_id and _rev values. |
View |
view(String viewId)
Provides access to CouchDB View APIs.
|
public CouchDbContext context()
CouchDbContext
public CouchDbDesign design()
CouchDbDesign
public Replication replication()
Replication
public Replicator replicator()
Replicator
public <T> T find(Class<T> classType, 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(Class<T> classType, 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(Class<T> classType, String id, 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(Class<T> classType, String uri)
The URI must be URI-encoded.
classType
- The class of type T.uri
- The URI as string.public InputStream find(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 InputStream find(String id, 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 boolean contains(String id)
id
- The document _id field.public Response save(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(Object object)
The database will be responsible for generating the document id.
object
- The object to saveResponse
public void batch(Object object)
object
- The object to save.public Response update(Object object)
_id
and _rev
values.object
- The object to updateResponse
DocumentConflictException
- If a conflict is detected during the update.public Response remove(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(String id, 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 List<Response> bulk(List<?> objects, boolean allOrNothing)
objects
- The List
of objects.allOrNothing
- Indicates whether the request has all-or-nothing semantics.List<Response>
Containing the resulted entries.public Response saveAttachment(InputStream in, String name, String contentType)
To retrieve an attachment, see find(String)
.
instream
- The InputStream
holding the binary data.name
- The attachment name.contentType
- The attachment "Content-Type".Response
public Response saveAttachment(InputStream in, String name, String contentType, String docId, String docRev)
null
.
To retrieve an attachment, see find(String)
.
instream
- 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
DocumentConflictException
public String invokeUpdateHandler(String updateHandlerUri, String docId, String query)
String query = "field=foo&value=bar"; String output = dbClient.invokeUpdateHandler("designDoc/update1", "docId", query);
updateHandlerUri
- The Update Handler URI, in the format: designDoc/update1
docId
- The document id to update.query
- The query string parameters, e.g, field=field1&value=value1
public String invokeUpdateHandler(String updateHandlerUri, String docId, Params params)
Use this method in particular when the docId contain special characters such as slashes (/).
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.query
- 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.
public URI getBaseUri()
public URI getDBUri()
public com.google.gson.Gson getGson()
Copyright © 2011–2016. All rights reserved.