Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

109
LINES

< > BotCompany Repo | #1005774 // RemoteDB v2 (using + extending RC)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (11672L/79K).

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<RC> list() { ret adopt((L<RC>) rpc(db, "xlist")); }
  L<RC> list(S className) { ret adopt((L<RC>) rpc(db, "xlist", className)); }
  L<RC> xlist() { ret list(); }
  L<RC> xlist(S className) { ret list(className); }
  
  // adopt is an internal method
  L<RC> adopt(L<RC> 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<RC> 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); }
}

Author comment

Began life as a copy of #1004925

download  show line numbers  debug dex  old transpilations   

Travelled to 20 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, imzmzdywqqli, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, lulzaavyztxj, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv

No comments. add comment

Snippet ID: #1005774
Snippet name: RemoteDB v2 (using + extending RC)
Eternal ID of this version: #1005774/25
Text MD5: e254f3ad5c212a6ce9ecb6c2c758b3d7
Transpilation MD5: 8a9a7018d8d2a6621e6a2bd202b4402d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-14 11:07:30
Source code size: 2478 bytes / 109 lines
Pitched / IR pitched: No / No
Views / Downloads: 750 / 8543
Version history: 24 change(s)
Referenced in: [show references]