Libraryless. Click here for Pure Java version (11672L/79K).
1 | extend RC { |
2 | transient RemoteDB db; |
3 | |
4 | S getString(S field) { ret db.xS(this, field); } |
5 | O get(S field) { ret db.xget(this, field); } |
6 | void set(S field, O value) { db.xset(this, field, value); } |
7 | } |
8 | |
9 | sclass RemoteDB implements AutoCloseable { |
10 | DialogIO db; |
11 | S name; |
12 | |
13 | // s = bot name or snippet ID |
14 | *(S s) { |
15 | this(s, false); |
16 | } |
17 | |
18 | *(S s, bool autoStart) { |
19 | name = s; |
20 | if (isSnippetID(s)) name = dbBotName(s); |
21 | db = findBot(name); |
22 | if (db == null) |
23 | if (autoStart) { |
24 | nohupJavax(fsI(s)); |
25 | waitForBotStartUp(name); |
26 | assertNotNull("Weird problem", db = findBot(s)); |
27 | } else |
28 | fail("DB " + s + " not running"); |
29 | } |
30 | |
31 | bool functional() { ret db != null; } // now always true |
32 | |
33 | L<RC> list() { ret adopt((L<RC>) rpc(db, "xlist")); } |
34 | L<RC> list(S className) { ret adopt((L<RC>) rpc(db, "xlist", className)); } |
35 | L<RC> xlist() { ret list(); } |
36 | L<RC> xlist(S className) { ret list(className); } |
37 | |
38 | // adopt is an internal method |
39 | L<RC> adopt(L<RC> l) { |
40 | if (l != null) for (RC rc : l) adopt(rc); |
41 | ret l; |
42 | } |
43 | |
44 | RC adopt(RC rc) { if (rc != null) rc.db = this; ret rc; } |
45 | |
46 | O adopt(O o) { |
47 | if (o instanceof RC) ret adopt((RC) o); |
48 | ret o; |
49 | } |
50 | |
51 | S xclass(RC o) { |
52 | ret (S) rpc(db, "xclass", o); |
53 | } |
54 | |
55 | O xget(RC o, S field) { |
56 | ret adopt(rpc(db, "xget", o, field)); |
57 | } |
58 | |
59 | S xS(RC o, S field) { |
60 | ret (S) xget(o, field); |
61 | } |
62 | |
63 | RC xgetref(RC o, S field) { |
64 | ret adopt((RC) xget(o, field)); |
65 | } |
66 | |
67 | void xset(RC o, S field, O value) { |
68 | rpc(db, "xset", o, field, value); |
69 | } |
70 | |
71 | RC uniq(S className) { |
72 | RC ref = first(list(className)); |
73 | if (ref == null) |
74 | ref = xnew(className); |
75 | ret ref; |
76 | } |
77 | RC xuniq(S className) { ret uniq(className); } |
78 | |
79 | RC xnew(S className, O... values) { |
80 | ret adopt((RC) rpc(db, "xnew", className, values)); |
81 | } |
82 | |
83 | void xdelete(RC o) { |
84 | rpc(db, "xdelete", o); |
85 | } |
86 | |
87 | void xdelete(L<RC> l) { |
88 | rpc(db, "xdelete", l); |
89 | } |
90 | |
91 | public void close() { |
92 | _close(db); |
93 | } |
94 | |
95 | S fullgrab() { ret (S) rpc(db, "xfullgrab"); } |
96 | S xfullgrab() { ret fullgrab(); } |
97 | |
98 | void xshutdown() { rpc(db, "xshutdown"); } |
99 | |
100 | long xchangeCount() { ret (long) rpc(db, "xchangeCount"); } |
101 | int xcount() { ret (int) rpc(db, "xcount"); } |
102 | |
103 | void reconnect { |
104 | close(); |
105 | db = findBot(name); |
106 | } |
107 | |
108 | RC rc(long id) { ret new RC(this, id); } |
109 | } |
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: | 751 / 8545 |
Version history: | 24 change(s) |
Referenced in: | [show references] |