public Replicator(CouchDbClientBase dbc) { this.dbc = dbc; replicatorDoc = new ReplicatorDocument(); replicatorDB = "_replicator"; // default replicator db userCtxRoles = new String[0]; // default roles dbURI = buildUri(dbc.getBaseUri()).path(replicatorDB).path("/").build(); }
CouchDbClientBase(CouchDbConfig config) { final CouchDbProperties props = config.getProperties(); this.httpClient = createHttpClient(props); this.gson = initGson(new GsonBuilder()); this.host = new HttpHost(props.getHost(), props.getPort(), props.getProtocol()); final String path = props.getPath() != null ? props.getPath() : ""; this.baseURI = buildUri().scheme(props.getProtocol()).host(props.getHost()).port(props.getPort()).path("/").path(path).build(); this.dbURI = buildUri(baseURI).path(props.getDbName()).path("/").build(); this.context = new CouchDbContext(this, props); this.design = new CouchDbDesign(this); }
/** * Finds a document in the replicator database. * @return {@link ReplicatorDocument} */ public ReplicatorDocument find() { assertNotEmpty(replicatorDoc.getId(), "Doc id"); final URI uri = buildUri(dbURI).path(replicatorDoc.getId()).query("rev", replicatorDoc.getRevision()).build(); return dbc.get(uri, ReplicatorDocument.class); }
/** * 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 = buildUri(dbURI).path(replicatorDoc.getId()).query("rev", replicatorDoc.getRevision()).build(); return dbc.delete(uri); }
/** * Removes a document from the database given both a document <code>_id</code> and <code>_rev</code> values. * @param id The document _id field. * @param rev The document _rev field. * @throws NoDocumentException If the document is not found in the database. * @return {@link Response} */ public Response remove(String id, String rev) { assertNotEmpty(id, "id"); assertNotEmpty(rev, "rev"); final URI uri = buildUri(getDBUri()).pathEncoded(id).query("rev", rev).build(); return delete(uri); }
/** * Queries a view as an {@link InputStream} * <p>The stream should be properly closed after usage, as to avoid connection leaks. * @return The result as an {@link InputStream}. */ public InputStream queryForStream() { URI uri = uriBuilder.build(); if(allDocsKeys != null) { // bulk docs return getStream(dbc.post(uri, allDocsKeys)); } return dbc.get(uri); }
CouchDbContext(CouchDbClientBase dbc, CouchDbProperties props) { this.dbc = dbc; if (props.isCreateDbIfNotExist()) { createDB(props.getDbName()); } else { serverVersion(); // pre warm up client } }
/** * @param key The key value, accepts a single value or multiple values for complex keys. * @return {@link View} */ public View key(Object... key) { this.key = getKeyAsJson(key); uriBuilder.query("key", this.key); return this; }
/** * Synchronize all design documents with the database. */ public void syncDesignDocsWithDb() { design().synchronizeAllWithDb(); }
/** * Gets a design document from the database. * @param id The document id * @param rev The document revision * @return {@link DesignDocument} */ public DesignDocument getFromDb(String id, String rev) { assertNotEmpty(id, "id"); assertNotEmpty(id, "rev"); final URI uri = buildUri(dbc.getDBUri()).path(id).query("rev", rev).build(); return dbc.get(uri, DesignDocument.class); }
public Replicator replicatorDB(String replicatorDB) { this.replicatorDB = replicatorDB; dbURI = buildUri(dbc.getBaseUri()).path(replicatorDB).path("/").build(); return this; }
/** * @param endKey The end key value, accepts a single value or multiple values for complex keys. * @return {@link View} */ public View endKey(Object... endKey) { this.endKey = getKeyAsJson(endKey); uriBuilder.query("endkey", this.endKey); return this; }
/** * Finds a document and return 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. * @return The result as {@link InputStream} * @throws NoDocumentException If the document is not found in the database. * @see #find(String, String) */ public InputStream find(String id) { assertNotEmpty(id, "id"); return get(buildUri(getDBUri()).path(id).build()); }
/** * @param startKey The start key value, accepts a single value or multiple values for complex keys. * @return {@link View} */ public View startKey(Object... startKey) { this.startKey = getKeyAsJson(startKey); uriBuilder.query("startkey", this.startKey); return this; }