Search in sources :

Example 1 with LinkDefinition

use of org.apache.qpid.server.protocol.v1_0.LinkDefinition in project qpid-broker-j by apache.

the class BDBLinkStore method getLinkDefinitions.

private Collection<LinkDefinition<Source, Target>> getLinkDefinitions(final LinkStoreUpdater updater) {
    Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
    Collection<LinkDefinition<Source, Target>> links = new HashSet<>();
    ModelVersion currentVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION, BrokerModel.MODEL_MINOR_VERSION);
    ModelVersion storedVersion = getStoredVersion();
    if (currentVersion.lessThan(storedVersion)) {
        throw new StoreException(String.format("Cannot downgrade preference store from '%s' to '%s'", storedVersion, currentVersion));
    }
    try (Cursor cursor = linksDatabase.openCursor(null, null)) {
        final DatabaseEntry key = new DatabaseEntry();
        final DatabaseEntry value = new DatabaseEntry();
        LinkKeyEntryBinding keyEntryBinding = LinkKeyEntryBinding.getInstance();
        LinkValueEntryBinding linkValueEntryBinding = LinkValueEntryBinding.getInstance();
        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
            LinkKey linkKey = keyEntryBinding.entryToObject(key);
            LinkValue linkValue = linkValueEntryBinding.entryToObject(value);
            LinkDefinition<Source, Target> link = new LinkDefinitionImpl<>(linkKey.getRemoteContainerId(), linkKey.getLinkName(), linkKey.getRole(), linkValue.getSource(), linkValue.getTarget());
            links.add(link);
        }
    }
    if (storedVersion.lessThan(currentVersion)) {
        links = updater.update(storedVersion.toString(), links);
        final Transaction txn = getEnvironmentFacade().beginTransaction(null);
        try {
            linksDatabase = getEnvironmentFacade().clearDatabase(txn, LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
            for (LinkDefinition<Source, Target> link : links) {
                save(linksDatabase, txn, link);
            }
            updateVersion(txn, currentVersion.toString());
            txn.commit();
            linksDatabase.close();
        } catch (Exception e) {
            txn.abort();
            throw e;
        }
    }
    return links;
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) StoreException(org.apache.qpid.server.store.StoreException) DatabaseNotFoundException(com.sleepycat.je.DatabaseNotFoundException) StoreException(org.apache.qpid.server.store.StoreException) LinkDefinition(org.apache.qpid.server.protocol.v1_0.LinkDefinition) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) LinkDefinitionImpl(org.apache.qpid.server.protocol.v1_0.LinkDefinitionImpl) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) ModelVersion(org.apache.qpid.server.model.ModelVersion) HashSet(java.util.HashSet)

Example 2 with LinkDefinition

use of org.apache.qpid.server.protocol.v1_0.LinkDefinition in project qpid-broker-j by apache.

the class BDBLinkStore method doSaveLink.

@Override
protected void doSaveLink(final LinkDefinition<Source, Target> link) {
    try {
        Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
        save(linksDatabase, null, link);
    } catch (RuntimeException e) {
        throw getEnvironmentFacade().handleDatabaseException(String.format("Failed saving of link '%s'", new LinkKey(link)), e);
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) Database(com.sleepycat.je.Database)

Example 3 with LinkDefinition

use of org.apache.qpid.server.protocol.v1_0.LinkDefinition in project qpid-broker-j by apache.

the class BDBLinkStore method doDeleteLink.

@Override
protected void doDeleteLink(final LinkDefinition<Source, Target> linkDefinition) {
    LinkKey linkKey = new LinkKey(linkDefinition);
    try {
        Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
        final DatabaseEntry databaseEntry = new DatabaseEntry();
        LinkKeyEntryBinding.getInstance().objectToEntry(linkKey, databaseEntry);
        OperationStatus status = linksDatabase.delete(null, databaseEntry);
        if (status != OperationStatus.SUCCESS) {
            LOGGER.debug(String.format("Unexpected status '%s' for deletion of '%s'", status, linkKey));
        }
    } catch (RuntimeException e) {
        throw getEnvironmentFacade().handleDatabaseException(String.format("Failed deletion of link '%s'", linkKey), e);
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 4 with LinkDefinition

use of org.apache.qpid.server.protocol.v1_0.LinkDefinition in project qpid-broker-j by apache.

the class JDBCLinkStore method insert.

private void insert(final Connection connection, final String linkKey, final LinkDefinition<? extends BaseSource, ? extends BaseTarget> linkDefinition) throws SQLException {
    try (PreparedStatement statement = connection.prepareStatement(String.format("INSERT INTO %s (link_key, remote_container_id, link_name, link_role, source, target) VALUES (?,?,?,?,?,?)", getLinksTableName()))) {
        statement.setString(1, linkKey);
        saveStringAsBlob(statement, 2, linkDefinition.getRemoteContainerId());
        saveStringAsBlob(statement, 3, linkDefinition.getName());
        statement.setInt(4, linkDefinition.getRole().getValue() ? 1 : 0);
        saveObjectAsBlob(statement, 5, linkDefinition.getSource());
        saveObjectAsBlob(statement, 6, linkDefinition.getTarget());
        if (statement.executeUpdate() != 1) {
            throw new StoreException(String.format("Cannot save link %s", new LinkKey(linkDefinition)));
        }
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) PreparedStatement(java.sql.PreparedStatement) StoreException(org.apache.qpid.server.store.StoreException)

Example 5 with LinkDefinition

use of org.apache.qpid.server.protocol.v1_0.LinkDefinition in project qpid-broker-j by apache.

the class LinkRegistryImpl method open.

@Override
public void open() {
    Collection<LinkDefinition<Source, Target>> links = _linkStore.openAndLoad(new LinkStoreUpdaterImpl());
    for (LinkDefinition<? extends BaseSource, ? extends BaseTarget> link : links) {
        ConcurrentMap<LinkKey, Link_1_0<? extends BaseSource, ? extends BaseTarget>> linkRegistry = getLinkRegistry(link.getRole());
        linkRegistry.put(new LinkKey(link), new LinkImpl<>(link, this));
    }
}
Also used : LinkStoreUpdaterImpl(org.apache.qpid.server.protocol.v1_0.store.LinkStoreUpdaterImpl) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget)

Aggregations

LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)8 StoreException (org.apache.qpid.server.store.StoreException)8 PreparedStatement (java.sql.PreparedStatement)5 Database (com.sleepycat.je.Database)3 DatabaseEntry (com.sleepycat.je.DatabaseEntry)3 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 LinkDefinition (org.apache.qpid.server.protocol.v1_0.LinkDefinition)3 OperationStatus (com.sleepycat.je.OperationStatus)2 ResultSet (java.sql.ResultSet)2 ModelVersion (org.apache.qpid.server.model.ModelVersion)2 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)2 BaseTarget (org.apache.qpid.server.protocol.v1_0.type.BaseTarget)2 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)2 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)2 Cursor (com.sleepycat.je.Cursor)1 DatabaseNotFoundException (com.sleepycat.je.DatabaseNotFoundException)1 Transaction (com.sleepycat.je.Transaction)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1