extend RC { transient RemoteDB db; S getString(S field) { ret db.xS(this, field); } O get(S field) { ret db.xget(this, field); } void set(S field, O value) { db.xset(this, field, value); } } sclass RemoteDB implements AutoCloseable { DialogIO db; S name; // s = bot name or snippet ID *(S s) { this(s, false); } *(S s, bool autoStart) { name = s; if (isSnippetID(s)) name = dbBotName(s); db = findBot(name); if (db == null) if (autoStart) { nohupJavax(fsI(s)); waitForBotStartUp(name); assertNotNull("Weird problem", db = findBot(s)); } else fail("DB " + s + " not running"); } bool functional() { ret db != null; } // now always true L list() { ret adopt((L) rpc(db, "xlist")); } L list(S className) { ret adopt((L) rpc(db, "xlist", className)); } L xlist() { ret list(); } L xlist(S className) { ret list(className); } // adopt is an internal method L adopt(L l) { if (l != null) for (RC rc : l) adopt(rc); ret l; } RC adopt(RC rc) { if (rc != null) rc.db = this; ret rc; } O adopt(O o) { if (o instanceof RC) ret adopt((RC) o); ret o; } S xclass(RC o) { ret (S) rpc(db, "xclass", o); } O xget(RC o, S field) { ret adopt(rpc(db, "xget", o, field)); } S xS(RC o, S field) { ret (S) xget(o, field); } RC xgetref(RC o, S field) { ret adopt((RC) xget(o, field)); } void xset(RC o, S field, O value) { rpc(db, "xset", o, field, value); } RC uniq(S className) { RC ref = first(list(className)); if (ref == null) ref = xnew(className); ret ref; } RC xuniq(S className) { ret uniq(className); } RC xnew(S className, O... values) { ret adopt((RC) rpc(db, "xnew", className, values)); } void xdelete(RC o) { rpc(db, "xdelete", o); } void xdelete(L l) { rpc(db, "xdelete", l); } public void close() { _close(db); } S fullgrab() { ret (S) rpc(db, "xfullgrab"); } S xfullgrab() { ret fullgrab(); } void xshutdown() { rpc(db, "xshutdown"); } long xchangeCount() { ret (long) rpc(db, "xchangeCount"); } int xcount() { ret (int) rpc(db, "xcount"); } void reconnect { close(); db = findBot(name); } RC rc(long id) { ret new RC(this, id); } }