Package com.sleepycat.je

Examples of com.sleepycat.je.Transaction


             *
             * Use a no-wait transaction to avoid blocking on a Replica while
             * attempting to open an index that is currently being populated
             * via the replication stream from the Master.
             */
            Transaction txn = null;
            DatabaseConfig dbConfig = getPrimaryConfig(entityMeta);
            if (dbConfig.getTransactional() &&
                DbCompat.getThreadTransaction(env) == null) {
                txn = env.beginTransaction(null, autoCommitNoWaitTxnConfig);
            }
            PrimaryOpenState priOpenState =
                new PrimaryOpenState(entityClassName);
            final boolean saveAllowCreate = dbConfig.getAllowCreate();
            boolean success = false;
            try {

                /*
                 * The AllowCreate setting is false in read-only / Replica
                 * upgrade mode. In this mode new primaries are not available.
                 * They can be opened later when the upgrade is complete on the
                 * Master, by calling getSecondaryIndex.  [#16655]
                 */
                if (catalog.isReadOnly()) {
                    dbConfig.setAllowCreate(false);
                }

                /*
                 * Open the primary database.  Account for database renaming
                 * by calling getDatabaseClassName.  The dbClassName will be
                 * null if the format has not yet been stored. [#16655].
                 */
                Database db = null;
                final String dbClassName =
                    catalog.getDatabaseClassName(entityClassName);
                if (dbClassName != null) {
                    final String[] fileAndDbNames =
                        parseDbName(storePrefix + dbClassName);
                    /* <!-- begin JE only --> */
                    try {
                    /* <!-- end JE only --> */
                        db = DbCompat.openDatabase(env, txn, fileAndDbNames[0],
                                                   fileAndDbNames[1],
                                                   dbConfig);
                    /* <!-- begin JE only --> */
                    } catch (LockConflictException e) {
                        /* Treat this as if the database does not exist. */
                    }
                    /* <!-- end JE only --> */
                }
                if (db == null) {
                    throw new IndexNotAvailableException
                        ("PrimaryIndex not yet available on this Replica, " +
                         "entity class: " + entityClassName);
                }

                priOpenState.addDatabase(db);

                /* Create index object. */
                priIndex = new InternalPrimaryIndex(db, primaryKeyClass,
                                                    keyBinding, entityClass,
                                                    entityBinding);

                /* Update index and database maps. */
                priIndexMap.put(entityClassName, priIndex);
                if (DbCompat.getDeferredWrite(dbConfig)) {
                    deferredWriteDatabases.put(db, null);
                }

                /* If not read-only, open all associated secondaries. */
                if (!dbConfig.getReadOnly()) {
                    openSecondaryIndexes(txn, entityMeta, priOpenState);

                    /*
                     * To enable foreign key contraints, also open all primary
                     * indexes referring to this class via a relatedEntity
                     * property in another entity. [#15358]
                     */
                    Set<String> inverseClassNames =
                        inverseRelatedEntityMap.get(entityClassName);
                    if (inverseClassNames != null) {
                        for (String relatedClsName : inverseClassNames) {
                            getRelatedIndex(relatedClsName);
                        }
                    }
                }
                success = true;
            } finally {
                dbConfig.setAllowCreate(saveAllowCreate);
                if (success) {
                    if (txn != null) {
                        txn.commit();
                    }
                } else {
                    if (txn != null) {
                        txn.abort();
                    }
                    priOpenState.undoState();
                }
            }
        }
View Full Code Here


                /*
                 * Use a no-wait transaction to avoid blocking on a Replica
                 * while attempting to open an index that is currently being
                 * populated via the replication stream from the Master.
                 */
                Transaction txn = null;
                if (getPrimaryConfig(entityMeta).getTransactional() &&
                    DbCompat.getThreadTransaction(env) == null) {
                    txn = env.beginTransaction(null,
                                               autoCommitNoWaitTxnConfig);
                }
                boolean success = false;
                try {

                    /*
                     * The doNotCreate param is true below in read-only /
                     * Replica upgrade mode. In this mode new secondaries are
                     * not available.  They can be opened later when the
                     * upgrade is complete on the Master, by calling
                     * getSecondaryIndex.  [#16655]
                     */
                    secIndex = openSecondaryIndex
                        (txn, primaryIndex, entityClass, entityMeta,
                         keyClass, keyClassName, secKeyMeta, secName,
                         makeSecName(dbClassName, dbKeyName),
                         catalog.isReadOnly() /*doNotCreate*/,
                         null /*priOpenState*/);
                    success = true;
                /* <!-- begin JE only --> */
                } catch (LockConflictException e) {
                    /* Treat this as if the database does not exist. */
                /* <!-- end JE only --> */
                } finally {
                    if (success) {
                        if (txn != null) {
                            txn.commit();
                        }
                    } else {
                        if (txn != null) {
                            txn.abort();
                        }
                    }
                }
            }
            if (secIndex == null) {
View Full Code Here

        EntityBinding binding = index.getEntityBinding();
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry data = new DatabaseEntry();

        CursorConfig cursorConfig = null;
        Transaction txn = null;
        if (dbConfig.getTransactional()) {
            txn = env.beginTransaction(null, autoCommitTxnConfig);
            cursorConfig = CursorConfig.READ_COMMITTED;
        }

        Cursor cursor = null;
        int nWritten = 0;
        try {
            cursor = db.openCursor(txn, cursorConfig);
            OperationStatus status = cursor.getFirst(key, data, null);
            while (status == OperationStatus.SUCCESS) {
                boolean oneWritten = false;
                if (evolveNeeded(key, data, binding)) {
                    cursor.putCurrent(data);
                    oneWritten = true;
                    nWritten += 1;
                }
                /* Update event stats, even if no listener. [#17024] */
                EvolveInternal.updateEvent
                    (event, entityClassName, 1, oneWritten ? 1 : 0);
                if (listener != null) {
                    if (!listener.evolveProgress(event)) {
                        break;
                    }
                }
                if (txn != null && nWritten >= WRITES_PER_TXN) {
                    cursor.close();
                    cursor = null;
                    txn.commit();
                    txn = null;
                    txn = env.beginTransaction(null, autoCommitTxnConfig);
                    cursor = db.openCursor(txn, cursorConfig);
                    DatabaseEntry saveKey = KeyRange.copy(key);
                    status = cursor.getSearchKeyRange(key, data, null);
                    if (status == OperationStatus.SUCCESS &&
                        KeyRange.equalBytes(key, saveKey)) {
                        status = cursor.getNext(key, data, null);
                    }
                } else {
                    status = cursor.getNext(key, data, null);
                }
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (txn != null) {
                if (nWritten > 0) {
                    txn.commit();
                } else {
                    txn.abort();
                }
            }
        }
    }
View Full Code Here

    @Override
    public void truncate() {

        if(isTruncating.compareAndSet(false, true)) {
            Transaction transaction = null;
            boolean succeeded = false;

            try {
                transaction = this.environment.beginTransaction(null, null);
View Full Code Here

        StoreUtils.assertValidKey(key);
        DatabaseEntry keyEntry = new DatabaseEntry(key.get());
        DatabaseEntry valueEntry = new DatabaseEntry();

        boolean succeeded = false;
        Transaction transaction = null;
        List<Versioned<byte[]>> vals = null;

        try {
            transaction = environment.beginTransaction(null, null);
View Full Code Here

        long startTimeNs = -1;

        if(logger.isTraceEnabled())
            startTimeNs = System.nanoTime();

        Transaction transaction = null;
        try {
            transaction = this.environment.beginTransaction(null, null);
            DatabaseEntry keyEntry = new DatabaseEntry(key.get());

            if(version == null) {
View Full Code Here

        StoreUtils.assertValidKey(key);
        DatabaseEntry keyEntry = new DatabaseEntry(key.get());
        DatabaseEntry valueEntry = new DatabaseEntry();

        Transaction transaction = null;
        List<Versioned<byte[]>> vals = null;
        KeyLockHandle<byte[]> handle;

        try {
            transaction = environment.beginTransaction(null, null);
View Full Code Here

        StoreUtils.assertValidKey(key);
        DatabaseEntry keyEntry = new DatabaseEntry(key.get());
        DatabaseEntry valueEntry = new DatabaseEntry();

        boolean succeeded = false;
        Transaction transaction = null;

        try {
            transaction = (Transaction) handle.getKeyLock();
            valueEntry.setData(StoreBinaryFormat.toByteArray(handle.getValues()));
            OperationStatus status = getBdbDatabase().put(transaction, keyEntry, valueEntry);
View Full Code Here

        }
    }

    @Override
    public void releaseLock(KeyLockHandle<byte[]> handle) {
        Transaction transaction = (Transaction) handle.getKeyLock();
        if(transaction != null) {
            attemptAbort(transaction);
        }
        handle.close();
    }
View Full Code Here

  private void execute(Operation... operations)
  {
    Environment env = this.pool.take();
    try
    {
      Transaction transaction = env.beginTransaction(null, null);
      try
      {
        for (Operation operation: operations)
        {
          operation.execute(env, transaction);
        }
        transaction.commit();
      }
      catch (RuntimeException e)
      {
        transaction.abort();
        throw e;
      }
    }
    finally
    {
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.