summaryrefslogtreecommitdiffstats
path: root/java/rasj/test/TestMArray.java
blob: e8f817f3043fe5892c761dbfb8ace6fbf5bd03a7 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
/** ***********************************************************
 * <pre>
 *
 * PURPOSE: class for testing special MArrays
 *
 *
 * COMMENTS:
 * - adapt to general testbed structure
 * </pre>
 *********************************************************** */

import java.io.*;
import java.net.*;
import rasj.clientcommhttp.*;
import rasj.odmg.*;
import org.odmg.*;
import rasj.*;
import java.util.*;

/**
 * class for testing special MArrays
 * for testing please enable test data output in toString method of RASGMArray
 * @version $$
 */
public class TestMArray
{
    /**
    * constants used in this test
    **/
    // prefixes for test output
    static final String PREFIX_PROGRAM  = "+++ +++ +++ ";
    static final String PREFIX_TESTSET  = "+++ +++ ";
    static final String PREFIX_TESTCASE = "+++ ";

    static final String DEFAULT_HOST = "localhost";
    static final String DEFAULT_BASE = "RASBASE";
    static final String DEFAULT_COLL = "test";
    /**
    * std error tag printed if a test fails
    **/
    static final String ERROR_TAG = "ERROR: ";

    /**
    * main program for testing
    * on error, an exception is thrown (java main() knows no exit status)
    **/
  public static void main(String[] args)
  {
    String serv = DEFAULT_HOST;
    String base = DEFAULT_BASE;
    String coll = DEFAULT_COLL;
    boolean wrongUsage = false;			// error in cmd line params?

    for (int i=args.length-1; i>=0; i--)
    {
      if (args[i].equals("--server"))
        serv = args[i+1];
      else if (args[i].equals("--database"))
        base = args[i+1];
      else if (args[i].equals("--collname"))
        coll = args[i+1];
      else
        wrongUsage = true;
    }

    if (wrongUsage)
      {
        System.out.println( "Usage: TestMArray [--server s] [--database d] [--collname c]" );
        System.out.println( "defaults: s=" + DEFAULT_HOST + ", d=" + DEFAULT_BASE + ", c=" + DEFAULT_COLL );
        return;
      }

    System.out.println( "rasdaman system test v5.1revC: testing class MArray." );
    System.out.println( PREFIX_PROGRAM + "system test started, using server" + serv + ", database " + base + ", collection" + coll );

    // -- START test cases -------------------------------------------------
    TestMArray marrayTest = new TestMArray(serv);
    // -- END test cases ---------------------------------------------------

    System.out.println( PREFIX_PROGRAM + "system test done." );
    return;
  } // main() 

  public TestMArray(String server)
  {
    DBag resultBag = null;
    Object result = null;
    Transaction myTa = null;
    Database myDb = null;
    OQLQuery myQu = null;

    boolean equal = false;

    try
    {
      System.out.println("### Testing MArrays: ...");
      Implementation myApp = new RasImplementation("http://"+server+":7001");
      myDb = myApp.newDatabase();

      System.out.println("Opening database ...");
      myDb.open("RASBASE", Database.OPEN_READ_WRITE);
      myTa = myApp.newTransaction();

      int width, height, len;
      width = 18;
      height = 18;
      len = (width+1)*(height+1);
      RasMInterval domain = new RasMInterval("[0:"+width+",0:"+height+"]");
      RasMInterval domain2 = new RasMInterval("[1:3,1:3]");
      RasStorageLayout stl = new RasStorageLayout();
      stl.setTileSize(128);


      /**
       * test the GMArray
       */
      System.out.println("\n\n### Testing GMArray with OID: ################################################");
      myQu = myApp.newOQLQuery();

      myQu.create("drop collection test");
      myTa.begin();
      try
      {
        resultBag = (DBag)myQu.execute();
        myTa.commit();
        //System.out.println("collection dropped");
      }
      catch(ODMGException e)
      {
        myTa.abort();
        System.err.println("Collection test does not exist: " + e.getMessage());
      }

      myQu.create("create collection test GreySet");
      RasGMArray mddConst = new RasGMArray(domain, 1, stl);
      //RasGMArray mddConst = new RasGMArray(domain, 1);
      byte[] data = new byte[len];
      mddConst.setObjectTypeName("GreyImage");

      // test: get new OID from the server for GMArray and insert
      System.out.println("new OID from server: " + myApp.getObjectId(mddConst));

      for(int j = 0; j < data.length; j++)
        data[j] = (byte)j;

      mddConst.setArray(data);
      /*
      System.out.println("\nbyte array: ");
      for(int j=0; j<mddConst.getArray().length; j++)
      {
        System.out.print(" "+ mddConst.getArray()[j]);
      }
      */
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("\ncollection created");
      myQu.create("insert into test values $1 ");

      //System.out.println("mdd before sending: " + mddConst);
      myQu.bind(mddConst);
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection inserted");

      myQu = myApp.newOQLQuery();
      myQu.create("select img from test as img");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection selected");
      if (resultBag != null)
      {
	Iterator iter = resultBag.iterator();
	while (iter.hasNext())
	{
          result = iter.next();
          equal = true;
          for(int j=0; j<mddConst.getArray().length; j++)
          {
            if(mddConst.getArray()[j] != ((RasGMArray)result).getArray()[j])
              equal = false;
          }
          if(!(myApp.getObjectId(mddConst).toString()).equals(myApp.getObjectId((RasGMArray)result).toString()))
            equal = false;
          System.out.println("result mdd: " + ((RasGMArray)mddConst).toTestString());
          System.out.println("result mdd: " + ((RasGMArray)result).toTestString());
        }
          System.out.println("inserted and selected GMArray and OIDs are equal: " + equal);
          //System.out.println("All results for test GMArray");
      }


      // testing copy constructor
      System.out.println("### Testing copy constructor:");
      RasGMArray mddConst2 = new RasGMArray(mddConst);
      mddConst2.setArray(data);
      //System.out.println("\nbyte array2: ");
      data = null;
      equal = true;
      for(int j=0; j<mddConst.getArray().length; j++)
      {
        //System.out.print(" "+ mddConst2.getArray()[j]);
        if(mddConst.getArray()[j] != mddConst2.getArray()[j])
              equal = false;
      }
      System.out.println("Copy constructor is OK: " + equal);

      /**
       * test the MArrayByte
       */
      System.out.println("\n\n### Testing MArrayByte: ################################################");
      myQu = myApp.newOQLQuery();

      myQu.create("drop collection test");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection dropped");

      myQu.create("create collection test GreySet");
      RasMArrayByte mddByte = new RasMArrayByte(domain, stl);
      byte[] dataByte = new byte[len];
      mddByte.setObjectTypeName("GreyImage");

      for(int j = 0; j < dataByte.length; j++)
        dataByte[j] = (byte)j;

      mddByte.setArray(dataByte);

      //System.out.println("\nbyte array: ");
      //for(int j=0; j<mddByte.getArray().length; j++)
      //{
        //System.out.print(" "+ mddByte.getArray()[j]);
      //}

      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("\ncollection created");
      myQu.create("insert into test values $1 ");

      //System.out.println("mdd before sending: " + mddByte);
      myQu.bind(mddByte);
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection inserted");

      myQu = myApp.newOQLQuery();
      myQu.create("select img from test as img");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection selected");
      if (resultBag != null)
      {
	Iterator iter = resultBag.iterator();
	while (iter.hasNext())
	{
          result = iter.next();
          System.out.println("result mdd: " + ((RasGMArray)mddByte).toTestString());
          System.out.println("result mdd: " + ((RasGMArray)result).toTestString());
          equal = true;
          for(int j=0; j<mddByte.getArray().length; j++)
          {
            if(mddByte.getArray()[j] != ((RasGMArray)result).getArray()[j])
              equal = false;
          }
        }
        //System.out.println("All results for MArrayByte");
        System.out.println("inserted and selected MArrayByte are equal: " + equal);
      }

      // testing copy constructor
      System.out.println("### Testing copy constructor:");
      RasMArrayByte mddByte2 = new RasMArrayByte(mddByte);
      mddByte2.setArray(dataByte);
      //System.out.println("\nbyte array2: ");
      dataByte = null;
      equal = true;
      for(int j=0; j<mddByte.getArray().length; j++)
      {
        //System.out.print(" "+ mddByte2.getArray()[j]);
        if(mddByte.getArray()[j] != mddByte2.getArray()[j])
              equal = false;
      }
      System.out.println("Copy constructor is OK: " + equal);

      /**
       * test the MArrayInteger
       */
      System.out.println("\n\n### Testing MArrayInteger: ################################################");
      myQu = myApp.newOQLQuery();

      myQu.create("drop collection test");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection dropped");

      myQu.create("create collection test UShortSet");
      RasMArrayInteger mddInteger = new RasMArrayInteger(domain, stl);
      int[] dataInteger = new int[len];
      //byte[] dataInteger = new byte[144];
      mddInteger.setObjectTypeName("UShortImage");

      for(int j = 0; j < dataInteger.length; j++)
        dataInteger[j] = j;

      mddInteger.setArray(dataInteger);

      //System.out.println("\nbyte array: ");
      //for(int j=0; j<mddInteger.getArray().length; j++)
      //{
        //System.out.print(" "+ mddInteger.getArray()[j]);
      //}

      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("\ncollection created");
      myQu.create("insert into test values $1 ");

      //System.out.println("mdd before sending: " + mddInteger);
      myQu.bind(mddInteger);
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection inserted");

      myQu = myApp.newOQLQuery();
      myQu.create("select img from test as img");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection selected");
      if (resultBag != null)
      {
	Iterator iter = resultBag.iterator();
	while (iter.hasNext())
	{
          result = iter.next();
          System.out.println("result mdd: " + ((RasGMArray)mddInteger).toTestString());
          System.out.println("result mdd: " + ((RasGMArray)result).toTestString());
          equal = true;
          for(int j=0; j<mddInteger.getArray().length; j++)
          {
            if(mddInteger.getArray()[j] != ((RasGMArray)result).getArray()[j])
                equal = false;
          }
        }
        //System.out.println("All results for MArrayInteger");
        System.out.println("inserted and selected MArrayInteger are equal: " + equal);
      }

      // testing copy constructor
      System.out.println("### Testing copy constructor:");
      RasMArrayInteger mddInteger2 = new RasMArrayInteger(mddInteger);
      mddInteger2.setArray(dataInteger);
      dataInteger = null;
      equal = true;
      for(int j=0; j<mddInteger2.getArray().length; j++)
      {
        //System.out.print(" "+ mddInteger2.getArray()[j]);
        if(mddInteger.getArray()[j] != mddInteger2.getArray()[j])
          equal = false;
      }
      System.out.println("Copy constructor is OK: " + equal);

      /*
      System.out.println("\nspecial array2: ");
      for(int j=0; j<mddInteger2.getIntArray().length; j++)
      {
        System.out.print(" "+ mddInteger2.getIntArray()[j]);
      }
      */

      /**
       * test the MArrayDouble
       */
      System.out.println("\n\n### Testing MArrayDouble: ################################################");
      myQu = myApp.newOQLQuery();

      myQu.create("drop collection test");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection dropped");

      myQu.create("create collection test DoubleSet");
      RasMArrayDouble mddDouble = new RasMArrayDouble(domain, stl);
      double[] dataDouble = new double[len];
      //byte[] dataDouble = new byte[288];
      mddDouble.setObjectTypeName("DoubleImage");

      for(double j = 0; j < dataDouble.length; j++)
        dataDouble[(int)j] = j;

      mddDouble.setArray(dataDouble);

      //System.out.println("\nbyte array: ");
      //for(int j=0; j<mddDouble.getArray().length; j++)
      //{
        //System.out.print(" "+ mddDouble.getArray()[j]);
      //}

      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("\ncollection created");
      myQu.create("insert into test values $1 ");

      //System.out.println("mdd before sending: " + mddDouble);
      myQu.bind(mddDouble);
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection inserted");

      myQu = myApp.newOQLQuery();
      myQu.create("select img from test as img");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection selected");
      if (resultBag != null)
      {
	Iterator iter = resultBag.iterator();
	while (iter.hasNext())
	{
          result = iter.next();
          equal = true;
          for(int j=0; j<mddDouble.getDoubleArray().length; j++)
          {
            if(mddDouble.getArray()[j] != ((RasGMArray)result).getArray()[j])
                equal = false;
          }
          System.out.println("result mdd: " + ((RasGMArray)mddDouble).toTestString());
          System.out.println("result mdd: " + ((RasGMArray)result).toTestString());
        }
          //System.out.println("All results for MArrayDouble");
          System.out.println("inserted and selected MArrayDouble are equal: " + equal);
      }


      // testing copy constructor
      System.out.println("### Testing copy constructor:");
      RasMArrayDouble mddDouble2 = new RasMArrayDouble(mddDouble);
      mddDouble2.setArray(dataDouble);
      //System.out.println("byte array2: ");
      dataDouble = null;
      equal = true;
      for(int j=0; j<mddDouble2.getArray().length; j++)
      {
        //System.out.print(" "+ mddDouble2.getArray()[j]);
        if(mddDouble.getArray()[j] != mddDouble2.getArray()[j])
              equal = false;
      }
      System.out.println("Copy constructor is OK: " + equal);

      /*
      System.out.println("\nspecial array2: ");
      for(int j=0; j<mddDouble2.getDoubleArray().length; j++)
      {
        System.out.print(" "+ mddDouble2.getDoubleArray()[j]);
      }
      */

      /**
       * test the MArrayFloat
       */
      System.out.println("\n\n### Testing MArrayFloat: ################################################");
      myQu = myApp.newOQLQuery();

      myQu.create("drop collection test");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection dropped");

      myQu.create("create collection test FloatSet");
      RasMArrayFloat mddFloat = new RasMArrayFloat(domain, stl);
      float[] dataFloat = new float[len];
      //byte[] dataFloat = new byte[144];
      mddFloat.setObjectTypeName("FloatImage");

      for(float j = 0; j < dataFloat.length; j++)
        dataFloat[(int)j] = j;

      mddFloat.setArray(dataFloat);

      //System.out.println("\nbyte array: ");
      //for(int j=0; j<mddFloat.getArray().length; j++)
      //{
        //System.out.print(" "+ mddFloat.getArray()[j]);
      //}

      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("\ncollection created");
      myQu.create("insert into test values $1 ");

      //System.out.println("mdd before sending: " + mddFloat);
      myQu.bind(mddFloat);
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection inserted");

      myQu = myApp.newOQLQuery();
      myQu.create("select img from test as img");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection selected");
      if (resultBag != null)
      {
	Iterator iter = resultBag.iterator();
	while (iter.hasNext())
	{
          result = iter.next();
          equal = true;
          for(int j=0; j<mddFloat.getArray().length; j++)
          {
            if(mddFloat.getArray()[j] != ((RasGMArray)result).getArray()[j])
              equal = false;
          }
          System.out.println("result mdd: " + ((RasGMArray)mddFloat).toTestString());
          System.out.println("result mdd: " + ((RasGMArray)result).toTestString());
        }
          //System.out.println("All results for MArrayFloat");
          System.out.println("inserted and selected MArrayFloat are equal: " + equal);
      }

      // testing copy constructor
      System.out.println("### Testing copy constructor:");
      RasMArrayFloat mddFloat2 = new RasMArrayFloat(mddFloat);
      mddFloat2.setArray(dataFloat);
      //System.out.println("\nbyte array2: ");
      dataFloat = null;
      equal = true;
      for(int j=0; j<mddFloat2.getArray().length; j++)
      {
        //System.out.print(" "+ mddFloat2.getArray()[j]);
        if(mddFloat.getArray()[j] != mddFloat2.getArray()[j])
              equal = false;
      }
      System.out.println("Copy constructor is OK: " + equal);
      /*
      System.out.println("\nspecial array2: ");
      for(int j=0; j<mddFloat2.getFloatArray().length; j++)
      {
        System.out.print(" "+ mddFloat2.getFloatArray()[j]);
      }
      */

      /**
       * test the MArrayShort
       */
      System.out.println("\n\n### Testing MArrayShort: ################################################");
      myQu = myApp.newOQLQuery();

      myQu.create("drop collection test");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection dropped");

      myQu.create("create collection test ShortSet");
      RasMArrayShort mddShort = new RasMArrayShort(domain, stl);
      //RasMArrayShort mddShort4 = new RasMArrayShort(domain, stl);
      //RasMArrayShort mddShort3 = new RasMArrayShort(domain, stl);
      short[] dataShort = new short[len];
      //short[] dataShort4 = new short[len];
      //short[] dataShort3 = new short[len];
      //byte[] dataShort = new byte[72];
      mddShort.setObjectTypeName("ShortImage");
      //mddShort4.setObjectTypeName("ShortImage");
      //mddShort3.setObjectTypeName("ShortImage");

      //System.out.println("new OID from server: " + myApp.getObjectId(mddShort));
      //System.out.println("new OID from server: " + myApp.getObjectId(mddShort4));
      for(int j = 0; j < dataShort.length; j++)
        dataShort[j] = (short)j;

      //for(int j = 0; j < dataShort.length; j++)
        //dataShort[j] = 1;
      //for(int j = 0; j < dataShort4.length; j++)
        //dataShort4[j] = 2;
      //for(int j = 0; j < dataShort3.length; j++)
        //dataShort3[j] = 3;


      mddShort.setArray(dataShort);
      //mddShort4.setArray(dataShort4);
      //mddShort3.setArray(dataShort3);
      /*
      System.out.println("\nbyte array: ");
      for(int j=0; j<mddShort.getArray().length; j++)
      {
        System.out.print(" "+ mddShort.getArray()[j]);
      }
      */
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      myQu = myApp.newOQLQuery();
      //System.out.println("\ncollection created");
      //myQu.create("insert into test values $1");
      myQu.create("insert into test values $1");
      //System.out.println("mdd before sending: " + mddShort);
      //myQu.bind("test");
      myQu.bind(mddShort);
      //myQu.bind(mddShort4);
      //myQu.bind(mddShort3);
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      /*
      myTa.begin();
      myQu = myApp.newOQLQuery();
      myQu.create("insert into test values $1");
      myQu.bind(mddShort4);
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      myTa.begin();
      myQu = myApp.newOQLQuery();
      myQu.create("insert into test values $1");
      myQu.bind(mddShort3);
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      */
      //System.out.println("collection inserted");
      myQu = myApp.newOQLQuery();
      myQu.create("select img from test as img");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection selected");
      if (resultBag != null)
      {
	Iterator iter = resultBag.iterator();
	while (iter.hasNext())
	{
          result = iter.next();
          equal = true;
          for(int j=0; j<mddShort.getArray().length; j++)
          {
            if(mddShort.getArray()[j] != ((RasGMArray)result).getArray()[j])
              equal = false;
          }
          System.out.println("result mdd: " + ((RasGMArray)mddShort).toTestString());
          System.out.println("result mdd: " + ((RasGMArray)result).toTestString());
        }
          //System.out.println("All results for MArrayShort");
          System.out.println("inserted and selected MArrayShort are equal: " + equal);
      }

      // testing copy constructor
      System.out.println("### Testing copy constructor:");
      RasMArrayShort mddShort2 = new RasMArrayShort(mddShort);
      mddShort2.setArray(dataShort);
      //System.out.println("\nbyte array2: ");
      dataShort = null;
      equal = true;
      for(int j=0; j<mddShort2.getArray().length; j++)
      {
        //System.out.print(" "+ mddShort2.getArray()[j]);
        if(mddShort.getArray()[j] != mddShort2.getArray()[j])
              equal = false;
      }
      System.out.println("Copy constructor is OK: " + equal);
      /*
      System.out.println("\nspecial array2: ");
      for(int j=0; j<mddShort2.getShortArray().length; j++)
      {
        System.out.print(" "+ mddShort2.getShortArray()[j]);
      }
      */

      /**
       * test the MArrayLong
       */
      System.out.println("\n\n### Testing MArrayLong: ################################################");
      myQu = myApp.newOQLQuery();

      myQu.create("drop collection test");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection dropped");

      myQu.create("create collection test ULongSet");
      RasMArrayLong mddLong = new RasMArrayLong(domain, stl);
      long[] dataLong = new long[len];
      //byte[] dataLong = new byte[288];
      mddLong.setObjectTypeName("ULongImage");

      for(long j = 0; j < dataLong.length; j++)
        dataLong[(int)j] = j;
      mddLong.setArray(dataLong);

      /*
      System.out.println("\nbyte array: ");
      for(int j=0; j<mddLong.getArray().length; j++)
      {
        System.out.print(" "+ mddLong.getArray()[j]);
      }
      */

      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("\ncollection created");
      myQu.create("insert into test values $1 ");

      //System.out.println("mdd before sending: " + mddLong);
      myQu.bind(mddLong);
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection inserted");

      myQu = myApp.newOQLQuery();
      myQu.create("select img from test as img");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      //System.out.println("collection selected");
      if (resultBag != null)
      {
	Iterator iter = resultBag.iterator();
	while (iter.hasNext())
	{
          result = iter.next();
          equal = true;
          for(int j=0; j<((RasGMArray)result).getArray().length; j++)
          {
            if(mddLong.getArray()[j] != ((RasGMArray)result).getArray()[j])
              equal = false;
          }
          System.out.println("result mdd: " + ((RasGMArray)mddLong).toTestString());
          System.out.println("result mdd: " + ((RasGMArray)result).toTestString());
        }
        //System.out.println("All results for MArrayLong");
        System.out.println("inserted MArrayInteger and selected MArrayLong are equal: " + equal);
      }

      // testing copy constructor
      System.out.println("### Testing copy constructor:");
      RasMArrayLong mddLong2 = new RasMArrayLong(mddLong);
      mddLong2.setArray(dataLong);
      //System.out.println("\nbyte array2: ");
      dataLong = null;
      equal = true;
      for(int j=0; j<mddLong2.getArray().length; j++)
      {
        //System.out.print(" "+ mddLong2.getArray()[j]);
        if(mddLong.getArray()[j] != mddLong2.getArray()[j])
              equal = false;
      }
      System.out.println("Copy constructor is OK: " + equal);

      System.out.println("\nspecial array: ");
      for(int j=0; j<((RasMArrayLong)result).getLongArray().length; j++)
      {
        System.out.print(" "+ ((RasMArrayLong)result).getLongArray()[j]);
      }


      /**
       * testing intersection
       */
      System.out.println("\n\n### Testing intersection:");
      mddConst2.intersectionWith(domain2);
      mddByte2.intersectionWith(domain2);
      mddDouble2.intersectionWith(domain2);
      mddFloat2.intersectionWith(domain2);
      mddInteger2.intersectionWith(domain2);
      mddLong2.intersectionWith(domain2);
      mddShort2.intersectionWith(domain2);
      System.out.println("OK\n");

      /**
       * testing OIDs
       */
      myQu = myApp.newOQLQuery();
      myQu.create("SELECT oid(img) FROM test AS img");
      //myQu.create("SELECT img FROM test AS img where (oid(img)=231425)");
      myTa.begin();
      resultBag = (DBag)myQu.execute();
      myTa.commit();
      if (resultBag != null)
      {
	Iterator iter = resultBag.iterator();
	while (iter.hasNext())
	{
          result = iter.next();
          //System.out.println("OID: " + result);
        }
        //System.out.println("All results");

      }

      /**
       * get new OID
       */
      System.out.println("### Testing OIDs:");
      myTa.begin();
      myApp.getObjectId(new RasGMArray());
      myTa.commit();

      System.out.println( "Closing database ..." );
      myDb.close();

      // get new OID without open TA
      RasGMArray gmar = new RasGMArray();
      equal = true;
      if(!myApp.getObjectId(gmar).equals(gmar.getOID().toString()))
        equal = false;
      System.out.println("same OID on client and server side: " + equal);

    }
    catch (RasException e)
    {
      System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!");
      System.out.println("An RasException has occurred: " + e.getMessage());
      System.out.println("Try to abort the transaction ...");
      if(myTa != null) myTa.abort();

      try
      {
        System.out.println("Try to close the database ...");
	if(myDb != null) myDb.close();
      }
      catch ( org.odmg.ODMGException exp )
      {
        System.err.println("Could not close the database: " + exp.getMessage());
      }
    }
    catch (RasRuntimeException e)
    {
      System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!");
      System.out.println("An RasRuntimeException has occurred: " + e.getMessage());
      System.out.println("Try to abort the transaction ...");
      if(myTa != null) myTa.abort();

      try
      {
        System.out.println("Try to close the database ...");
	if(myDb != null) myDb.close();
      }
      catch ( org.odmg.ODMGException exp )
      {
        System.err.println("Could not close the database: " + exp.getMessage());
      }
    }
    catch (org.odmg.ODMGException e)
    {
      System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!");
      System.out.println("An ODMGException has occurred: " + e.getMessage());
      System.out.println("Try to abort the transaction ...");
      if(myTa != null) myTa.abort();

      try
      {
        System.out.println("Try to close the database ...");
	if(myDb != null) myDb.close();
      }
      catch ( org.odmg.ODMGException exp )
      {
        System.err.println("Could not close the database: " + exp.getMessage());
      }
    }
    System.out.println( "Done." );

  }
}