1 | import java.util.Arrays;
|
---|
2 | import java.util.Iterator;
|
---|
3 |
|
---|
4 | import org.odmg.DBag;
|
---|
5 | import org.odmg.Database;
|
---|
6 | import org.odmg.ODMGException;
|
---|
7 | import org.odmg.OQLQuery;
|
---|
8 | import org.odmg.Transaction;
|
---|
9 |
|
---|
10 | import rasj.RasImplementation;
|
---|
11 | import rasj.RasMArrayInteger;
|
---|
12 |
|
---|
13 | public class ReadData {
|
---|
14 | private static String server = "localhost";
|
---|
15 | private static String port = "7001";
|
---|
16 | private static String base = "RASBASE";
|
---|
17 | private static String user = "rasguest";
|
---|
18 | private static String password = "rasguest";
|
---|
19 |
|
---|
20 | public static void main(String[] args) {
|
---|
21 |
|
---|
22 | Database database = null;
|
---|
23 | Transaction transaction = null;
|
---|
24 | try {
|
---|
25 | RasImplementation app = new RasImplementation("http://" + server + ":" + port);
|
---|
26 | app.setUserIdentification(user, password);
|
---|
27 |
|
---|
28 | database = app.newDatabase();
|
---|
29 | database.open(base, Database.OPEN_READ_ONLY);
|
---|
30 |
|
---|
31 | transaction = app.newTransaction();
|
---|
32 | transaction.begin();
|
---|
33 |
|
---|
34 | OQLQuery selectQuery = app.newOQLQuery();
|
---|
35 |
|
---|
36 | // If csv(...) is used, the data-type is changed to RasMArrayByte.
|
---|
37 | // If the ushort-values are read as byte, wrong values are returned.
|
---|
38 | // Casting to integer or short causes an exception.
|
---|
39 | selectQuery.create(
|
---|
40 | "select marray x in [1:10, 0:23] values (c[2016, 12, x[0], x[1], 50, 450, 450]) from MemTestData as c");
|
---|
41 | DBag resultSet = (DBag) selectQuery.execute();
|
---|
42 |
|
---|
43 | Iterator<?> iter = resultSet.iterator();
|
---|
44 |
|
---|
45 | RasMArrayInteger result = (RasMArrayInteger) iter.next();
|
---|
46 | int[] readData = result.getIntArray();
|
---|
47 |
|
---|
48 | System.out.println(Arrays.toString(readData));
|
---|
49 |
|
---|
50 | // Only read access was required.
|
---|
51 | transaction.abort();
|
---|
52 | } catch (ODMGException e) {
|
---|
53 | e.printStackTrace();
|
---|
54 | if (transaction != null) {
|
---|
55 | transaction.abort();
|
---|
56 | }
|
---|
57 | } finally {
|
---|
58 | if (database != null) {
|
---|
59 | try {
|
---|
60 | database.close();
|
---|
61 | } catch (ODMGException e) {
|
---|
62 | e.printStackTrace();
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|