Search in sources :

Example 16 with Database

use of com.sleepycat.je.Database in project qpid-broker-j by apache.

the class UpgradeFrom4to5Test method assertQueues.

private void assertQueues(Set<String> expectedQueueNames) {
    List<AMQShortString> durableSubNames = Collections.emptyList();
    final UpgradeFrom4To5.QueueRecordBinding binding = new UpgradeFrom4To5.QueueRecordBinding(durableSubNames);
    final Set<String> actualQueueNames = new HashSet<String>();
    CursorOperation queueNameCollector = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            QueueRecord record = binding.entryToObject(value);
            String queueName = record.getNameShortString().toString();
            actualQueueNames.add(queueName);
        }
    };
    new DatabaseTemplate(_environment, "queueDb_v5", null).run(queueNameCollector);
    assertEquals("Unexpected queue names", expectedQueueNames, actualQueueNames);
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Transaction(com.sleepycat.je.Transaction) QueueRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.QueueRecord) Database(com.sleepycat.je.Database) HashSet(java.util.HashSet)

Example 17 with Database

use of com.sleepycat.je.Database in project qpid-broker-j by apache.

the class UpgradeFrom4to5Test method assertQueueHasOwner.

private void assertQueueHasOwner(String queueName, final String expectedOwner) {
    List<AMQShortString> durableSubNames = Collections.emptyList();
    final UpgradeFrom4To5.QueueRecordBinding binding = new UpgradeFrom4To5.QueueRecordBinding(durableSubNames);
    final AtomicReference<String> actualOwner = new AtomicReference<String>();
    final AtomicBoolean foundQueue = new AtomicBoolean(false);
    CursorOperation queueNameCollector = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            QueueRecord record = binding.entryToObject(value);
            String queueName = record.getNameShortString().toString();
            if (queueName.equals(queueName)) {
                foundQueue.set(true);
                actualOwner.set(AMQShortString.toString(record.getOwner()));
            }
        }
    };
    new DatabaseTemplate(_environment, "queueDb_v5", null).run(queueNameCollector);
    assertTrue("Could not find queue in database", foundQueue.get());
    assertEquals("Queue has unexpected owner", expectedOwner, actualOwner.get());
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AtomicReference(java.util.concurrent.atomic.AtomicReference) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(com.sleepycat.je.Transaction) QueueRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.QueueRecord) Database(com.sleepycat.je.Database)

Example 18 with Database

use of com.sleepycat.je.Database in project qpid-broker-j by apache.

the class UpgradeFrom7To8Test method loadConfiguredObjectHierarchy.

private Map<UpgradeHierarchyKey, UUID> loadConfiguredObjectHierarchy() {
    final Map<UpgradeHierarchyKey, UUID> hierarchyRecords = new HashMap<UpgradeHierarchyKey, UUID>();
    final UpgradeHierarchyKeyBinding hierarchyKeyBinding = new UpgradeHierarchyKeyBinding();
    final UpgradeUUIDBinding uuidParentBinding = new UpgradeUUIDBinding();
    CursorOperation hierarchyCursor = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            UpgradeHierarchyKey hierarchyKey = hierarchyKeyBinding.entryToObject(key);
            UUID parentId = uuidParentBinding.entryToObject(value);
            hierarchyRecords.put(hierarchyKey, parentId);
        }
    };
    new DatabaseTemplate(_environment, CONFIGURED_OBJECT_HIERARCHY_DB_NAME, null).run(hierarchyCursor);
    return hierarchyRecords;
}
Also used : Transaction(com.sleepycat.je.Transaction) HashMap(java.util.HashMap) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID)

Example 19 with Database

use of com.sleepycat.je.Database in project qpid-broker-j by apache.

the class UpgradeFrom5To6 method upgradeQueues.

private List<String> upgradeQueues(Environment environment, Transaction transaction, final String virtualHostName) {
    final List<String> queueNames = new ArrayList<String>();
    LOGGER.info("Queues");
    if (environment.getDatabaseNames().contains(OLD_QUEUE_DB_NAME)) {
        final UpgradeQueueBinding queueBinding = new UpgradeQueueBinding();
        CursorOperation queueCursor = new CursorOperation() {

            @Override
            public void processEntry(Database queueDatabase, Database configuredObjectsDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                OldQueueRecord queueRecord = queueBinding.entryToObject(value);
                String queueName = queueRecord.getNameShortString().toString();
                queueNames.add(queueName);
                String owner = queueRecord.getOwner() == null ? null : queueRecord.getOwner().toString();
                boolean exclusive = queueRecord.isExclusive();
                FieldTable arguments = queueRecord.getArguments();
                UUID queueId = UUIDGenerator.generateQueueUUID(queueName, virtualHostName);
                UpgradeConfiguredObjectRecord configuredObject = createQueueConfiguredObjectRecord(queueName, owner, exclusive, arguments);
                storeConfiguredObjectEntry(configuredObjectsDatabase, queueId, configuredObject, transaction);
            }
        };
        new DatabaseTemplate(environment, OLD_QUEUE_DB_NAME, CONFIGURED_OBJECTS_DB_NAME, transaction).run(queueCursor);
        environment.removeDatabase(transaction, OLD_QUEUE_DB_NAME);
        LOGGER.info(queueCursor.getRowCount() + " Queue Entries");
    }
    return queueNames;
}
Also used : FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) ArrayList(java.util.ArrayList) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) UUID(java.util.UUID)

Example 20 with Database

use of com.sleepycat.je.Database in project qpid-broker-j by apache.

the class UpgradeFrom5To6 method upgradeXidEntries.

private void upgradeXidEntries(Environment environment, Transaction transaction, final String virtualHostName) {
    if (environment.getDatabaseNames().contains(OLD_XID_DB_NAME)) {
        LOGGER.info("Xid Records");
        final OldPreparedTransactionBinding oldTransactionBinding = new OldPreparedTransactionBinding();
        final NewPreparedTransactionBinding newTransactionBinding = new NewPreparedTransactionBinding();
        CursorOperation xidEntriesCursor = new CursorOperation() {

            @Override
            public void processEntry(Database oldXidDatabase, Database newXidDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
                OldPreparedTransaction oldPreparedTransaction = oldTransactionBinding.entryToObject(value);
                OldRecordImpl[] oldDequeues = oldPreparedTransaction.getDequeues();
                OldRecordImpl[] oldEnqueues = oldPreparedTransaction.getEnqueues();
                NewRecordImpl[] newEnqueues = null;
                NewRecordImpl[] newDequeues = null;
                if (oldDequeues != null) {
                    newDequeues = new NewRecordImpl[oldDequeues.length];
                    for (int i = 0; i < newDequeues.length; i++) {
                        OldRecordImpl dequeue = oldDequeues[i];
                        UUID id = UUIDGenerator.generateQueueUUID(dequeue.getQueueName(), virtualHostName);
                        newDequeues[i] = new NewRecordImpl(id, dequeue.getMessageNumber());
                    }
                }
                if (oldEnqueues != null) {
                    newEnqueues = new NewRecordImpl[oldEnqueues.length];
                    for (int i = 0; i < newEnqueues.length; i++) {
                        OldRecordImpl enqueue = oldEnqueues[i];
                        UUID id = UUIDGenerator.generateQueueUUID(enqueue.getQueueName(), virtualHostName);
                        newEnqueues[i] = new NewRecordImpl(id, enqueue.getMessageNumber());
                    }
                }
                NewPreparedTransaction newPreparedTransaction = new NewPreparedTransaction(newEnqueues, newDequeues);
                DatabaseEntry newValue = new DatabaseEntry();
                newTransactionBinding.objectToEntry(newPreparedTransaction, newValue);
                put(newXidDatabase, transaction, key, newValue);
            }
        };
        new DatabaseTemplate(environment, OLD_XID_DB_NAME, NEW_XID_DB_NAME, transaction).run(xidEntriesCursor);
        environment.removeDatabase(transaction, OLD_XID_DB_NAME);
        LOGGER.info(xidEntriesCursor.getRowCount() + " Xid Entries");
    }
}
Also used : DatabaseEntry(com.sleepycat.je.DatabaseEntry) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) UUID(java.util.UUID)

Aggregations

Database (com.sleepycat.je.Database)73 DatabaseEntry (com.sleepycat.je.DatabaseEntry)46 Transaction (com.sleepycat.je.Transaction)35 DatabaseConfig (com.sleepycat.je.DatabaseConfig)27 UUID (java.util.UUID)12 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)11 Environment (com.sleepycat.je.Environment)10 OperationStatus (com.sleepycat.je.OperationStatus)8 Cursor (com.sleepycat.je.Cursor)7 HashSet (java.util.HashSet)7 StoreException (org.apache.qpid.server.store.StoreException)7 HashMap (java.util.HashMap)6 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)5 NewPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction)5 OldPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction)5 Test (org.junit.Test)5 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)4