public class CloudantClient
extends java.lang.Object
This class is the main object to use to gain access to the Cloudant APIs. Instances of CloudantClient are created using a ClientBuilder. Once created a CloudantClient is immutable and safe to access from multiple threads.
CloudantClient client = ClientBuilder.account
CloudantClient("mycloudantaccount","myusername",
"mypassword");
Database
from the client e.g.:
Database db = client.database("customers",false);
CRUD
APIs accessed from the Database
e.g.:
Database.createIndex(String, String, String, IndexField[])
e.g.:
db.createIndex("Person_name", "Person_name_design_doc", "json", new IndexField[] { new IndexField
("Person_name",SortOrder.asc)})
Database.findByIndex(String, Class)
e.g.:
db.findByIndex(" \"selector\": {
\"Person_name\": \"Alec Guinness\" }", Movie.class)}
Database.deleteIndex(String, String)
e.g.:
db.deleteIndex("Person_name", "Person_name_design_doc")
db.search("views101/animals")
com.cloudant.client.api.views
db.changes()
db.getDesignDocumentManager()
account.replication()
and account.replicator()
Modifier and Type | Method and Description |
---|---|
void |
createDB(java.lang.String dbName)
Request to create a new database with the specified name.
|
void |
createPartitionedDB(java.lang.String dbName)
Request to create a new partitioned database with the specified name.
|
Database |
database(java.lang.String name,
boolean create)
Get a database reference for the database with the specified name.
|
void |
deleteDB(java.lang.String dbName)
Request to delete the database with the specified name.
|
com.cloudant.http.HttpConnection |
executeRequest(com.cloudant.http.HttpConnection request)
Executes a HTTP request.
|
ApiKey |
generateApiKey()
Use the authorization feature to generate new API keys to access your data.
|
java.util.List<Task> |
getActiveTasks()
Get the list of active tasks from the server.
|
java.util.List<java.lang.String> |
getAllDbs()
List all the databases on the server for the Cloudant account.
|
java.net.URI |
getBaseUri() |
com.google.gson.Gson |
getGson() |
Membership |
getMembership()
Get the list of all nodes and the list of active nodes in the cluster.
|
MetaInformation |
metaInformation()
Get the welcome message metadata.
|
Replication |
replication()
Provides access to Cloudant replication APIs.
|
Replicator |
replicator()
Provides access to Cloudant replication APIs.
|
SchedulerDocsResponse.Doc |
schedulerDoc(java.lang.String docId)
Get replication document state for a given replication document ID.
|
SchedulerDocsResponse |
schedulerDocs()
Lists replication documents.
|
SchedulerJobsResponse |
schedulerJobs()
Lists replication jobs.
|
java.lang.String |
serverVersion()
Get the reported server version from the welcome message metadata.
|
void |
shutdown()
Shuts down the connection manager used by this client instance.
|
java.util.List<java.lang.String> |
uuids(long count)
Request a list of generated UUIDs from the Cloudant server.
|
public ApiKey generateApiKey()
Example usage:
ApiKey key = client.generateApiKey();
System.out.println(key);
Example output:
key: isdaingialkyciffestontsk password: XQiDHmwnkUu4tknHIjjs2P64
Database.setPermissions(String, EnumSet)
public java.util.List<Task> getActiveTasks()
public Membership getMembership()
public Database database(java.lang.String name, boolean create)
Note that if create is false
and the database does not exist an instance will be
returned, but the first operation on that instance will throw a
NoDocumentException
because the database does not
exist.
name
- name of database to accesscreate
- flag indicating whether to create the database if it does not existpublic void deleteDB(java.lang.String dbName)
dbName
- the database namepublic void createDB(java.lang.String dbName)
dbName
- the database namePreconditionFailedException
- if a database with
the same name
already existspublic void createPartitionedDB(java.lang.String dbName)
dbName
- the database namePreconditionFailedException
- if a database with
the same name
already existsDatabase.query(String, String, Class)
,
Database.search(String, String)
,
SettableViewParameters.Common.partition(String)
public java.net.URI getBaseUri()
public java.util.List<java.lang.String> getAllDbs()
public java.lang.String serverVersion()
public MetaInformation metaInformation()
public Replication replication()
Replication
,
Replication - the _replicate endpointpublic Replicator replicator()
Replicator
,
Replication - the _replicator databasepublic SchedulerJobsResponse schedulerJobs()
public SchedulerDocsResponse schedulerDocs()
public SchedulerDocsResponse.Doc schedulerDoc(java.lang.String docId)
docId
- The replication document IDdocId
public com.cloudant.http.HttpConnection executeRequest(com.cloudant.http.HttpConnection request)
Note: Streams obtained from the HttpConnection must be closed after use to release the connection.
HttpConnection response = account.executeRequest(Http.GET(new URL(account.getBaseUri() +
"/aNewAPI")));
if (response.getConnection().getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream stream = response.responseAsInputStream();
//process stream
}
Note that whilst the request can be constructed for any URL the connection information (e.g. Cookie, BasicAuth etc) specified by this client will be added to the request before it is executed.
request
- The HTTP request to execute, obtained from Http
.HttpConnection
that has been executedCouchDbException
- for error HTTP status codes or if there is an IOException
public void shutdown()
public java.util.List<java.lang.String> uuids(long count)
count
- the number of UUIDspublic com.google.gson.Gson getGson()