use of com.cloudant.client.internal.DatabaseURIHelper in project java-cloudant by cloudant.
the class Database method deleteIndex.
/**
* Delete an index with the specified name and type in the given design document.
*
* @param indexName name of the index
* @param designDocId ID of the design doc (the _design prefix will be added if not present)
* @param type type of the index, valid values or "text" or "json"
*/
public void deleteIndex(String indexName, String designDocId, String type) {
assertNotEmpty(indexName, "indexName");
assertNotEmpty(designDocId, "designDocId");
assertNotNull(type, "type");
if (!designDocId.startsWith("_design")) {
designDocId = "_design/" + designDocId;
}
URI uri = new DatabaseURIHelper(db.getDBUri()).path("_index").path(designDocId).path(type).path(indexName).build();
InputStream response = null;
try {
HttpConnection connection = Http.DELETE(uri);
response = client.couchDbClient.executeToInputStream(connection);
getResponse(response, Response.class, client.getGson());
} finally {
close(response);
}
}
use of com.cloudant.client.internal.DatabaseURIHelper in project java-cloudant by cloudant.
the class CouchDatabaseBase method find.
/**
* Finds a document given id and revision and returns the result as {@link InputStream}.
* <p><b>Note</b>: The stream must be closed after use to release the connection.
*
* @param id The document _id field.
* @param rev The document _rev field.
* @return The result as {@link InputStream}
* @throws NoDocumentException If the document is not found in the database.
*/
public InputStream find(String id, String rev) {
assertNotEmpty(id, "id");
assertNotEmpty(rev, "rev");
final URI uri = new DatabaseURIHelper(dbUri).documentUri(id, "rev", rev);
return couchDbClient.get(uri);
}
use of com.cloudant.client.internal.DatabaseURIHelper in project java-cloudant by cloudant.
the class Replicator method find.
/**
* Finds a document in the replicator database.
*
* @return {@link ReplicatorDocument}
*/
public ReplicatorDocument find() {
assertNotEmpty(replicatorDoc.getId(), "Doc id");
final URI uri = new DatabaseURIHelper(dbURI).documentUri(replicatorDoc.getId(), replicatorDoc.getRevision());
return client.get(uri, ReplicatorDocument.class);
}
use of com.cloudant.client.internal.DatabaseURIHelper in project java-cloudant by cloudant.
the class Replicator method remove.
/**
* Removes a document from the replicator database.
*
* @return {@link Response}
*/
public Response remove() {
assertNotEmpty(replicatorDoc.getId(), "Doc id");
assertNotEmpty(replicatorDoc.getRevision(), "Doc rev");
final URI uri = new DatabaseURIHelper(dbURI).path(replicatorDoc.getId()).query("rev", replicatorDoc.getRevision()).build();
return client.delete(uri);
}
use of com.cloudant.client.internal.DatabaseURIHelper in project java-cloudant by cloudant.
the class Database method post.
/**
* Creates a document in the database similarly to {@link Database#post(Object)} but using a
* specific write quorum.
*
* @param object The object to save
* @param writeQuorum the write Quorum
* @return {@link com.cloudant.client.api.model.Response}
* @see Database#post(Object)
* @see <a
* href="https://console.bluemix.net/docs/services/Cloudant/api/document.html#quorum-writing-and-reading-data"
* target="_blank">Documents - quorum</a>
*/
public com.cloudant.client.api.model.Response post(Object object, int writeQuorum) {
assertNotEmpty(object, "object");
InputStream response = null;
try {
URI uri = new DatabaseURIHelper(db.getDBUri()).query("w", writeQuorum).build();
response = client.couchDbClient.executeToInputStream(createPost(uri, client.getGson().toJson(object), "application/json"));
Response couchDbResponse = getResponse(response, Response.class, client.getGson());
com.cloudant.client.api.model.Response cloudantResponse = new com.cloudant.client.api.model.Response(couchDbResponse);
return cloudantResponse;
} finally {
close(response);
}
}
Aggregations