public class CloudantClient
extends java.lang.Object
This class is the main object to use to gain access to the Cloudant APIs.
CloudantClient client = new 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)
db.view()
db.changes()
db.design()
account.replication()
and account.replicator()
client.shutdown()
to
ensure proper release of resources.Constructor and Description |
---|
CloudantClient(java.lang.String account,
java.lang.String authCookie)
Constructs a new instance of this class and connects to the cloudant account with the
specified credentials
|
CloudantClient(java.lang.String account,
java.lang.String authCookie,
ConnectOptions connectOptions)
Constructs a new instance of this class and connects to the cloudant account with the
specified credentials
|
CloudantClient(java.lang.String account,
java.lang.String loginUsername,
java.lang.String password)
Constructs a new instance of this class and connects to the cloudant server with the
specified credentials
|
CloudantClient(java.lang.String account,
java.lang.String loginUsername,
java.lang.String password,
ConnectOptions connectOptions)
Constructs a new instance of this class and connects to the cloudant account with the
specified credentials
|
Modifier and Type | Method and Description |
---|---|
void |
createDB(java.lang.String dbName)
Request to create a new database; if one doesn't exist.
|
Database |
database(java.lang.String name,
boolean create)
Get a database
|
void |
deleteDB(java.lang.String dbName)
Request to delete a database.
|
void |
deleteDB(java.lang.String dbName,
java.lang.String confirm)
Deprecated.
use
deleteDB(String) |
org.apache.http.HttpResponse |
executeRequest(org.apache.http.client.methods.HttpRequestBase request)
Executes a HTTP request.
|
ApiKey |
generateApiKey()
Generate an API key
|
java.util.List<Task> |
getActiveTasks()
Get all active tasks
|
java.util.List<java.lang.String> |
getAllDbs() |
java.net.URI |
getBaseUri() |
java.lang.String |
getCookie()
Get the cookieStore
|
com.google.gson.Gson |
getGson() |
Membership |
getMembership()
Get the list of nodes in a cluster
|
Replication |
replication()
Provides access to Cloudant replication APIs.
|
Replicator |
replicator()
Provides access to Cloudant replication APIs.
|
java.lang.String |
serverVersion() |
void |
setGsonBuilder(com.google.gson.GsonBuilder gsonBuilder)
Sets a
GsonBuilder to create Gson instance. |
void |
shutdown()
Shuts down the connection manager used by this client instance.
|
java.util.List<java.lang.String> |
uuids(long count)
Request cloudant to send a list of UUIDs.
|
public CloudantClient(java.lang.String account, java.lang.String loginUsername, java.lang.String password)
account
- For cloudant.com, the cloudant account to connect to. For Cloudant
local, the server URLloginUsername
- The apiKey (if using an APIKey, else pass in the account for this
parameter also)password
- The Password credentialpublic CloudantClient(java.lang.String account, java.lang.String loginUsername, java.lang.String password, ConnectOptions connectOptions)
account
- For cloudant.com, the cloudant account to connect to. For Cloudant
local, the server URLloginUsername
- The apiKey (if using an APIKey, else pass in the account for this
parameter also)password
- The Password credentialconnectOptions
- optional properties to connect e.g connectionTime,socketTimeout,etcpublic CloudantClient(java.lang.String account, java.lang.String authCookie)
account
- For cloudant.com, the cloudant account to connect to. For Cloudant
local, the server URLauthCookie
- The cookie obtained from last loginpublic CloudantClient(java.lang.String account, java.lang.String authCookie, ConnectOptions connectOptions)
account
- For cloudant.com, the cloudant account to connect to. For Cloudant
local, the server URLaccount
- The cloudant account to connect toauthCookie
- The cookie obtained from last loginconnectOptions
- optional properties to connect e.g connectionTime,socketTimeout,etcpublic ApiKey generateApiKey()
public java.util.List<Task> getActiveTasks()
public java.lang.String getCookie()
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 doesnt exist.@Deprecated public void deleteDB(java.lang.String dbName, java.lang.String confirm)
deleteDB(String)
dbName
- The database nameconfirm
- A confirmation string with the value: delete databasepublic void deleteDB(java.lang.String dbName)
dbName
- The database namepublic void createDB(java.lang.String dbName)
dbName
- The Database namepublic java.net.URI getBaseUri()
public java.util.List<java.lang.String> getAllDbs()
public java.lang.String serverVersion()
public Replication replication()
Replication
public Replicator replicator()
Replication
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 shutdown()
public java.util.List<java.lang.String> uuids(long count)
count
- The count of UUIDs.public void setGsonBuilder(com.google.gson.GsonBuilder gsonBuilder)
GsonBuilder
to create Gson
instance.
Useful for registering custom serializers/deserializers, such as Datetime formats.
public com.google.gson.Gson getGson()