Ticket #1: QueryExample.java

File QueryExample.java, 2.5 KB (added by Andrei Aiordachioaie, 15 years ago)

RasJ use that displays the presented bug

Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package wcs.tools;
7
8import java.util.Iterator;
9import org.odmg.DBag;
10import org.odmg.Database;
11import org.odmg.Implementation;
12import org.odmg.ODMGException;
13import org.odmg.OQLQuery;
14import org.odmg.Transaction;
15import rasj.RasImplementation;
16
17/**
18 *
19 * @author andrei
20 */
21public class QueryExample
22{
23 public final String query = "select max_cells(c.0) from rgb as c";
24
25 private String server;
26 private String base;
27 Implementation myApp = null;
28 Database myDb = null;
29 Transaction myTa = null;
30
31 public QueryExample(String s, String b)
32 {
33 this.server = s;
34 this.base = b;
35
36 myApp = new RasImplementation(server);
37 myDb = myApp.newDatabase();
38 }
39
40 public void log(String msg)
41 {
42 System.err.flush();
43 System.out.println("log> " + msg);
44 System.out.flush();
45 }
46
47 private void init() throws ODMGException
48 {
49 if (myApp == null)
50 {
51 myApp = new RasImplementation(server);
52 }
53 if (myDb == null)
54 {
55 myDb = myApp.newDatabase();
56 }
57 log("Opening database...");
58 myDb.open(base, Database.OPEN_READ_ONLY);
59 log("Beginning new transaction ...");
60 myTa = myApp.newTransaction();
61 myTa.begin();
62 }
63
64 private void finish() throws ODMGException
65 {
66 log("Commiting transaction ...");
67 myTa.commit();
68 log("Closing database...");
69 myDb.close();
70 log("Finished !");
71 }
72
73 private void abort() throws ODMGException
74 {
75 log("Aborting transaction...");
76 myTa.abort();
77 log("Closing database...");
78 myDb.close();
79 log("Finished !");
80 }
81
82 public void sendQuery() throws ODMGException
83 {
84
85
86 init();
87
88 log("Querying for all available collections ...");
89 OQLQuery myQu = myApp.newOQLQuery();
90 myQu.create(query);
91
92 DBag resultSet = (DBag) myQu.execute();
93 if (resultSet != null)
94 {
95 Iterator iter = resultSet.iterator();
96 while (iter.hasNext())
97 {
98 Byte myByte = (Byte) iter.next();
99 System.out.println("*** Result is: " + myByte);
100 }
101 }
102
103 finish();
104 }
105
106 public static void main(String[] args) throws ODMGException
107 {
108 QueryExample ex = new QueryExample(
109 "http://kahlua.eecs.jacobs-university.de:9001", "RASSERVICE");
110 ex.sendQuery();
111 }
112}