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

68
LINES

< > BotCompany Repo | #1000694 // spike of SnippetDB

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2081L/16K/49K).

1  
!636
2  
!modern
3  
!* ctr
4  
5  
main {
6  
  psvm {
7  
    new SnippetDB db;
8  
    db.importMySQLDump(gunzipToText("#1000673"));
9  
    //db.printStats();
10  
    
11  
    print();
12  
    db.printFullSnippet("#636");
13  
  }
14  
  
15  
  static class Table {
16  
    List<List<String>> data;
17  
    List<String> fields;
18  
    
19  
    *(List<List<String>> *data, List<String> *fields) {}
20  
    
21  
    Map<S, S> rowAsMap(L<S> row) {
22  
      new Map<S, S> map;
23  
      for (int i = 0; i < row.size(); i++)
24  
        map.put(fields.get(i), row.get(i));
25  
      return map;
26  
    }
27  
  }
28  
  
29  
  static class SnippetDB {
30  
    Map<String, List> tables;
31  
    Map<String, List> tableFields;
32  
    
33  
    void importMySQLDump(String dump) {
34  
      print("Importing " + dump.length() + " chars.");
35  
      Class importer = hotwire("#1000660");
36  
      set(importer, "in", dump);
37  
      callMain(importer);
38  
      tables = (Map) get(importer, "tables");
39  
      tableFields = (Map) get(importer, "tableFields");
40  
      print("Total rows imported: " + get(importer, "totalRows"));
41  
    }
42  
    
43  
    void printStats() {
44  
      print(structure(tables.keySet()));
45  
      print(structure(tableFields));
46  
    }
47  
    
48  
    Table table(String name) {
49  
      return new Table(tables.get(name), tableFields.get(name));
50  
    }
51  
    
52  
    Map<S, S> getFullSnippet(String id) {
53  
      id = "" + parseSnippetID(id);
54  
      Table t = table("snippets_public");
55  
      for (List row : t.data) {
56  
        Map<S, S> map = t.rowAsMap(row);
57  
        String _id = map.get("sn_id");
58  
        if (id.equals(_id))
59  
          return map;
60  
      }
61  
      return null;
62  
    }
63  
    
64  
    void printFullSnippet(S id) {
65  
      print(structure(getFullSnippet(id)));
66  
    }
67  
  }
68  
}

Author comment

Began life as a copy of #1000678

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000694
Snippet name: spike of SnippetDB
Eternal ID of this version: #1000694/1
Text MD5: 8bbafe6973aa980ffc98692f8dfe96aa
Transpilation MD5: 14423f260d9868d003c6a21d4c30f053
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-15 18:14:11
Source code size: 1683 bytes / 68 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 569 / 569
Referenced in: [show references]