public class Database
extends java.lang.Object
NoDocumentException
if the database does not exist.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)
Performs a Bulk Documents insert request.
|
Changes |
changes()
Provides access to Change Notifications API.
|
boolean |
contains(java.lang.String id)
Checks if a document exist in the database.
|
void |
createIndex(java.lang.String indexDefinition)
create a new Index
|
void |
createIndex(java.lang.String indexName,
java.lang.String designDocName,
java.lang.String indexType,
IndexField[] fields)
Create a new index
|
void |
deleteIndex(java.lang.String indexName,
java.lang.String designDocId)
Delete an index
|
DbDesign |
design()
Provides access to CouchDB Design Documents.
|
void |
ensureFullCommit()
Requests the database commits any recent changes to disk.
|
<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> |
findByIndex(java.lang.String selectorJson,
java.lang.Class<T> classOfT)
Find documents using an index
|
<T> java.util.List<T> |
findByIndex(java.lang.String selectorJson,
java.lang.Class<T> classOfT,
FindByIndexOptions options)
Find documents using an index
|
java.net.URI |
getDBUri() |
java.util.Map<java.lang.String,java.util.EnumSet<Permissions>> |
getPermissions()
Returns the Permissions of this database.
|
Shard |
getShard(java.lang.String docId)
Get info about the shard a document belongs to
|
java.util.List<Shard> |
getShards()
Get info about the shards in the database
|
DbInfo |
info() |
java.lang.String |
invokeUpdateHandler(java.lang.String updateHandlerUri,
java.lang.String docId,
Params params)
Invokes an Update Handler.
|
java.lang.String |
invokeUpdateHandler(java.lang.String updateHandlerUri,
java.lang.String docId,
java.lang.String query)
Deprecated.
use
invokeUpdateHandler(String, String, Params) instead. |
java.util.List<Index> |
listIndices()
List all indices
|
Response |
post(java.lang.Object object)
Saves an object in the database using HTTP POST request.
|
Response |
post(java.lang.Object object,
int writeQuorum)
Saves an object in the database using HTTP POST request with specificied write
quorum
|
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. |
Response |
save(java.lang.Object object)
Saves an object in the database, using HTTP PUT request.
|
Response |
save(java.lang.Object object,
int writeQuorum)
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 . |
Search |
search(java.lang.String searchIndexId)
Provides access to Cloudant Search APIs.
|
void |
setPermissions(java.lang.String userNameorApikey,
java.util.EnumSet<Permissions> permissions)
Set permissions for a user/apiKey on this database.
|
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. |
Response |
update(java.lang.Object object,
int writeQuorum)
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 void setPermissions(java.lang.String userNameorApikey, java.util.EnumSet<Permissions> permissions)
Note this method is only applicable to databases that support the Cloudant authorization API such as Cloudant DBaaS. For unsupported databases consider using the /db/_security endpoint.
userNameorApikey
- permissions
- permissions to grantjava.lang.UnsupportedOperationException
- if called on a database that does not provide the
Cloudant authorization APIpublic java.util.Map<java.lang.String,java.util.EnumSet<Permissions>> getPermissions()
Note this method is only applicable to databases that support the Cloudant authorization API such as Cloudant DBaaS. For unsupported databases consider using the /db/_security endpoint.
java.lang.UnsupportedOperationException
- if called on a database that does not provide the
Cloudant authorization APIpublic java.util.List<Shard> getShards()
public Shard getShard(java.lang.String docId)
docId
- document IDpublic void createIndex(java.lang.String indexName, java.lang.String designDocName, java.lang.String indexType, IndexField[] fields)
indexName
- optional name of the index (if not provided one will be generated)designDocName
- optional name of the design doc in which the index will be createdindexType
- optional, type of index (only "json" as of now)fields
- array of fields in the indexpublic void createIndex(java.lang.String indexDefinition)
indexDefinition
- public <T> java.util.List<T> findByIndex(java.lang.String selectorJson, java.lang.Class<T> classOfT)
selectorJson
- JSON object describing criteria used to select documents.
Is of the form "selector": {<your data here>}
classOfT
- The class of Java objects to be returnedpublic <T> java.util.List<T> findByIndex(java.lang.String selectorJson, java.lang.Class<T> classOfT, FindByIndexOptions options)
selectorJson
- JSON object describing criteria used to select documents.
Is of the form "selector": {<your data here>}
options
- query Index options
classOfT
- The class of Java objects to be returnedpublic java.util.List<Index> listIndices()
public void deleteIndex(java.lang.String indexName, java.lang.String designDocId)
indexName
- name of the indexdesignDocId
- ID of the design docpublic Search search(java.lang.String searchIndexId)
Search
public DbDesign design()
CouchDbDesign
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.
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 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 save(java.lang.Object object, int writeQuorum)
If the object doesn't have an _id
value, the code will assign a
UUID
as the document id.
object
- The object to savewriteQuorum
- the write QuorumResponse
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 Response post(java.lang.Object object, int writeQuorum)
The database will be responsible for generating the document id.
object
- The object to savewriteQuorum
- the write QuorumResponse
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 update(java.lang.Object object, int writeQuorum)
_id
and
_rev
values.object
- The object to updatewriteQuorum
- the write QuorumResponse
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)
objects
- The List
of objects.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
DocumentConflictException
@Deprecated public java.lang.String invokeUpdateHandler(java.lang.String updateHandlerUri, java.lang.String docId, java.lang.String query)
invokeUpdateHandler(String, String, Params)
instead.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 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 void syncDesignDocsWithDb()
public java.net.URI getDBUri()
public DbInfo info()
CouchDbInfo
Containing the DB info.public void ensureFullCommit()