Examples of CurrentTransaction


Examples of com.sleepycat.bdb.CurrentTransaction

    final boolean beginAutoCommit() {

        if (isAutoCommit()) {
            try {
                CurrentTransaction currentTxn = view.getCurrentTxn();
                if (currentTxn.getTxn() == null) {
                    currentTxn.beginTxn();
                    return true;
                }
            } catch (DbException e) {
                throw new RuntimeExceptionWrapper(e);
            }
View Full Code Here

Examples of com.sleepycat.bdb.CurrentTransaction


    public static DbTxn createTransaction(DbEnv environment) throws DbException {
        // TODO remove dirty hack!
        cachedEnvironment = environment;
        CurrentTransaction currentTxn = CurrentTransaction.getInstance(environment);
        return currentTxn.beginTxn();
        /**
         // TODO temporary hack until BDB supports nested transactions
         if (getTransactionCount() == 0) {
         DbTxn transaction = environment.txnBegin(getTransaction(), TRANSACTION_FLAGS);
         pushTransaction(transaction);
View Full Code Here

Examples of com.sleepycat.bdb.CurrentTransaction

     * @param transaction
     * @throws javax.jms.JMSException if the transaction could not be committed
     */
    public static DbTxn commitTransaction(DbTxn transaction) throws JMSException {
        try {
            CurrentTransaction currentTxn = CurrentTransaction.getInstance(cachedEnvironment);
            currentTxn.commitTxn();
            return null;
        }
        catch (DbException e) {
            throw JMSExceptionHelper.newJMSException("Failed to commit transaction: " + transaction + " in container: " + e, e);
        }
View Full Code Here

Examples of com.sleepycat.bdb.CurrentTransaction

     * @param transaction
     */
    public static void rollbackTransaction(DbTxn transaction) {
        if (transaction != null) {
            try {
                CurrentTransaction currentTxn = CurrentTransaction.getInstance(cachedEnvironment);
                currentTxn.abortTxn();
            }
            catch (DbException e) {
                log.warn("Cannot rollback transaction due to: " + e, e);
            }
        }
View Full Code Here

Examples of com.sleepycat.bdb.CurrentTransaction


    public static DbTxn createTransaction(DbEnv environment) throws DbException {
        // TODO remove dirty hack!
        cachedEnvironment = environment;
        CurrentTransaction currentTxn = CurrentTransaction.getInstance(environment);
        return currentTxn.beginTxn();
        /**
         // TODO temporary hack until BDB supports nested transactions
         if (getTransactionCount() == 0) {
         DbTxn transaction = environment.txnBegin(getTransaction(), TRANSACTION_FLAGS);
         pushTransaction(transaction);
View Full Code Here

Examples of com.sleepycat.bdb.CurrentTransaction

     * @param transaction
     * @throws javax.jms.JMSException if the transaction could not be committed
     */
    public static DbTxn commitTransaction(DbTxn transaction) throws JMSException {
        try {
            CurrentTransaction currentTxn = CurrentTransaction.getInstance(cachedEnvironment);
            currentTxn.commitTxn();
            return null;
        }
        catch (DbException e) {
            throw JMSExceptionHelper.newJMSException("Failed to commit transaction: " + transaction + " in container: " + e, e);
        }
View Full Code Here

Examples of com.sleepycat.bdb.CurrentTransaction

     * @param transaction
     */
    public static void rollbackTransaction(DbTxn transaction) {
        if (transaction != null) {
            try {
                CurrentTransaction currentTxn = CurrentTransaction.getInstance(cachedEnvironment);
                currentTxn.abortTxn();
            }
            catch (DbException e) {
                log.warn("Cannot rollback transaction due to: " + e, e);
            }
        }
View Full Code Here

Examples of com.sleepycat.collections.CurrentTransaction

        if (!open()) {
            return;
        }

        final CurrentTransaction currentTxn =
            CurrentTransaction.getInstance(env);

        TransactionRunner runner = new TransactionRunner(env);
        try {
            runner.run(new TransactionWorker() {
                public void doWork()
                    throws Exception {

                    insertUntilOutOfMemory(currentTxn.getTransaction());
                }
            });
            fail("Expected OutOfMemoryError");
        } catch (OutOfMemoryError expected) { }

        /*
         * If TransactionRunner does not abort the transaction, this thread
         * will be left with a transaction attached.
         */
        assertNull(currentTxn.getTransaction());

        verifyDataAndClose();
    }
View Full Code Here

Examples of com.sleepycat.collections.CurrentTransaction

    }

    private void writeAndRead()
        throws Exception {

        CurrentTransaction txn = CurrentTransaction.getInstance(env);
        if (txn != null) {
            txn.beginTransaction(null);
        }

        MarshalledObject o1 = new MarshalledObject("data1", "pk1", "ik1", "");
        assertNull(storeMap1.put(null, o1));

        assertEquals(o1, storeMap1.get("pk1"));
        assertEquals(o1, indexMap1.get("ik1"));

        MarshalledObject o2 = new MarshalledObject("data2", "pk2", "", "pk1");
        assertNull(storeMap2.put(null, o2));

        assertEquals(o2, storeMap2.get("pk2"));
        assertEquals(o2, indexMap2.get("pk1"));

        if (txn != null) {
            txn.commitTransaction();
            txn.beginTransaction(null);
        }

        /*
         * store1 contains o1 with primary key "pk1" and index key "ik1".
         *
         * store2 contains o2 with primary key "pk2" and foreign key "pk1",
         * which is the primary key of store1.
         */

        if (onDelete == ForeignKeyDeleteAction.ABORT) {

            /* Test that we abort trying to delete a referenced key. */

            try {
                storeMap1.remove("pk1");
                fail();
            } catch (RuntimeExceptionWrapper expected) {
                assertTrue(expected.getCause() instanceof DatabaseException);
                if (txn != null) {
                    txn.abortTransaction();
                    txn.beginTransaction(null);
                }
            }

            /* Test that we can put a record into store2 with a null foreign
             * key value. */

            o2 = new MarshalledObject("data2", "pk2", "", "");
            assertNotNull(storeMap2.put(null, o2));
            assertEquals(o2, storeMap2.get("pk2"));

            /* The index2 record should have been deleted since the key was set
             * to null above. */

            assertNull(indexMap2.get("pk1"));

            /* Test that now we can delete the record in store1, since it is no
             * longer referenced. */

            assertNotNull(storeMap1.remove("pk1"));
            assertNull(storeMap1.get("pk1"));
            assertNull(indexMap1.get("ik1"));

        } else if (onDelete == ForeignKeyDeleteAction.NULLIFY) {

            /* Delete the referenced key. */

            assertNotNull(storeMap1.remove("pk1"));
            assertNull(storeMap1.get("pk1"));
            assertNull(indexMap1.get("ik1"));

            /* The store2 record should still exist, but should have an empty
             * secondary key since it was nullified. */

            o2 = (MarshalledObject) storeMap2.get("pk2");
            assertNotNull(o2);
            assertEquals("data2", o2.getData());
            assertEquals("pk2", o2.getPrimaryKey());
            assertEquals("", o2.getIndexKey1());
            assertEquals("", o2.getIndexKey2());

        } else if (onDelete == ForeignKeyDeleteAction.CASCADE) {

            /* Delete the referenced key. */

            assertNotNull(storeMap1.remove("pk1"));
            assertNull(storeMap1.get("pk1"));
            assertNull(indexMap1.get("ik1"));

            /* The store2 record should have deleted also. */

            assertNull(storeMap2.get("pk2"));
            assertNull(indexMap2.get("pk1"));

        } else {
            throw new IllegalStateException();
        }

        /*
         * Test that a foreign key value may not be used that is not present
         * in the foreign store. "pk2" is not in store1 in this case.
         */
        MarshalledObject o3 = new MarshalledObject("data3", "pk3", "", "pk2");
        try {
            storeMap2.put(null, o3);
            fail();
        } catch (RuntimeExceptionWrapper expected) {
            assertTrue(expected.getCause() instanceof DatabaseException);
        }

        if (txn != null) {
            txn.commitTransaction();
        }
    }
View Full Code Here

Examples of com.sleepycat.collections.CurrentTransaction

                finalizedFlag.append('.');
            }
        }

        MyEnv myEnv = new MyEnv(env.getHome(), env.getConfig());
        CurrentTransaction myCurrTxn = CurrentTransaction.getInstance(myEnv);

        store.close();
        store = null;
        map = null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.