| 1 | /*
|
|---|
| 2 | * To change this license header, choose License Headers in Project Properties.
|
|---|
| 3 | * To change this template file, choose Tools | Templates
|
|---|
| 4 | * and open the template in the editor.
|
|---|
| 5 | */
|
|---|
| 6 | package rasdaman.testconnectionrasj;
|
|---|
| 7 |
|
|---|
| 8 | import org.odmg.Database;
|
|---|
| 9 | import org.odmg.ODMGException;
|
|---|
| 10 | import org.odmg.Transaction;
|
|---|
| 11 | import rasj.RasImplementation;
|
|---|
| 12 |
|
|---|
| 13 | /**
|
|---|
| 14 | *
|
|---|
| 15 | * @author dimitar
|
|---|
| 16 | */
|
|---|
| 17 | public class TestConnection {
|
|---|
| 18 |
|
|---|
| 19 | private static String server = "localhost";
|
|---|
| 20 | private static String port = "7001";
|
|---|
| 21 | private static String databaseName = "RASBASE";
|
|---|
| 22 | private static String user = "rasadmin";
|
|---|
| 23 | private static String password = "rasadmin";
|
|---|
| 24 |
|
|---|
| 25 | public static void main(String[] args) {
|
|---|
| 26 | System.out.println("----------------------------------------------------");
|
|---|
| 27 | System.out.println("Starting test");
|
|---|
| 28 | long startTime = 0;
|
|---|
| 29 | long totalStartTime = System.nanoTime();
|
|---|
| 30 | Database database = null;
|
|---|
| 31 | try {
|
|---|
| 32 | startTime = System.nanoTime();
|
|---|
| 33 | RasImplementation app = new RasImplementation("http://" + server + ":" + port);
|
|---|
| 34 |
|
|---|
| 35 | System.out.println("Constructing RasImplementation: " +
|
|---|
| 36 | ((System.nanoTime() - startTime)/1000000) + " ms");
|
|---|
| 37 | startTime = System.nanoTime();
|
|---|
| 38 |
|
|---|
| 39 | app.setUserIdentification(user, password);
|
|---|
| 40 |
|
|---|
| 41 | System.out.println("Setting user identification: " +
|
|---|
| 42 | ((System.nanoTime() - startTime)/1000000) + " ms");
|
|---|
| 43 | startTime = System.nanoTime();
|
|---|
| 44 |
|
|---|
| 45 | database = app.newDatabase();
|
|---|
| 46 |
|
|---|
| 47 | System.out.println("Creating Database: " +
|
|---|
| 48 | ((System.nanoTime() - startTime)/1000000) + " ms");
|
|---|
| 49 | startTime = System.nanoTime();
|
|---|
| 50 |
|
|---|
| 51 | database.open(databaseName, Database.OPEN_READ_WRITE);
|
|---|
| 52 |
|
|---|
| 53 | System.out.println("Opening database: " +
|
|---|
| 54 | ((System.nanoTime() - startTime)/1000000) + " ms");
|
|---|
| 55 |
|
|---|
| 56 | for (int i = 0; i < 10; i++)
|
|---|
| 57 | {
|
|---|
| 58 | System.out.println("");
|
|---|
| 59 | startTime = System.nanoTime();
|
|---|
| 60 | Transaction transaction = app.newTransaction();
|
|---|
| 61 |
|
|---|
| 62 | System.out.println("Creating Transaction " + i + ": " +
|
|---|
| 63 | ((System.nanoTime() - startTime)/1000000) + " ms");
|
|---|
| 64 | startTime = System.nanoTime();
|
|---|
| 65 |
|
|---|
| 66 | transaction.begin();
|
|---|
| 67 |
|
|---|
| 68 | System.out.println("Begin Transaction " + i + ": " +
|
|---|
| 69 | ((System.nanoTime() - startTime)/1000000) + " ms");
|
|---|
| 70 | startTime = System.nanoTime();
|
|---|
| 71 |
|
|---|
| 72 | // do some stuff here...
|
|---|
| 73 | transaction.commit();
|
|---|
| 74 |
|
|---|
| 75 | System.out.println("Commit Transaction " + i + ": " +
|
|---|
| 76 | ((System.nanoTime() - startTime)/1000000) + " ms");
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | } catch (ODMGException e) {
|
|---|
| 81 | e.printStackTrace();
|
|---|
| 82 | } finally {
|
|---|
| 83 | if (database != null) {
|
|---|
| 84 | try {
|
|---|
| 85 | database.close();
|
|---|
| 86 | } catch (ODMGException e) {
|
|---|
| 87 | e.printStackTrace();
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | long estimatedTime = System.nanoTime() - totalStartTime;
|
|---|
| 93 | System.out.println("Total elapsed time: " + (estimatedTime/1000000) + " ms");
|
|---|
| 94 | System.out.println("Test finished");
|
|---|
| 95 | System.out.println("----------------------------------------------------");
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | }
|
|---|