forked from facebookincubator/CG-SQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGSQLMain.java
More file actions
58 lines (49 loc) · 1.66 KB
/
CGSQLMain.java
File metadata and controls
58 lines (49 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import child.*;
import com.facebook.cgsql.CQLResultSet;
import java.nio.charset.StandardCharsets;
import sample.*;
public class CGSQLMain {
public static void main(String[] args) {
TestResult.open();
// get result set handle
long handle = TestResult.getTestResult();
// make the sample result set
Sample data = new Sample(new CQLResultSet(handle));
// use the results
dumpResults(data);
// release the connection
TestResult.close();
}
public static void dumpResults(Sample data) {
System.out.println("Dumping Results");
int count = data.getCount();
System.out.println(String.format("count = %d", count));
for (int i = 0; i < count; i++) {
byte[] bytes = data.getBytes(i);
String s = new String(bytes, StandardCharsets.UTF_8);
System.out.println(
String.format(
"Row %d: name:%s blob:%s age:%d(encoded = %s) thing:%f key1:%s key2:%s(encoded = %s)",
i,
data.getName(i),
s,
data.getAge(i),
Boolean.toString(data.getAgeIsEncoded()),
data.getThing(i),
data.getKey1(i),
data.getKey2(i),
Boolean.toString(data.getKey2IsEncoded())));
Child child = new Child(data.getMyChildResult(i));
for (int j = 0; j < child.getCount(); j++) {
System.out.println(
String.format("--> Child Row %d: x:%d y:%s", j, child.getX(j), child.getY(j)));
}
}
}
}