MCPcopy Create free account
hub / github.com/MariaDB/server / main

Method main

storage/connect/TestInsert2.java:14–100  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

12 static Mongo2Interface jdi = null;
13
14 public static void main(String[] args) {
15 int rc;
16 String[] parms = new String[4];
17
18 jdi = new Mongo2Interface(DEBUG);
19
20 parms[0] = getLine("URI: ", false);
21 parms[1] = getLine("Database: ", false);
22 parms[2] = null;
23 parms[3] = null;
24
25 if (parms[0] == null)
26 parms[0] = "mongodb://localhost:27017";
27
28 if (parms[1] == null)
29 parms[1] = "test";
30
31 rc = jdi.MongoConnect(parms);
32
33 if (rc == 0) {
34 Object bdoc = jdi.MakeDocument();
35
36 if (jdi.DocAdd(bdoc, "_id", (Object) 1, 0))
37 System.out.println(jdi.GetErrmsg());
38
39 if (jdi.DocAdd(bdoc, "Name", (Object) "Smith", 0))
40 System.out.println(jdi.GetErrmsg());
41
42 if (jdi.DocAdd(bdoc, "Age", (Object) 39, 0))
43 System.out.println(jdi.GetErrmsg());
44
45 if (jdi.DocAdd(bdoc, "Pi", (Object) 3.14, 0))
46 System.out.println(jdi.GetErrmsg());
47
48 if (jdi.DocAdd(bdoc, "Phone", (Object) "{\"ext\":[4,5,7]}", 1))
49 System.out.println(jdi.GetErrmsg());
50
51 if (jdi.DocAdd(bdoc, "Scores", (Object) "[24,2,13]", 2))
52 System.out.println(jdi.GetErrmsg());
53
54 Object bar = jdi.MakeArray();
55
56 for (int i = 1; i < 3; i++)
57 if (jdi.ArrayAdd(bar, i, (Object) (Math.random() * 10.0), 0))
58 System.out.println(jdi.GetErrmsg());
59
60 if (jdi.DocAdd(bdoc, "Prices", bar, 0))
61 System.out.println(jdi.GetErrmsg());
62
63 Object dat = new Date();
64
65 if (jdi.DocAdd(bdoc, "Date", dat, 0))
66 System.out.println(jdi.GetErrmsg());
67
68 System.out.println(bdoc);
69
70 // Try to update
71 if (!jdi.GetCollection("updtest") && !jdi.FindColl(null, null)) {

Callers

nothing calls this directly

Calls 15

getLineMethod · 0.95
randomMethod · 0.80
MongoConnectMethod · 0.45
MakeDocumentMethod · 0.45
DocAddMethod · 0.45
GetErrmsgMethod · 0.45
MakeArrayMethod · 0.45
ArrayAddMethod · 0.45
GetCollectionMethod · 0.45
FindCollMethod · 0.45
CollDeleteMethod · 0.45
CollInsertMethod · 0.45

Tested by

no test coverage detected