1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 |
|
---|
6 | package ssdm.rasdaman_connector;
|
---|
7 |
|
---|
8 | import rasj.*;
|
---|
9 | import org.odmg.*;
|
---|
10 | import java.util.*;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | *
|
---|
14 | * @author andan342
|
---|
15 | */
|
---|
16 | public class ConnectorTest {
|
---|
17 | String server = "localhost";
|
---|
18 | String base = "RASBASE";
|
---|
19 | String coll = "mr";
|
---|
20 | String port = "7001";
|
---|
21 | String user = "rasadmin";
|
---|
22 | String passwd = "rasadmin";
|
---|
23 |
|
---|
24 | public static void main(String[] args) {
|
---|
25 | ConnectorTest ct = new ConnectorTest();
|
---|
26 |
|
---|
27 | System.out.println("------------- Inserting new array");
|
---|
28 | ct.insertStripes();
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void insertStripes()
|
---|
32 | {
|
---|
33 | try {
|
---|
34 | // from Application Examples (dev-guide-java.pdf, page 15)
|
---|
35 | Transaction myTa = null;
|
---|
36 | Database myDb = null;
|
---|
37 | OQLQuery myQu = null;
|
---|
38 |
|
---|
39 | Implementation myApp = new RasImplementation("http://"+server+":"+port);
|
---|
40 | ((RasImplementation)myApp).setUserIdentification(user, passwd);
|
---|
41 | myDb = myApp.newDatabase();
|
---|
42 |
|
---|
43 | System.out.println("Opening database ...");
|
---|
44 | myDb.open(base, Database.OPEN_EXCLUSIVE);
|
---|
45 |
|
---|
46 | try {
|
---|
47 | System.out.println("Starting transaction ...");
|
---|
48 | myTa = myApp.newTransaction();
|
---|
49 | myTa.begin();
|
---|
50 |
|
---|
51 | // Example 3 (dev-guide-java.pdf, page 31)
|
---|
52 | // set up query object for collection creation:
|
---|
53 | myQu = myApp.newOQLQuery(); //AA
|
---|
54 | myQu.create("create collection test GreySet");
|
---|
55 | // finally, execute âcreate collectionâ statement:
|
---|
56 | myQu.execute();
|
---|
57 |
|
---|
58 | // Example 2 (dev-guide-java.pdf, page 30)
|
---|
59 | // create 2-D MDD with cell length 1, i.e., type âbyteâ:
|
---|
60 | RasGMArray myMDD = new RasGMArray( new RasMInterval( "[1:400,1:400]"), 1 );
|
---|
61 | // byte container for array data, matching in size:
|
---|
62 | byte[] mydata = new byte[160000];
|
---|
63 | // initialize array as all-black with two grey stripes:
|
---|
64 | for(int y=0; y<400; y++)
|
---|
65 | {
|
---|
66 | for(int x=0; x<400; x++)
|
---|
67 | {
|
---|
68 | if((x>99 && x<151) || (x>299 && x<351)) mydata[y*399+x]=100;
|
---|
69 | else mydata[y*399+x]=0;
|
---|
70 | }
|
---|
71 | }
|
---|
72 | // now insert byte array into MDD object
|
---|
73 | // (sets only the pointer, no copying takes place!):
|
---|
74 | myMDD.setArray(mydata);
|
---|
75 | // set the object type name (used for server type checking):
|
---|
76 | myMDD.setObjectTypeName("GreyImage");
|
---|
77 | RasStorageLayout ms = new RasStorageLayout();
|
---|
78 | ms.setTileDomain("[1:200,1:200]");
|
---|
79 | ms.setTileSize(40000);
|
---|
80 | myMDD.setStorageLayout(ms);
|
---|
81 |
|
---|
82 | // now create the insert statement:
|
---|
83 | myQu = myApp.newOQLQuery(); //AA
|
---|
84 | myQu.create("insert into test values $1");
|
---|
85 | // let the server generate a new OID for the object to be
|
---|
86 | // inserted, and remember this OID locally:
|
---|
87 | String myNewOID = myApp.getObjectId( myMDD );
|
---|
88 | // bind the MDD value which substitutes formal parameter $1:
|
---|
89 | myQu.bind(myMDD); // âŠand ship the complete statement to the server:
|
---|
90 | myQu.execute();
|
---|
91 |
|
---|
92 | System.out.println("== Committing transaction...");
|
---|
93 | myTa.commit();
|
---|
94 | System.out.println("== Array inserted with OID = " + myNewOID);
|
---|
95 | } catch (Exception ex) {
|
---|
96 | ex.printStackTrace();
|
---|
97 | myTa.abort();
|
---|
98 | } finally {
|
---|
99 | myDb.close();
|
---|
100 | }
|
---|
101 | } catch (Exception e) {
|
---|
102 | e.printStackTrace();
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | }
|
---|