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.
|
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.
|
HttpConnection |
executeRequest(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.
|
Replication |
replication()
Provides access to Cloudant replication APIs.
|
Replicator |
replicator()
Provides access to Cloudant replication APIs.
|
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)
name
- name of database to accesscreate
- flag indicating whether to create the database if it does not existcom.cloudant.client.org.lightcouch.NoDocumentException
- if the database does not
exist and create was falsepublic void deleteDB(java.lang.String dbName)
dbName
- the database namepublic void createDB(java.lang.String dbName)
dbName
- the database namecom.cloudant.client.org.lightcouch.PreconditionFailedException
- if a database with
the same name
already existspublic java.net.URI getBaseUri()
public java.util.List<java.lang.String> getAllDbs()
public java.lang.String serverVersion()
public Replication replication()
Replication
,
Replication - _replicate
public Replicator replicator()
Replicator
,
Replication - _replicator
public HttpConnection executeRequest(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
}
request
- The HTTP request to execute, obtained from Http
.HttpConnection
that has been executedcom.cloudant.client.org.lightcouch.CouchDbException
- 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()