@Override synchronized public void addChangeListener(CouchDbChangeListener listener) throws Exception { if( !shuttingDown ) { if( null == thread ){ thread = new CouchDbChangeMonitorThread(couchDb.getContext(), getChangeUrl()); thread.start(); } thread.addChangeListener(listener); } }
public CouchClient getClient(CouchContext context, URL url, int versionMajor, int versionMinor) throws Exception { CouchClientImpl client = new CouchClientImpl(context, url); CouchServerVersionImpl serverVersion = new CouchServerVersionImpl(""+versionMajor+"."+versionMinor,versionMajor, versionMinor); client.setVersion(serverVersion); return client; }
@Override public void removeMemberRole(String name) throws Exception { JSONArray ary = getArray("members", "roles"); removeStringFromArray(ary, name); }
@Override public CouchDbSecurityDocument getSecurityDocument() throws Exception { URL securityUrl = new URL(url, "_security"); JSONObject response = ConnectionUtils.getJsonResource(getContext(), securityUrl); ConnectionUtils.captureReponseErrors(response, "Error while fetching security document: "); CouchDbSecurityDocumentImpl security = new CouchDbSecurityDocumentImpl(response); return security; }
@Override public CouchDb createDatabase(String dbName) throws Exception { // Compute url URL effectiveUrl = new URL(url, dbName+"/"); JSONObject response = ConnectionUtils.putJsonResource(context, effectiveUrl, null); ConnectionUtils.captureReponseErrors(response, "Error while creating database "+dbName+": "); CouchDbImpl db = new CouchDbImpl(this, effectiveUrl); return db; }
@Override public JSONArray activeTasks() throws Exception { URL effectiveUrl = new URL(url, "_active_tasks"); JSONArray response = ConnectionUtils.getJsonResource(getContext(), effectiveUrl, JSONArray.class); ConnectionUtils.captureReponseErrors(response, "Error while obtaining active tasks"); return response; } }
@Override public CouchUserDocContext getUserFromName(String userName) throws Exception { try{ JSONObject userDoc = getDocument("org.couchdb.user:"+userName); CouchUserDocContextImpl userCtx = new CouchUserDocContextImpl(userDoc); return userCtx; } catch(Exception e) { throw new Exception("Error obtaining document for user: "+userName); } }
@Override public CouchQueryResults performQuery(CouchQuery query) throws Exception { JSONObject jsonResponse = performQuery(query, JSONObject.class); CouchQueryResultsImpl results; try { results = new CouchQueryResultsImpl(jsonResponse); } catch (Exception e) { throw new Exception("Error while parsing query response",e); } return results; }
@Override public Collection<String> getAdminRoles() { return extractStringsFromArray("admins", "roles"); }
@Override synchronized public void shutdown() { if( null != thread ){ thread.shutdown(); thread = null; shuttingDown = true; } }
@Override synchronized public CouchDbChangeMonitor getChangeMonitor() throws Exception { if( null == changeMonitor ){ changeMonitor = new CouchDbChangeMonitorImpl(this); } return changeMonitor; }
public CouchDb getDb(CouchClient client, URL dbUrl) throws Exception { CouchDbImpl couchDb = new CouchDbImpl(client, dbUrl); return couchDb; }
public CouchClient getClient(CouchContext context, URL url) throws Exception { CouchClientImpl client = new CouchClientImpl(context, url); return client; }
@Override public Collection<JSONObject> getDocuments(List<String> docIds) throws Exception { return getDocuments(docIds, null); }
@Override public void removeAdminUser(String name) throws Exception { JSONArray ary = getArray("admins", "names"); removeStringFromArray(ary, name); }
@Override public Collection<String> getMemberUsers() { return extractStringsFromArray("members", "names"); }
@Override public void removeMemberUser(String name) throws Exception { JSONArray ary = getArray("members", "names"); removeStringFromArray(ary, name); }
@Override public Collection<String> getMemberRoles() { return extractStringsFromArray("members", "roles"); }
@Override public void removeAdminRole(String name) throws Exception { JSONArray ary = getArray("admins", "roles"); removeStringFromArray(ary, name); }
@Override public Collection<String> getAdminUsers() { return extractStringsFromArray("admins", "names"); }