/** * Request a database sends a list of UUIDs. * @param count The count of UUIDs. * @return a list of UUIDs */ public List<String> uuids(long count) { final String uri = String.format("%s_uuids?count=%d", dbc.getBaseUri(), count); final JsonObject json = dbc.findAny(JsonObject.class, uri); return dbc.getGson().fromJson(json.get("uuids").toString(), new TypeToken<List<String>>(){}.getType()); } }
/** * @return DB Server version. */ public String serverVersion() { InputStream instream = null; try { instream = dbc.get(buildUri(dbc.getBaseUri()).build()); Reader reader = new InputStreamReader(instream, Charsets.UTF_8); return getAsString(new JsonParser().parse(reader).getAsJsonObject(), "version"); } finally { close(instream); } }
/** * Requests CouchDB deletes a database. * @param dbName The database name * @param confirm A confirmation string with the value: <tt>delete database</tt> */ public void deleteDB(String dbName, String confirm) { assertNotEmpty(dbName, "dbName"); if(!"delete database".equals(confirm)) throw new IllegalArgumentException("Invalid confirm!"); dbc.delete(buildUri(dbc.getBaseUri()).path(dbName).build()); }
public Replicator replicatorDB(String replicatorDB) { this.replicatorDB = replicatorDB; dbURI = buildUri(dbc.getBaseUri()).path(replicatorDB).path("/").build(); return this; }
/** * @return All Server databases. */ public List<String> getAllDbs() { InputStream instream = null; try { Type typeOfList = new TypeToken<List<String>>() {}.getType(); instream = dbc.get(buildUri(dbc.getBaseUri()).path("_all_dbs").build()); Reader reader = new InputStreamReader(instream, Charsets.UTF_8); return dbc.getGson().fromJson(reader, typeOfList); } finally { close(instream); } }
/** * Triggers a replication request. * @return {@link ReplicationResult} */ public ReplicationResult trigger() { assertNotEmpty(source, "Source"); assertNotEmpty(target, "Target"); HttpResponse response = null; try { JsonObject json = createJson(); if(log.isDebugEnabled()) { log.debug(json); } final URI uri = buildUri(dbc.getBaseUri()).path("_replicate").build(); response = dbc.post(uri, json.toString()); final InputStreamReader reader = new InputStreamReader(getStream(response), Charsets.UTF_8); return dbc.getGson().fromJson(reader, ReplicationResult.class); } finally { close(response); } }
/** * Requests CouchDB creates a new database; if one doesn't exist. * @param dbName The Database name */ public void createDB(String dbName) { assertNotEmpty(dbName, "dbName"); InputStream getresp = null; HttpResponse putresp = null; final URI uri = buildUri(dbc.getBaseUri()).path(dbName).build(); try { getresp = dbc.get(uri); } catch (NoDocumentException e) { // db doesn't exist final HttpPut put = new HttpPut(uri); putresp = dbc.executeRequest(put); log.info(String.format("Created Database: '%s'", dbName)); } finally { close(getresp); close(putresp); } }
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(); }