Search in sources :

Example 1 with Response

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

the class Database method saveAttachment.

/**
 * Creates an attachment from the specified InputStream and a new document with a generated
 * document ID.
 * <P>Example usage:</P>
 * <pre>
 * {@code
 * byte[] bytesToDB = "binary data".getBytes();
 * ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytesToDB);
 * Response response = db.saveAttachment(bytesIn, "foo.txt", "text/plain");
 * }
 * </pre>
 * <p>To retrieve an attachment, see {@link #find(Class, String, Params)}</p>
 *
 * @param in          The {@link InputStream} providing the binary data.
 * @param name        The attachment name.
 * @param contentType The attachment "Content-Type".
 * @return {@link com.cloudant.client.api.model.Response}
 * @see <a
 * href="https://console.bluemix.net/docs/services/Cloudant/api/attachments.html#attachments"
 * target="_blank">Attachments</a>
 */
public com.cloudant.client.api.model.Response saveAttachment(InputStream in, String name, String contentType) {
    Response couchDbResponse = db.saveAttachment(in, name, contentType);
    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 2 with Response

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

the class Database method update.

/**
 * Updates an object in the database similarly to {@link #update(Object)}, but specifying the
 * write quorum.
 *
 * @param object      the object to update
 * @param writeQuorum the write quorum
 * @return {@link com.cloudant.client.api.model.Response}
 * @throws DocumentConflictException if a conflict is detected during the update.
 * @see Database#update(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 update(Object object, int writeQuorum) {
    Response couchDbResponse = client.couchDbClient.put(getDBUri(), object, false, 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 3 with Response

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

the class Database method remove.

/**
 * Removes a document from the database.
 * <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");
 * //now remove the remote Bar
 * Response response = db.remove(bar);
 * }
 * </pre>
 *
 * @param object the document to remove as an object
 * @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(Object object) {
    Response couchDbResponse = db.remove(object);
    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 4 with Response

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

the class Replicator method save.

/**
 * Adds a new document to the replicator database.
 *
 * @return {@link Response}
 */
public com.cloudant.client.api.model.Response save() {
    Response couchDbResponse = replicator.save();
    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)

Example 5 with Response

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

the class Database method update.

/**
 * Updates an object in the database, the object must have the correct {@code _id} and
 * {@code _rev} values.
 * <P>Example usage:</P>
 * <pre>
 * {@code
 * //get a Bar object from the database
 * Bar bar = db.find(Bar.class, "exampleId");
 * //change something about bar
 * bar.setSomeProperty(true);
 * //now update the remote Bar
 * Response responseUpdate = db.update(bar);
 * }
 * </pre>
 * <P>
 * Note that the Java object is not modified by the update operation and so will not include the
 * revision generated by the database server. You can obtain the server revision for this write
 * from the response, for example:
 * </P>
 * <pre>
 *     {@code
 *     Foo foo = new Foo();
 *     Response response = db.update(foo);
 *     foo.setRevision(response.getRevision());
 *     }
 * </pre>
 *
 * @param object the object to update
 * @return {@link com.cloudant.client.api.model.Response}
 * @throws DocumentConflictException if a conflict is detected during the update.
 * @see <a
 * href="https://console.bluemix.net/docs/services/Cloudant/api/document.html#update"
 * target="_blank">Documents - update</a>
 */
public com.cloudant.client.api.model.Response update(Object object) {
    Response couchDbResponse = db.update(object);
    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