// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static void assertNotEmpty(Object object, String prefix) throws IllegalArgumentException {
// 	if(object == null) {
// 		throw new IllegalArgumentException(format("%s may not be null.", prefix));
// 	} else if(object instanceof String && ((String)object).length() == 0) {
// 		throw new IllegalArgumentException(format("%s may not be empty.", prefix));
// 	} 
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static void assertNull(Object object, String prefix) throws IllegalArgumentException {
// 	if(object != null) {
// 		throw new IllegalArgumentException(format("%s should be null.", prefix));
// 	} 
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static void close(HttpResponse response) {
// 	try {
// 		close(response.getEntity().getContent());
// 	} catch (Exception e) {}
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static String generateUUID() {
// 	return UUID.randomUUID().toString().replace("-", "");
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static String getAsString(JsonObject j, String e) {
// 	return (j.get(e) == null || j.get(e).isJsonNull()) ? null : j.get(e).getAsString();  
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static InputStream getStream(HttpResponse response) {
// 	try { 
// 		return response.getEntity().getContent();
// 	} catch (Exception e) {
// 		throw new CouchDbException("Error reading response. ", e);
// 	}
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static String streamToString(InputStream in) {
//     Scanner s = new Scanner(in);
//     s.useDelimiter("\\A");
//     String str = s.hasNext() ? s.next() : null;
//     close(in);
//     close(s);
//     return str;
// }
// 
// Path: src/main/java/org/lightcouch/URIBuilder.java
// public static URIBuilder buildUri() {
// 	return new URIBuilder();
// }


import static org.lightcouch.CouchDbUtil.assertNotEmpty;
import static org.lightcouch.CouchDbUtil.assertNull;
import static org.lightcouch.CouchDbUtil.close;
import static org.lightcouch.CouchDbUtil.generateUUID;
import static org.lightcouch.CouchDbUtil.getAsString;
import static org.lightcouch.CouchDbUtil.getStream;
import static org.lightcouch.CouchDbUtil.streamToString;
import static org.lightcouch.URIBuilder.buildUri;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.codec.Charsets;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
		HttpResponse response = null;
		try { 
			URI uri = buildUri(getDBUri()).query("batch", "ok").build();
			response = post(uri, getGson().toJson(object));
		} finally {
			close(response);
		}
	}
	
	/**
	 * Updates an object in the database, the object must have the correct <code>_id</code> and <code>_rev</code> values.
	 * @param object The object to update
	 * @throws DocumentConflictException If a conflict is detected during the update.
	 * @return {@link Response}
	 */
	public Response update(Object object) {
		return put(getDBUri(), object, false);
	}
	
	/**
	 * Removes a document from the database. 
	 * <p>The object must have the correct <code>_id</code> and <code>_rev</code> values.
	 * @param object The document to remove as object.
	 * @throws NoDocumentException If the document is not found in the database.
	 * @return {@link Response}
	 */
	public Response remove(Object object) {
		assertNotEmpty(object, "object");
		JsonObject jsonObject = getGson().toJsonTree(object).getAsJsonObject();
		final String id = getAsString(jsonObject, "_id");
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static void assertNotEmpty(Object object, String prefix) throws IllegalArgumentException {
// 	if(object == null) {
// 		throw new IllegalArgumentException(format("%s may not be null.", prefix));
// 	} else if(object instanceof String && ((String)object).length() == 0) {
// 		throw new IllegalArgumentException(format("%s may not be empty.", prefix));
// 	} 
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static void assertNull(Object object, String prefix) throws IllegalArgumentException {
// 	if(object != null) {
// 		throw new IllegalArgumentException(format("%s should be null.", prefix));
// 	} 
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static void close(HttpResponse response) {
// 	try {
// 		close(response.getEntity().getContent());
// 	} catch (Exception e) {}
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static String generateUUID() {
// 	return UUID.randomUUID().toString().replace("-", "");
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static String getAsString(JsonObject j, String e) {
// 	return (j.get(e) == null || j.get(e).isJsonNull()) ? null : j.get(e).getAsString();  
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static InputStream getStream(HttpResponse response) {
// 	try { 
// 		return response.getEntity().getContent();
// 	} catch (Exception e) {
// 		throw new CouchDbException("Error reading response. ", e);
// 	}
// }
// 
// Path: src/main/java/org/lightcouch/CouchDbUtil.java
// public static String streamToString(InputStream in) {
//     Scanner s = new Scanner(in);
//     s.useDelimiter("\\A");
//     String str = s.hasNext() ? s.next() : null;
//     close(in);
//     close(s);
//     return str;
// }
// 
// Path: src/main/java/org/lightcouch/URIBuilder.java
// public static URIBuilder buildUri() {
// 	return new URIBuilder();
// }


// Path: src/main/java/org/lightcouch/CouchDbClientBase.java
import static org.lightcouch.CouchDbUtil.assertNotEmpty;
import static org.lightcouch.CouchDbUtil.assertNull;
import static org.lightcouch.CouchDbUtil.close;
import static org.lightcouch.CouchDbUtil.generateUUID;
import static org.lightcouch.CouchDbUtil.getAsString;
import static org.lightcouch.CouchDbUtil.getStream;
import static org.lightcouch.CouchDbUtil.streamToString;
import static org.lightcouch.URIBuilder.buildUri;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.codec.Charsets;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;

		HttpResponse response = null;
		try { 
			URI uri = buildUri(getDBUri()).query("batch", "ok").build();
			response = post(uri, getGson().toJson(object));
		} finally {
			close(response);
		}
	}
	
	/**
	 * Updates an object in the database, the object must have the correct <code>_id</code> and <code>_rev</code> values.
	 * @param object The object to update
	 * @throws DocumentConflictException If a conflict is detected during the update.
	 * @return {@link Response}
	 */
	public Response update(Object object) {
		return put(getDBUri(), object, false);
	}
	
	/**
	 * Removes a document from the database. 
	 * <p>The object must have the correct <code>_id</code> and <code>_rev</code> values.
	 * @param object The document to remove as object.
	 * @throws NoDocumentException If the document is not found in the database.
	 * @return {@link Response}
	 */
	public Response remove(Object object) {
		assertNotEmpty(object, "object");
		JsonObject jsonObject = getGson().toJsonTree(object).getAsJsonObject();
		final String id = getAsString(jsonObject, "_id");
		final String rev = getAsString(jsonObject, "_rev");