Package com.sleepycat.je

Examples of com.sleepycat.je.Database


                                                             RoutingStrategy strategy) {
        synchronized(lock) {
            try {
                String storeName = storeDef.getName();
                Environment environment = getEnvironment(storeDef);
                Database db = environment.openDatabase(null, storeName, databaseConfig);
                BdbRuntimeConfig runtimeConfig = new BdbRuntimeConfig(voldemortConfig);
                BdbStorageEngine engine = null;
                if(voldemortConfig.getBdbPrefixKeysWithPartitionId()) {
                    engine = new PartitionPrefixedBdbStorageEngine(storeName,
                                                                   environment,
View Full Code Here


      operations[i] = new Operation()
      {
        @Override
        public void execute(Environment env, Transaction transaction)
        {
          Database database = env.openDatabase(transaction, operation.getDatabaseName(), new DatabaseConfig().setTransactional(true));
          try
          {
            operation.execute(database);
          }
          finally
          {
            database.close();
          }
        }
      };
    }
    this.execute(operations);
View Full Code Here

    Query<T> query = new Query<T>()
    {
      @Override
      public T execute(Environment env)
      {
        Database database = env.openDatabase(null, dbQuery.getDatabaseName(), new DatabaseConfig().setReadOnly(true));
        try
        {
          return dbQuery.execute(database);
        }
        finally
        {
          database.close();
        }
      }
    };
    return this.execute(query);
  }
View Full Code Here

      File location = verifyOrCreateEnvironmentDirectory(new File(cfg.getLocation()));
      try {
         env = factory.createEnvironment(location, cfg.readEnvironmentProperties());
         cacheDb = factory.createDatabase(env, cfg.getCacheDbName());
         Database catalogDb = factory.createDatabase(env, cfg.getCatalogDbName());
         expiryDb = factory.createDatabase(env, cfg.getExpiryDbName());
         catalog = factory.createStoredClassCatalog(catalogDb);
         cacheMap = factory.createStoredMapViewOfDatabase(cacheDb, catalog, marshaller);
         expiryMap = factory.createStoredSortedMapForKeyExpiry(expiryDb, catalog, marshaller);
      } catch (DatabaseException e) {
View Full Code Here

    {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);
        int storeVersion = -1;
        Database versionDb = null;
        Cursor cursor = null;
        try
        {
            versionDb = environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
            cursor = versionDb.openCursor(null, null);
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();
            while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
            {
                int version = IntegerBinding.entryToInt(key);
                if (storeVersion < version)
                {
                    storeVersion = version;
                }
            }
        }
        finally
        {
            if (cursor != null)
            {
                cursor.close();
            }
            if (versionDb != null)
            {
                versionDb.close();
            }
        }
        return storeVersion;
    }
View Full Code Here

    {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);
        int storeVersion = -1;
        Database versionDb = null;
        Cursor cursor = null;
        try
        {
            versionDb = _environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
            cursor = versionDb.openCursor(null, null);
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();
            while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
            {
                int version = IntegerBinding.entryToInt(key);
                if (storeVersion < version)
                {
                    storeVersion = version;
                }
            }
        }
        finally
        {
            if (cursor != null)
            {
                cursor.close();
            }
            if (versionDb != null)
            {
                versionDb.close();
            }
        }
        return storeVersion;
    }
View Full Code Here

     *
     * @see org.jresearch.gossip.dao.file.IFileProcessor#saveFileData(byte[],
     *      java.lang.String)
     */
    public void saveFileData(byte[] data, String key) throws SystemException {
        Database db = null;
        try {
            db = getFileDB();
            DatabaseEntry theKey = new DatabaseEntry(key.getBytes("UTF-8"));
            DatabaseEntry theData = new DatabaseEntry(data);
            db.put(null, theKey, theData);
        } catch (UnsupportedEncodingException e) {
            throw new SystemException(e);
        } catch (DatabaseException e) {
            throw new SystemException(e);
        } finally {
            if (db != null) {
                try {
                    db.close();
                } catch (DatabaseException e) {
                    throw new SystemException(e);
                }
            }
        }
View Full Code Here

     * (non-Javadoc)
     *
     * @see org.jresearch.gossip.dao.file.IFileProcessor#getFileData(java.lang.String)
     */
    public byte[] getFileData(String key) throws SystemException {
        Database db = null;
        try {
            db = getFileDB();
            DatabaseEntry theKey = new DatabaseEntry(key.getBytes("UTF-8"));
            DatabaseEntry theData = new DatabaseEntry();
            if (db.get(null, theKey, theData, LockMode.DEFAULT) == OperationStatus.SUCCESS) { return theData
                    .getData(); }
            return null;
        } catch (UnsupportedEncodingException e) {
            throw new SystemException(e);
        } catch (DatabaseException e) {
            throw new SystemException(e);
        } finally {
            if (db != null) {
                try {
                    db.close();
                } catch (DatabaseException e) {
                    throw new SystemException(e);
                }
            }
        }
View Full Code Here

     * (non-Javadoc)
     *
     * @see org.jresearch.gossip.dao.file.IFileProcessor#removeFileData(java.lang.String)
     */
    public void removeFileData(String key) throws SystemException {
        Database db = null;
        try {
            db = getFileDB();
            DatabaseEntry theKey = new DatabaseEntry(key.getBytes("UTF-8"));
            db.delete(null, theKey);
        } catch (UnsupportedEncodingException e) {
            throw new SystemException(e);
        } catch (DatabaseException e) {
            throw new SystemException(e);
        } finally {
            if (db != null) {
                try {
                    db.close();
                } catch (DatabaseException e) {
                    throw new SystemException(e);
                }
            }
        }
View Full Code Here


        //Migrate _messageMetaDataDb;
        _logger.info("Message MetaData");
       
        final Database newMetaDataDB = _newMessageStore.getMetaDataDb();
        final TupleBinding<Object> oldMetaDataTupleBinding = _oldMessageStore.getMetaDataTupleBindingFactory().getInstance();
        final TupleBinding<Object> newMetaDataTupleBinding = _newMessageStore.getMetaDataTupleBindingFactory().getInstance();
       
        DatabaseVisitor metaDataVisitor = new DatabaseVisitor()
        {
            public void visit(DatabaseEntry key, DatabaseEntry value) throws DatabaseException
            {
                _count++;
                MessageMetaData metaData = (MessageMetaData) oldMetaDataTupleBinding.entryToObject(value);

                // get message id
                Long messageId = TupleBinding.getPrimitiveBinding(Long.class).entryToObject(key);

                // ONLY copy data if message is delivered to existing queue
                if (!queueMessages.contains(messageId))
                {
                    return;
                }
                DatabaseEntry newValue = new DatabaseEntry();
                newMetaDataTupleBinding.objectToEntry(metaData, newValue);
               
                newMetaDataDB.put(null, key, newValue);
            }
        };
        _oldMessageStore.visitMetaDataDb(metaDataVisitor);

        logCount(metaDataVisitor.getVisitedCount(), "Message MetaData");


        //Migrate _messageContentDb;
        _logger.info("Message Contents");
        final Database newContentDB = _newMessageStore.getContentDb();
       
        final TupleBinding<MessageContentKey> oldContentKeyTupleBinding = new MessageContentKeyTB_4();
        final TupleBinding<MessageContentKey> newContentKeyTupleBinding = new MessageContentKeyTB_5();
        final TupleBinding contentTB = new ContentTB();
       
        DatabaseVisitor contentVisitor = new DatabaseVisitor()
        {
            long _prevMsgId = -1; //Initialise to invalid value
            int _bytesSeenSoFar = 0;
           
            public void visit(DatabaseEntry key, DatabaseEntry value) throws DatabaseException
            {
                _count++;

                //determine the msgId of the current entry
                MessageContentKey_4 contentKey = (MessageContentKey_4) oldContentKeyTupleBinding.entryToObject(key);
                long msgId = contentKey.getMessageId();

                // ONLY copy data if message is delivered to existing queue
                if (!queueMessages.contains(msgId))
                {
                    return;
                }
                //if this is a new message, restart the byte offset count.
                if(_prevMsgId != msgId)
                {
                    _bytesSeenSoFar = 0;
                }

                //determine the content size
                ByteBuffer content = (ByteBuffer) contentTB.entryToObject(value);
                int contentSize = content.limit();

                //create the new key: id + previously seen data count
                MessageContentKey_5 newKey = new MessageContentKey_5(msgId, _bytesSeenSoFar);
                DatabaseEntry newKeyEntry = new DatabaseEntry();
                newContentKeyTupleBinding.objectToEntry(newKey, newKeyEntry);

                DatabaseEntry newValueEntry = new DatabaseEntry();
                contentTB.objectToEntry(content, newValueEntry);

                newContentDB.put(null, newKeyEntry, newValueEntry);

                _prevMsgId = msgId;
                _bytesSeenSoFar += contentSize;
            }
        };
        _oldMessageStore.visitContentDb(contentVisitor);

        logCount(contentVisitor.getVisitedCount(), "Message Content");


        //Migrate _deliveryDb;
        _logger.info("Delivery Records");
        final Database deliveryDb =_newMessageStore.getDeliveryDb();
        DatabaseVisitor deliveryDbVisitor = new DatabaseVisitor()
        {

            public void visit(DatabaseEntry key, DatabaseEntry value) throws DatabaseException
            {
                _count++;

                // get message id from entry key
                QueueEntryKey entryKey = (QueueEntryKey) queueEntryTB.entryToObject(key);
                AMQShortString queueName = entryKey.getQueueName();

                // ONLY copy data if message queue exists
                if (existingQueues.contains(queueName))
                {
                    deliveryDb.put(null, key, value);
                }
            }
        };
        _oldMessageStore.visitDelivery(deliveryDbVisitor);
        logCount(contentVisitor.getVisitedCount(), "Delivery Record");
View Full Code Here

TOP

Related Classes of com.sleepycat.je.Database

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.