Ticket #409: CreateCollection.java

File CreateCollection.java, 1.3 KB (added by Dirk Daems, 11 years ago)
Line 
1import java.nio.file.Files;
2import java.nio.file.Paths;
3
4import org.odmg.Database;
5import org.odmg.OQLQuery;
6import org.odmg.Transaction;
7
8import rasj.RasGMArray;
9import rasj.RasImplementation;
10import rasj.RasMInterval;
11
12public class CreateCollection{
13
14 public static void main(String [] args){
15
16 RasImplementation rasImpl = new RasImplementation("http://localhost:7001");
17 Transaction transaction = null;
18
19 try{
20
21 rasImpl.setUserIdentification("rasadmin", "rasadmin");
22 Database rasDb = rasImpl.newDatabase();
23
24 rasDb.open("RASBASE", Database.OPEN_READ_WRITE);
25
26 transaction = rasImpl.newTransaction();
27 transaction.begin();
28
29 OQLQuery myQu = rasImpl.newOQLQuery();
30
31 myQu.create("create collection my_collection GreySet");
32 myQu.execute();
33
34 RasGMArray mdd = createMDDFromFile("/tmp/polygon.tiff");
35 mdd.setObjectTypeName("GreyImage");
36
37 myQu.create("insert into my_collection values inv_tiff( $1 )");
38 myQu.bind(mdd);
39 myQu.execute();
40
41 }
42 catch(Exception ex){
43
44 ex.printStackTrace();
45
46 }
47 finally{
48 if(transaction != null){
49 transaction.commit();
50 }
51 }
52
53 }
54
55 public static RasGMArray createMDDFromFile(String fileName) throws Exception{
56
57 RasGMArray mdd = new RasGMArray(new RasMInterval("[1:422,1:229]"), 1);
58 byte [] array = Files.readAllBytes(Paths.get(fileName));
59 mdd.setArray(array);
60
61 return mdd;
62
63 }
64
65}