Package com.sleepycat.je

Examples of com.sleepycat.je.Transaction


        if (currentTxn != null &&
            (allowNestedTxn || currentTxn.getTransaction() == null)) {
            /* Transactional and (not nested or nested txns allowed). */
            int useMaxRetries = maxRetries;
            for (int retries = 0;; retries += 1) {
                Transaction txn = null;
                try {
                    txn = currentTxn.beginTransaction(config);
                    worker.doWork();
                    if (txn != null && txn == currentTxn.getTransaction()) {
                        currentTxn.commitTransaction();
View Full Code Here


            if (trans.txn != null) {
                if (!DbCompat.NESTED_TRANSACTIONS) {
                    throw new IllegalStateException
                        ("Nested transactions are not supported");
                }
                Transaction parentTxn = trans.txn;
                trans = new Trans(trans, config);
                trans.txn = env.beginTransaction(parentTxn, config);
                localTrans.set(trans);
            } else {
                trans.txn = env.beginTransaction(null, config);
View Full Code Here

    public final Transaction commitTransaction()
        throws DatabaseException, IllegalStateException {

        Trans trans = (Trans) localTrans.get();
        if (trans != null && trans.txn != null) {
            Transaction parent = closeTxn(trans);
            trans.txn.commit();
            return parent;
        } else {
            throw new IllegalStateException("No transaction is active");
        }
View Full Code Here

    public final Transaction abortTransaction()
        throws DatabaseException, IllegalStateException {

        Trans trans = (Trans) localTrans.get();
        if (trans != null && trans.txn != null) {
            Transaction parent = closeTxn(trans);
            trans.txn.abort();
            return parent;
        } else {
            throw new IllegalStateException("No transaction is active");
        }
View Full Code Here

                              final EntityModel modelParam,
                              final Mutations mutationsParam)
        throws DatabaseException {

        for (int i = 0;; i += 1) {
            Transaction txn = null;
            if (transactional && DbCompat.getThreadTransaction(env) == null) {
                txn =
                    env.beginTransaction(null, store.getAutoCommitTxnConfig());
            }
            boolean success = false;
            try {
                init(txn, storePrefix, modelParam, mutationsParam);
                success = true;
                return;
            } catch (LockConflictException e) {

                /*
                 * It is very unlikely that two threads opening the same
                 * EntityStore will cause a lock conflict.  However, because we
                 * read-modify-update the catalog record,
                 * LockPreemptedException must be handled in a replicated JE
                 * environment.  Since LockPreemptedException is a
                 * LockConfictException, it is simplest to retry when any
                 * LockConfictException occurs.
                 */
                if (i >= MAX_TXN_RETRIES) {
                    throw e;
                }
                continue;
            } finally {

                /*
                 * If the catalog is read-only we abort rather than commit,
                 * because a ReplicaWriteException may have occurred.
                 * ReplicaWriteException invalidates the transaction, and there
                 * are no writes to commit anyway. [#16655]
                 */
                if (txn != null) {
                    if (success && !isReadOnly()) {
                        txn.commit();
                    } else {
                        txn.abort();
                    }
                }
            }
        }
    }
View Full Code Here

     */
    private void writeDataCheckStale(Data newData)
        throws DatabaseException, RefreshException {

        for (int i = 0;; i += 1) {
            Transaction txn = null;
            if (transactional && DbCompat.getThreadTransaction(env) == null) {
                txn =
                    env.beginTransaction(null, store.getAutoCommitTxnConfig());
            }
            boolean success = false;
            try {
                if (isMetadataStale(txn)) {
                    throw new RefreshException(store, this,  -1 /*formatId*/);
                }
                writeData(txn, newData);
                success = true;
                return;
            } catch (LockConflictException e) {

                /*
                 * A lock conflict should not occur because writes to the
                 * catalog DB are in synchronized methods.  However, because we
                 * read-modify-update the catalog record,
                 * LockPreemptedException must be handled in a replicated JE
                 * environment.  Since LockPreemptedException is a
                 * LockConfictException, it is simplest to retry when any
                 * LockConfictException occurs.
                 */
                if (i >= MAX_TXN_RETRIES) {
                    throw e;
                }
                continue;
            } finally {

                /*
                 * If the catalog is read-only we abort rather than commit,
                 * because a ReplicaWriteException may have occurred.
                 * ReplicaWriteException invalidates the transaction, and there
                 * are no writes to commit anyway. [#16655]
                 */
                if (txn != null) {
                    if (success && !isReadOnly()) {
                        txn.commit();
                    } else {
                        txn.abort();
                    }
                }
            }
        }
    }
View Full Code Here

        if (cdbMode) {
            cursorConfig = new CursorConfig();
            DbCompat.setWriteCursor(cursorConfig, true);
        }
        Cursor cursor = null;
        Transaction txn = null;
        try {
            if (txnMode) {
                txn = db.getEnvironment().beginTransaction(null, null);
            }
            cursor = db.openCursor(txn, cursorConfig);

            /* Get the current class ID. */
            DatabaseEntry key = new DatabaseEntry(LAST_CLASS_ID_KEY);
            DatabaseEntry data = new DatabaseEntry();
            OperationStatus status = cursor.getSearchKey(key, data,
                                                         writeLockMode);
            if (status != OperationStatus.SUCCESS) {
                throw DbCompat.unexpectedState("Class ID not initialized");
            }
            byte[] idBytes = getBytes(data);

            /* Increment the ID by one and write the updated record.  */
            idBytes = incrementID(idBytes);
            data.setData(idBytes);
            cursor.put(key, data);

            /*
             * Write the new class format record whose key is the ID just
             * assigned.
             */
            byte[] keyBytes = new byte[1 + idBytes.length];
            keyBytes[0] = REC_CLASS_FORMAT;
            System.arraycopy(idBytes, 0, keyBytes, 1, idBytes.length);
            key.setData(keyBytes);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos;
            try {
                oos = new ObjectOutputStream(baos);
                oos.writeObject(classFormat);
            } catch (IOException e) {
                throw RuntimeExceptionWrapper.wrapIfNeeded(e);
            }
            data.setData(baos.toByteArray());

            cursor.put(key, data);

            /*
             * Write the new class info record, using the key passed in; this
             * is done last so that a reader who gets the class info record
             * first will always find the corresponding class format record.
             */
            classInfo.setClassID(idBytes);
            classInfo.toDbt(data);

            cursor.put(classKey, data);

            /*
             * Update the maps before closing the cursor, so that the cursor
             * lock prevents other writers from duplicating this entry.
             */
            classInfo.setClassFormat(classFormat);
            classMap.put(className, classInfo);
            formatMap.put(new BigInteger(idBytes), classFormat);
            return classInfo;
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (txn != null) {
                txn.commit();
            }
        }
    }
View Full Code Here

    /*
     * Initiate the LogChangeSet, if there exists any exceptions while reading
     * the ChangeSet metadata from SyncDB, invalidate the Environment.
     */
    private void initChangeSet(Environment env) {
        Transaction txn = env.beginTransaction(null, null);
        boolean success = false;

        try {
            DatabaseEntry changeSetData = new DatabaseEntry();

            processor.readChangeSetData(txn, dataSetName, changeSetData);

            /*
             * If there is no ChangeSet information for this SyncDataSet in
             * SyncDB, create a new one, otherwise deserialize the
             * DatabaseEntry.
             */
            changeSet = (changeSetData.getData() == null) ?
                new LogChangeSet() : binding.entryToObject(changeSetData);
            success = true;
        } finally {
           if (success) {
              txn.commit();
           } else {
              txn.abort();
           }
        }
    }
View Full Code Here

         */
        boolean success = false;

        final Environment env = envImpl.getInternalEnvHandle();
        assert env != null;
        final Transaction txn = DbInternal.beginInternalTransaction(env, null);
        try {

            /*
             * TODO: Need to call close, or make SyncDB a singleton, to avoid
             * leaving a Database handle open every time the SyncDB is
             * constructed.
             */
            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setAllowCreate(allowCreate);
            dbConfig.setTransactional(true);
          
            /* Set the trigger for updating the SyncCleanerBarrier. */
            SyncTrigger trigger = new SyncTrigger(SYNC_TRIGGER_NAME);
            ArrayList<Trigger> list = new ArrayList<Trigger>();
            list.add(trigger);
            dbConfig.setTriggers(list);

            DbInternal.setReplicated(dbConfig, true);

            db = DbInternal.openInternalDatabase
                (env, txn, DbType.SYNC.getInternalName(), dbConfig);
            dbImpl = DbInternal.getDatabaseImpl(db);
            success = true;
        } finally {
            if (success) {
                txn.commit();
            } else {
                txn.abort();
            }
        }
    }
View Full Code Here

                                       boolean doCleaning)
        throws Exception {

        long a, c, d, e, f;

        Transaction txn = null;
        CheckpointConfig force = new CheckpointConfig();
        force.setForce(true);

        a = System.currentTimeMillis();
        env.removeDatabase(txn, name);
View Full Code Here

TOP

Related Classes of com.sleepycat.je.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.