Package com.sleepycat.je

Examples of com.sleepycat.je.Transaction


    }

    private void upgradeMessages(final Environment environment, final UpgradeInteractionHandler handler)
            throws AMQStoreException
    {
        Transaction transaction = null;
        try
        {
            transaction = environment.beginTransaction(null, null);
            upgradeMessages(environment, handler, transaction);
            transaction.commit();
        }
        catch (Exception e)
        {
            transaction.abort();
            if (e instanceof DatabaseException)
            {
                throw (DatabaseException) e;
            }
            else if (e instanceof AMQStoreException)
View Full Code Here


                abort();
            }
        };

        Transaction transaction = _environment.beginTransaction(null, null);
        new DatabaseTemplate(_environment, OLD_CONTENT_DB_NAME, transaction).run(cursorOperation);
        transaction.commit();
    }
View Full Code Here

    private void updateConfigVersion(int newConfigVersion) throws AMQStoreException
    {
        Cursor cursor = null;
        try
        {
            Transaction txn = _environment.beginTransaction(null, null);
            cursor = _configVersionDb.openCursor(txn, null);
            DatabaseEntry key = new DatabaseEntry();
            ByteBinding.byteToEntry((byte) 0,key);
            DatabaseEntry value = new DatabaseEntry();

            while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS)
            {
                IntegerBinding.intToEntry(newConfigVersion, value);
                OperationStatus status = cursor.put(key, value);
                if (status != OperationStatus.SUCCESS)
                {
                    throw new AMQStoreException("Error setting config version: " + status);
                }
            }
            cursor.close();
            cursor = null;
            txn.commit();
        }
        finally
        {
            closeCursorSafely(cursor);
        }
View Full Code Here

                cipher.init(Cipher.ENCRYPT_MODE, secretKey);
                eventData = cipher.doFinal(eventData);
            }
            final DatabaseEntry key = new DatabaseEntry(keyData);
            final DatabaseEntry data = new DatabaseEntry(eventData);
            Transaction txn = environment.beginTransaction(null, null);
            try {
                database.put(txn, key, data);
                txn.commit();
                queue.add(keyData);
            } catch (Exception ex) {
                if (txn != null) {
                    txn.abort();
                }
                throw ex;
            }
        } catch (Exception ex) {
            throw new LoggingException("Exception occurred writing log event", ex);
View Full Code Here

                                    LOGGER.error("Error sending events", ioe);
                                    break;
                                }
                                cursor.close();
                                cursor = null;
                                Transaction txn = environment.beginTransaction(null, null);
                                try {
                                    for (Event event : batch.getEvents()) {
                                        try {
                                            Map<String, String> headers = event.getHeaders();
                                            key = new DatabaseEntry(headers.get(FlumeEvent.GUID).getBytes(UTF8));
                                            database.delete(txn, key);
                                        } catch (Exception ex) {
                                            LOGGER.error("Error deleting key from database", ex);
                                        }
                                    }
                                    txn.commit();
                                } catch (Exception ex) {
                                    LOGGER.error("Unable to commit transaction", ex);
                                    if (txn != null) {
                                        txn.abort();
                                    }
                                }
                            } catch (Exception ex) {
                                LOGGER.error("Error reading database", ex);
                                shutdown = true;
                                break;
                            } finally {
                                if (cursor != null) {
                                    cursor.close();
                                }
                            }
                        } else {
                            Transaction txn = environment.beginTransaction(null, null);
                            Cursor cursor = database.openCursor(txn, null);
                            try {
                                status = cursor.getFirst(key, data, LockMode.RMW);
                                while (status == OperationStatus.SUCCESS) {
                                    SimpleEvent event = createEvent(data);
                                    if (event != null) {
                                        try {
                                            manager.doSend(event);
                                        } catch (Exception ioe) {
                                            errors = true;
                                            LOGGER.error("Error sending event", ioe);
                                            break;
                                        }
                                        if (!errors) {
                                            try {
                                                cursor.delete();
                                            } catch (Exception ex) {
                                                LOGGER.error("Unable to delete event", ex);
                                            }
                                        }
                                    }
                                    status = cursor.getNext(key, data, LockMode.RMW);
                                }
                                if (cursor != null) {
                                    cursor.close();
                                    cursor = null;
                                }
                                txn.commit();
                                txn = null;
                            } catch (Exception ex) {
                                LOGGER.error("Error reading or writing to database", ex);
                                shutdown = true;
                                break;
                            } finally {
                                if (cursor != null) {
                                    cursor.close();
                                }
                                if (txn != null) {
                                    txn.abort();
                                }
                            }
                        }
                        if (errors) {
                            Thread.sleep(manager.delay);
View Full Code Here

    */
   protected void prepare(List<? extends Modification> mods, GlobalTransaction tx) throws CacheLoaderException {
      if (trace) log.tracef("preparing transaction %s", tx);
      try {
         transactionRunner.prepare(new ModificationsTransactionWorker(this, mods));
         Transaction txn = currentTransaction.getTransaction();
         if (trace) log.tracef("transaction %s == sleepycat transaction %s", tx, txn);
         txnMap.put(tx, txn);
         ReflectionUtil.setValue(currentTransaction, "localTrans", new ThreadLocal());
      } catch (Exception e) {
         throw convertToCacheLoaderException("Problem preparing transaction", e);
View Full Code Here

    * @param tx     java transaction used to lookup a SleepyCat transaction
    * @param commit true to commit false to abort
    * @throws CacheLoaderException if there are problems committing or aborting the transaction
    */
   protected void completeTransaction(GlobalTransaction tx, boolean commit) throws CacheLoaderException {
      Transaction txn = txnMap.remove(tx);
      if (txn != null) {
         if (trace) log.tracef("%s sleepycat transaction %s", commit ? "committing" : "aborting", txn);
         try {
            if (commit)
               txn.commit();
            else
               txn.abort();
         } catch (Exception caught) {
            throw convertToCacheLoaderException("Problem completing transaction", caught);
         }
      } else {
         if (trace) log.tracef("no sleepycat transaction associated  transaction %s", tx);
View Full Code Here

        throws ResourceException {

        checkEnv("begin");
        long id = -1;
        try {
            Transaction txn = env.beginTransaction(null, transConfig);
            env.setThreadTransaction(txn);
            id = txn.getId();
        } catch (DatabaseException DE) {
            throw new ResourceException("During begin: " + DE.toString());
        }

        ConnectionEvent connEvent = new ConnectionEvent
View Full Code Here

        EnvironmentImpl envImpl = DbInternal.getEnvironmentImpl(env);
        boolean envIsTransactional = envImpl.isTransactional();

        if (userTxn == null) {
            Transaction xaLocker = env.getThreadTransaction();
            if (xaLocker != null) {
                return DbInternal.getLocker(xaLocker);
            }
        }
View Full Code Here

        throws DatabaseException {

        EnvironmentImpl envImpl = DbInternal.getEnvironmentImpl(env);

        if (locker == null) {
            Transaction xaTxn = env.getThreadTransaction();
            if (xaTxn != null) {
                return DbInternal.getLocker(xaTxn);
            }
        }
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.