Search in sources :

Example 21 with DatabaseURIHelper

use of com.cloudant.client.internal.DatabaseURIHelper in project java-cloudant by cloudant.

the class CouchDatabaseBase method find.

/**
 * Finds an Object of the specified type.
 *
 * @param <T>       Object type.
 * @param classType The class of type T.
 * @param id        The document _id field.
 * @param rev       The document _rev field.
 * @return An object of type T.
 * @throws NoDocumentException If the document is not found in the database.
 */
public <T> T find(Class<T> classType, String id, String rev) {
    assertNotEmpty(classType, "Class");
    assertNotEmpty(id, "id");
    assertNotEmpty(id, "rev");
    final URI uri = new DatabaseURIHelper(dbUri).documentUri(id, "rev", rev);
    return couchDbClient.get(uri, classType);
}
Also used : DatabaseURIHelper(com.cloudant.client.internal.DatabaseURIHelper) URI(java.net.URI)

Example 22 with DatabaseURIHelper

use of com.cloudant.client.internal.DatabaseURIHelper in project java-cloudant by cloudant.

the class CouchDatabaseBase method post.

/**
 * Saves an object in the database using HTTP <tt>POST</tt> request.
 * <p>The database will be responsible for generating the document id.
 *
 * @param object The object to save
 * @return {@link Response}
 */
public Response post(Object object) {
    assertNotEmpty(object, "object");
    InputStream response = null;
    try {
        response = couchDbClient.post(new DatabaseURIHelper(dbUri).getDatabaseUri(), getGson().toJson(object));
        return getResponse(response, Response.class, getGson());
    } finally {
        close(response);
    }
}
Also used : InputStream(java.io.InputStream) DatabaseURIHelper(com.cloudant.client.internal.DatabaseURIHelper)

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