Package de.zib.scalaris

Examples of de.zib.scalaris.Transaction


        System.out.println("Reading values with the class `Transaction`:");

        System.out.print("    Initialising Transaction object... ");
        try {
            final Transaction transaction = new Transaction();
            System.out.println("done");

            System.out.print("    Starting transaction... ");
            System.out.println("done");

            System.out
                    .println("    `OtpErlangObject readObject(OtpErlangString)`...");
            for (int i = 0; i < otpKeys.arity(); ++i) {
                final OtpErlangString otpKey = (OtpErlangString) otpKeys.elementAt(i);
                try {
                    otpValue = (OtpErlangString) transaction.read(otpKey).value();
                    System.out.println("      read(" + otpKey.stringValue()
                            + ") == " + otpValue.stringValue());
                } catch (final ConnectionException e) {
                    System.out.println("      read(" + otpKey.stringValue()
                            + ") failed: " + e.getMessage());
                } catch (final TimeoutException e) {
                    System.out.println("      read(" + otpKey.stringValue()
                            + ") failed with timeout: " + e.getMessage());
                } catch (final UnknownException e) {
                    System.out.println("      read(" + otpKey.stringValue()
                            + ") failed with unknown: " + e.getMessage());
                } catch (final NotFoundException e) {
                    System.out.println("      read(" + otpKey.stringValue()
                            + ") failed with not found: " + e.getMessage());
                } catch (final ClassCastException e) {
                    System.out.println("      read(" + otpKey.stringValue()
                            + ") failed with unknown return type: " + e.getMessage());
                }
            }

            System.out.println("    `String read(String)`...");
            for (int i = 0; i < keys.length; ++i) {
                final String key = keys[i];
                try {
                    value = transaction.read(key).stringValue();
                    System.out.println("      read(" + key + ") == " + value);
                } catch (final ConnectionException e) {
                    System.out.println("      read(" + key + ") failed: "
                            + e.getMessage());
                } catch (final TimeoutException e) {
                    System.out.println("      read(" + key
                            + ") failed with timeout: " + e.getMessage());
                } catch (final UnknownException e) {
                    System.out.println("      read(" + key
                            + ") failed with unknown: " + e.getMessage());
                } catch (final NotFoundException e) {
                    System.out.println("      read(" + key
                            + ") failed with not found: " + e.getMessage());
                }
            }

            System.out.print("    Committing transaction... ");
            transaction.commit();
            System.out.println("done");
        } catch (final ConnectionException e) {
            System.out.println("failed: " + e.getMessage());
            return;
        } catch (final TimeoutException e) {
View Full Code Here


        System.out.println("Writing values with the class `Transaction`:");

        System.out.print("    Initialising Transaction object... ");
        try {
            final Transaction transaction = new Transaction();
            System.out.println("done");

            System.out.print("    Starting transaction... ");
            System.out.println("done");

            System.out
                    .println("    `writeObject(OtpErlangString, OtpErlangObject)`...");
            for (int i = 0; i < otpKeys.arity(); ++i) {
                final OtpErlangString otpKey = (OtpErlangString) otpKeys.elementAt(i);
                final OtpErlangString otpValue = (OtpErlangString) otpValues
                        .elementAt(i);
                try {
                    transaction.write(otpKey, otpValue);
                    System.out.println("      write(" + otpKey.stringValue()
                            + ", " + otpValue.stringValue() + ") succeeded");
                } catch (final ConnectionException e) {
                    System.out.println("      write(" + otpKey.stringValue()
                            + ", " + otpValue.stringValue() + ") failed: "
                            + e.getMessage());
                } catch (final TimeoutException e) {
                    System.out.println("      write(" + otpKey.stringValue()
                            + ", " + otpValue.stringValue()
                            + ") failed with timeout: " + e.getMessage());
                } catch (final UnknownException e) {
                    System.out.println("      write(" + otpKey.stringValue()
                            + ", " + otpValue.stringValue()
                            + ") failed with unknown: " + e.getMessage());
                }
            }

            System.out.println("    `write(String, String)`...");
            for (int i = 0; i < keys.length; ++i) {
                final String key = keys[i];
                final String value = values[i];
                try {
                    transaction.write(key, value);
                    System.out.println("      write(" + key + ", " + value
                            + ") succeeded");
                } catch (final ConnectionException e) {
                    System.out.println("      write(" + key + ", " + value
                            + ") failed: " + e.getMessage());
                } catch (final TimeoutException e) {
                    System.out.println("      write(" + key + ", " + value
                            + ") failed with timeout: " + e.getMessage());
                } catch (final UnknownException e) {
                    System.out.println("      write(" + key + ", " + value
                            + ") failed with unknown: " + e.getMessage());
                }
            }

            System.out.print("    Committing transaction... ");
            transaction.commit();
            System.out.println("done");
        } catch (final ConnectionException e) {
            System.out.println("failed: " + e.getMessage());
            return;
        } catch (final TimeoutException e) {
View Full Code Here

        String result3 = "";
        System.out.println("Transaction 1 using class `Transaction`:");

        System.out.print("    Initialising Transaction object... ");
        try {
            final Transaction transaction = new Transaction();
            System.out.println("done");

            try {
                System.out.print("    Starting transaction... ");
                System.out.println("done");

                otpWrite(transaction, key1, value1);
                otpWrite(transaction, key2, value2);

                result1 = otpRead(transaction, key1);
                result2 = otpRead(transaction, key2);
                try {
                    result3 = otpRead(transaction, key3);
                } catch (final NotFoundException e) {
//                    System.out.println("    caught not_found for " + key3);
                }

                otpWrite(transaction, key3, result1 + result2);

                result3 = otpRead(transaction, key3);

                System.out.print("    Committing transaction... ");
                transaction.commit();
                System.out.println("done");

                System.out.println();
                System.out.println("    --------------------");
                System.out.println();

                System.out.print("    Starting transaction... ");
                System.out.println("done");

                write(transaction, key1, value1);
                write(transaction, key2, value2);

                result1 = read(transaction, key1);
                result2 = read(transaction, key2);
                try {
                    result3 = read(transaction, key3);
                } catch (final NotFoundException e) {
//                  System.out.println("    caught not_found for " + key3);
                }

                write(transaction, key3, result1 + result2);

                result3 = read(transaction, key3);

                System.out.print("    Committing transaction... ");
                transaction.commit();
                System.out.println("done");
            } catch (final TimeoutException e) {
                // read/write operation
                transaction.abort();
                System.out.println("    Transaction aborted due to timeout: "
                        + e.getMessage());
            } catch (final NotFoundException e) {
                // read/write operation
                transaction.abort();
                System.out
                        .println("    Transaction aborted because elements were not found although they should exist: "
                                + e.getMessage());
            } catch (final AbortException e) {
                System.out.println("    Transaction aborted during commit: "
View Full Code Here

            final String value2, final String key3) {
        System.out.println("Transaction 2 using class `Transaction`:");

        System.out.print("    Initialising Transaction object... ");
        try {
            final Transaction transaction = new Transaction();
            System.out.println("done");

            try {
                System.out.print("    Starting transaction... ");
                System.out.println("done");

                otpWrite(transaction, key1, value1);

                System.out.print("    Committing transaction... ");
                transaction.commit();
                System.out.println("done");

                System.out.print("    Starting transaction... ");
                System.out.println("done");

                otpWrite(transaction, key1, "WRONG value");
                otpRead(transaction, key1);

                System.out.print("    Aborting transaction... ");
                transaction.abort();
                System.out.println("done");

                System.out.print("    Starting transaction... ");
                System.out.println("done");

                otpRead(transaction, key1);

                System.out.print("    Committing transaction... ");
                transaction.commit();
                System.out.println("done");

                System.out.println();
                System.out.println("    --------------------");
                System.out.println();

                System.out.print("    Starting transaction... ");
                System.out.println("done");

                write(transaction, key1, value1);

                System.out.print("    Committing transaction... ");
                transaction.commit();
                System.out.println("done");

                System.out.print("    Starting transaction... ");
                System.out.println("done");

                write(transaction, key1, "WRONG value");
                read(transaction, key1);

                System.out.print("    Aborting transaction... ");
                transaction.abort();
                System.out.println("done");

                System.out.print("    Starting transaction... ");
                System.out.println("done");

                read(transaction, key1);

                System.out.print("    Committing transaction... ");
                transaction.commit();
                System.out.println("done");

            } catch (final TimeoutException e) {
                // read/write operation
                transaction.abort();
                System.out.println("    Transaction aborted due to timeout: "
                        + e.getMessage());
            } catch (final NotFoundException e) {
                // read/write operation
                transaction.abort();
                System.out
                        .println("    Transaction aborted because elements were not found although they should exist: "
                                + e.getMessage());
            } catch (final AbortException e) {
                System.out.println("    Transaction aborted during commit: "
View Full Code Here

                Connection connection = cFactory.createConnection(
                        "wiki_import", true);
                scalaris_single.put(new TransactionSingleOp(connection));
                connection = cFactory.createConnection(
                        "wiki_import", true);
                scalaris_tx.put(new Transaction(connection));
            }
        } catch (ConnectionException e) {
            System.err.println("Connection to Scalaris failed");
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
View Full Code Here

            this.scalaris_pageCount_key = scalaris_pageCount_key;
        }
       
        @Override
        public void run() {
            Transaction scalaris_tx;
            try {
                scalaris_tx = this.scalaris_tx.take();
            } catch (InterruptedException e) {
                System.err.println("update of " + scalaris_pageList_key + " and " + scalaris_pageCount_key + " interrupted while getting connection to Scalaris");
                throw new RuntimeException(e);
View Full Code Here

                    oldPage, newPage, newShortRevs, pageEdits, statName,
                    System.currentTimeMillis() - timeAtStart);
        }
       
        String title = MyWikiModel.normalisePageTitle(title0, nsObject);
        Transaction scalaris_tx = new Transaction(connection);

        // check that the current version is still up-to-date:
        // read old version first, then write
        int oldRevId = -1;
        String pageInfoKey = getPageKey(title0, nsObject);
       
        Transaction.RequestList requests = new Transaction.RequestList();
        requests.addRead(pageInfoKey);
       
        Transaction.ResultList results;
        try {
            results = scalaris_tx.req_list(requests);
        } catch (Exception e) {
            return new SavePageResult(false,
                    "unknown exception getting page info (" + pageInfoKey
                            + ") from Scalaris: " + e.getMessage(),
                    e instanceof ConnectionException, oldPage, newPage,
View Full Code Here

TOP

Related Classes of de.zib.scalaris.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.