Search in sources :

Example 11 with DatabaseURIHelper

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);
    }
}
Also used : HttpConnection(com.cloudant.http.HttpConnection) InputStream(java.io.InputStream) DatabaseURIHelper(com.cloudant.client.internal.DatabaseURIHelper) URI(java.net.URI)

Example 12 with DatabaseURIHelper

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);
}
Also used : DatabaseURIHelper(com.cloudant.client.internal.DatabaseURIHelper) URI(java.net.URI)

Example 13 with DatabaseURIHelper

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);
}
Also used : DatabaseURIHelper(com.cloudant.client.internal.DatabaseURIHelper) URI(java.net.URI)

Example 14 with DatabaseURIHelper

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);
}
Also used : DatabaseURIHelper(com.cloudant.client.internal.DatabaseURIHelper) URI(java.net.URI)

Example 15 with DatabaseURIHelper

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);
    }
}
Also used : Response(com.cloudant.client.org.lightcouch.Response) AllDocsRequestResponse(com.cloudant.client.internal.views.AllDocsRequestResponse) CouchDbUtil.getResponse(com.cloudant.client.org.lightcouch.internal.CouchDbUtil.getResponse) InputStream(java.io.InputStream) DatabaseURIHelper(com.cloudant.client.internal.DatabaseURIHelper) URI(java.net.URI)

Aggregations

DatabaseURIHelper (com.cloudant.client.internal.DatabaseURIHelper)22 URI (java.net.URI)20 InputStream (java.io.InputStream)11 CouchDbUtil.getAsString (com.cloudant.client.org.lightcouch.internal.CouchDbUtil.getAsString)3 HttpConnection (com.cloudant.http.HttpConnection)3 JsonObject (com.google.gson.JsonObject)3 InputStreamReader (java.io.InputStreamReader)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 CouchDbUtil.getResponse (com.cloudant.client.org.lightcouch.internal.CouchDbUtil.getResponse)2 Reader (java.io.Reader)2 QueryResult (com.cloudant.client.api.query.QueryResult)1 AllDocsRequestResponse (com.cloudant.client.internal.views.AllDocsRequestResponse)1 Response (com.cloudant.client.org.lightcouch.Response)1 CouchDbUtil.streamToString (com.cloudant.client.org.lightcouch.internal.CouchDbUtil.streamToString)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1