Package com.sleepycat.je.txn

Examples of com.sleepycat.je.txn.Locker


     */
    public List getDbNames()
        throws DatabaseException {
       
        List nameList = new ArrayList();
        Locker locker = null;
        CursorImpl cursor = null;
        try {
            locker = new BasicLocker(envImpl);
            cursor = new CursorImpl(nameDatabase, locker);
            DatabaseEntry keyDbt = new DatabaseEntry();
            DatabaseEntry dataDbt = new DatabaseEntry();
            if (cursor.positionFirstOrLast(true, null)) {
                OperationStatus status;
                cursor.getCurrentAlreadyLatched(keyDbt, dataDbt,
                                                LockType.READ, true);
                do {
                    String name = new String(keyDbt.getData(), "UTF-8");
                    if (!isReservedDbName(name)) {
                        nameList.add(name);
                    }

                    /* Go on to the next entry. */
                    status = cursor.getNext(keyDbt, dataDbt, LockType.READ,
                                            true,   // go forward
                                            false); // do need to latch
                } while (status == OperationStatus.SUCCESS);
            }
            return nameList;
  } catch (UnsupportedEncodingException UEE) {
      throw new DatabaseException(UEE);
        } finally {
            if (cursor != null) {
                cursor.close();
            }

            if (locker != null) {
                locker.operationEnd();
            }
        }
    }
View Full Code Here


         * DatabaseEntry parameters, since parameter checking is done by the
         * public API.
         */
        UtilizationTracker tracker = new UtilizationTracker(envImpl);
        ObsoleteINCounter inCounter = new ObsoleteINCounter(tracker);
        Locker locker = new ThreadLocker(envImpl);
        Cursor cursor = null;
        int count = 0;
  CursorImpl impl = null;
        try {
      EnvironmentImpl.incThreadLocalReferenceCount();
View Full Code Here

                                     PrintStream out,
                                     boolean verbose)
        throws DatabaseException {

        boolean ok = true;
        Locker locker = new ThreadLocker(envImpl);
        Cursor cursor = null;
  CursorImpl impl = null;
        try {
      EnvironmentImpl.incThreadLocalReferenceCount();
            cursor = DbInternal.newCursor(this, locker, null);
View Full Code Here

        DatabaseUtil.checkForNullDbt(key, "key", true);
        checkRequiredDbState(OPEN, "Can't call SecondaryDatabase.delete:");
        trace(Level.FINEST, "SecondaryDatabase.delete", txn,
              key, null, null);

        Locker locker = null;
        Cursor cursor = null;

        OperationStatus commitStatus = OperationStatus.NOTFOUND;
        try {
            locker = LockerFactory.getWritableLocker
                (envHandle, txn, isTransactional());

            /* Read the primary key (the data of a secondary). */
            cursor = new Cursor(this, locker, null);
            DatabaseEntry pKey = new DatabaseEntry();
            OperationStatus searchStatus =
                cursor.search(key, pKey, LockMode.RMW, SearchMode.SET);

            /* Delete the primary and all secondaries (including this one). */
            if (searchStatus == OperationStatus.SUCCESS) {
                commitStatus = primaryDb.deleteInternal(locker, pKey);
            }
            return commitStatus;
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (locker != null) {
                locker.operationEnd(commitStatus);
            }
        }
    }
View Full Code Here

        checkRequiredDbState(OPEN, "Can't call Database.delete:");
        checkWritable("delete");
        trace(Level.FINEST, "Database.delete", txn, key, null, null);

        OperationStatus commitStatus = OperationStatus.NOTFOUND;
        Locker locker = null;
        try {
            locker = LockerFactory.getWritableLocker
                (envHandle, txn, isTransactional());
            commitStatus = deleteInternal(locker, key);
            return commitStatus;
        } finally {
            if (locker != null) {
                locker.operationEnd(commitStatus);
            }
        }
    }
View Full Code Here

                                DatabaseEntry key,
        DatabaseEntry data,
        PutMode putMode)
        throws DatabaseException {

        Locker locker = null;
        Cursor cursor = null;
        OperationStatus commitStatus = OperationStatus.KEYEXIST;
        try {
            locker = LockerFactory.getWritableLocker
    (envHandle, txn, isTransactional());

            cursor = new Cursor(this, locker, null);
            commitStatus = cursor.putInternal(key, data, putMode);
            return commitStatus;
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (locker != null) {
                locker.operationEnd(commitStatus);
            }
        }
    }
View Full Code Here

        /*
         * Check that all cursors use the same locker, if any cursor is
         * transactional.  And if non-transactional, that all databases are in
         * the same environment.
         */
        Locker locker = cursors[0].getCursorImpl().getLocker();
        if (!locker.isTransactional()) {
            EnvironmentImpl env = envHandle.getEnvironmentImpl();
            for (int i = 1; i < cursors.length; i += 1) {
                Locker locker2 = cursors[i].getCursorImpl().getLocker();
                if (locker2.isTransactional()) {
                    throw new IllegalArgumentException
                            ("All cursors must use the same transaction.");
                }
                EnvironmentImpl env2 = cursors[i].getDatabaseImpl()
                                                 .getDbEnvironment();
                if (env != env2) {
                    throw new IllegalArgumentException
                            ("All cursors must use the same environment.");
                }
            }
            locker = null; /* Don't reuse a non-transactional locker. */
        } else {
            for (int i = 1; i < cursors.length; i += 1) {
                Locker locker2 = cursors[i].getCursorImpl().getLocker();
                if (locker.getTxnLocker() != locker2.getTxnLocker()) {
                    throw new IllegalArgumentException
                            ("All cursors must use the same transaction.");
                }
            }
        }
View Full Code Here

        Tracer.trace(Level.FINEST,
                     envHandle.getEnvironmentImpl(),
                     "Database.truncate: txnId=" +
                     ((txn == null) ? "null" : Long.toString(txn.getId())));

        Locker locker = null;
        boolean triggerLock = false;
        boolean operationOk = false;

        try {
            locker = LockerFactory.getWritableLocker
                (envHandle, txn, isTransactional(), true /*retainLocks*/,
                 null);

            /*
       * Pass true to always get a read lock on the triggers, so we are
       * sure that no secondaries are added during truncation.
       */
            acquireTriggerListReadLock();
            triggerLock = true;

            /* Truncate primary. */
            int count = truncateInternal(locker, countRecords);

            /* Truncate secondaries. */
            for (int i = 0; i < triggerList.size(); i += 1) {
                Object obj = triggerList.get(i);
                if (obj instanceof SecondaryTrigger) {
                    SecondaryDatabase secDb = ((SecondaryTrigger) obj).getDb();
                    secDb.truncateInternal(locker, false);
                }
            }

            operationOk = true;
            return count;
        } finally {
            if (locker != null) {
                locker.operationEnd(operationOk);
            }
            if (triggerLock) {
                releaseTriggerListReadLock();
            }
        }
View Full Code Here

                                                DatabaseEntry pKey,
                                                DatabaseEntry data,
                                                LockMode lockMode)
        throws DatabaseException {

        Locker locker = cursorImpl.getLocker();
        Cursor cursor = null;
        try {
      cursor = new Cursor(primaryDb, locker, null);
            OperationStatus status =
                cursor.search(pKey, data, lockMode, SearchMode.SET);
View Full Code Here

  throws Throwable {

        try {

            initEnv(true);
            Locker txn = new BasicLocker(DbInternal.envGetEnvironmentImpl(env));
            NullCursor cursor = new NullCursor(tree.getDatabase(), txn);

            try {
                byte[][] keys = new byte[N_TOP_LEVEL_KEYS][];
                LN[][] lns = new LN[N_TOP_LEVEL_KEYS][];
                for (int i = 0; i < N_TOP_LEVEL_KEYS; i++) {
                    byte[] key = new byte[N_KEY_BYTES];
                    keys[i] = key;
                    lns[i] = new LN[N_DUPLICATES_PER_KEY];
                    TestUtils.generateRandomAlphaBytes(key);
                    for (int j = 0; j < N_DUPLICATES_PER_KEY; j++) {
                        byte[] data = new byte[N_KEY_BYTES];
                        TestUtils.generateRandomAlphaBytes(data);
                        LN ln = new LN(data);
                        lns[i][j] = ln;
                        insertAndRetrieveDuplicate(key, ln, cursor);
                    }
                }

                for (int i = 0; i < N_TOP_LEVEL_KEYS; i++) {
                    byte[] key = keys[i];
                    for (int j = 0; j < N_DUPLICATES_PER_KEY; j++) {
                        LN ln = lns[i][j];
                        retrieveDuplicateLN(key, ln);
                    }
                }
            } finally {
                txn.operationEnd();
            }
        } catch (Throwable t) {
            t.printStackTrace();
            throw t;
        }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.txn.Locker

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.