Search in sources :

Example 6 with Response

use of com.cloudant.client.org.lightcouch.Response in project java-cloudant by cloudant.

the class Database method bulk.

/**
 * Uses the {@code _bulk_docs} endpoint to insert multiple documents into the database in a
 * single HTTP request.
 * <P>Example usage:</P>
 * <pre>
 * {@code
 * //create a list
 * List<Object> newDocs = new ArrayList<Object>();
 * //add some objects to the list
 * newDocs.add(new Foo());
 * newDocs.add(new JsonObject());
 * //use the bulk insert
 * List<Response> responses = db.bulk(newDocs);
 * }
 * </pre>
 *
 * @param objects the {@link List} of objects
 * @return {@code List<Response>} one per object
 * @see <a
 * href="https://console.bluemix.net/docs/services/Cloudant/api/document.html#bulk-operations"
 * target="_blank">Documents - bulk operations</a>
 */
public List<com.cloudant.client.api.model.Response> bulk(List<?> objects) {
    List<Response> couchDbResponseList = db.bulk(objects, false);
    List<com.cloudant.client.api.model.Response> cloudantResponseList = new ArrayList<com.cloudant.client.api.model.Response>(couchDbResponseList.size());
    for (Response couchDbResponse : couchDbResponseList) {
        com.cloudant.client.api.model.Response response = new com.cloudant.client.api.model.Response(couchDbResponse);
        cloudantResponseList.add(response);
    }
    return cloudantResponseList;
}
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) ArrayList(java.util.ArrayList)

Example 7 with Response

use of com.cloudant.client.org.lightcouch.Response in project java-cloudant by cloudant.

the class Database method removeAttachment.

/**
 * Removes an attachment from the specified document.
 * <p>The object must have the correct {@code _id} and {@code _rev} values.</p>
 * <P>Example usage:</P>
 * <pre>
 * {@code
 * //get a Bar object from the database
 * Bar bar = db.find(Bar.class, "exampleId");
 * String attachmentName = "example.jpg";
 * //now remove the remote Bar attachment
 * Response response = db.removeAttachment(bar, attachmentName);
 * }
 * </pre>
 *
 * @param object the document to remove as an object
 * @param attachmentName the attachment name to remove
 * @return {@link com.cloudant.client.api.model.Response}
 * @throws NoDocumentException If the document is not found in the database.
 * @throws DocumentConflictException If a conflict is detected during the removal.
 * @see <a
 * href="https://console.bluemix.net/docs/services/Cloudant/api/attachments.html#delete"
 * target="_blank">Documents - delete</a>
 */
public com.cloudant.client.api.model.Response removeAttachment(Object object, String attachmentName) {
    Response couchDbResponse = db.removeAttachment(object, attachmentName);
    com.cloudant.client.api.model.Response response = new com.cloudant.client.api.model.Response(couchDbResponse);
    return 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)

Example 8 with Response

use of com.cloudant.client.org.lightcouch.Response 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)

Example 9 with Response

use of com.cloudant.client.org.lightcouch.Response in project java-cloudant by cloudant.

the class Database method save.

/**
 * Saves a document in the database similarly to {@link Database#save(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}
 * @throws DocumentConflictException If a conflict is detected during the save.
 * @see Database#save(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 save(Object object, int writeQuorum) {
    Response couchDbResponse = client.couchDbClient.put(getDBUri(), object, true, writeQuorum);
    com.cloudant.client.api.model.Response response = new com.cloudant.client.api.model.Response(couchDbResponse);
    return 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)

Example 10 with Response

use of com.cloudant.client.org.lightcouch.Response in project java-cloudant by cloudant.

the class Database method remove.

/**
 * Removes the document from the database with the specified {@code _id} and {@code _rev}
 * values.
 * <P>Example usage:</P>
 * <pre>
 * {@code
 * Response response = db.remove("exampleId", "1-12345exampleRev");
 * }
 * </pre>
 *
 * @param id  the document _id field
 * @param rev the document _rev field
 * @return {@link com.cloudant.client.api.model.Response}
 * @throws NoDocumentException If the document is not found in the database.
 * @see <a
 * href="https://console.bluemix.net/docs/services/Cloudant/api/document.html#delete"
 * target="_blank">Documents - delete</a>
 */
public com.cloudant.client.api.model.Response remove(String id, String rev) {
    Response couchDbResponse = db.remove(id, rev);
    com.cloudant.client.api.model.Response response = new com.cloudant.client.api.model.Response(couchDbResponse);
    return 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)

Aggregations

Response (com.cloudant.client.org.lightcouch.Response)14 AllDocsRequestResponse (com.cloudant.client.internal.views.AllDocsRequestResponse)12 CouchDbUtil.getResponse (com.cloudant.client.org.lightcouch.internal.CouchDbUtil.getResponse)12 DatabaseURIHelper (com.cloudant.client.internal.DatabaseURIHelper)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1