Search in sources :

Example 1 with LinkDefinitionImpl

use of org.apache.qpid.server.protocol.v1_0.LinkDefinitionImpl 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 LinkDefinitionImpl

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

the class JDBCLinkStore method getLinks.

private Collection<LinkDefinition<Source, Target>> getLinks() throws SQLException {
    Collection<LinkDefinition<Source, Target>> links = new ArrayList<>();
    try (Connection connection = getConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(String.format("SELECT remote_container_id, link_name, link_role, source, target FROM %s", getLinksTableName()))) {
        while (resultSet.next()) {
            String remoteContainerId = getBlobValueAsString(resultSet, 1);
            String linkName = getBlobValueAsString(resultSet, 2);
            Role role = Role.valueOf(resultSet.getBoolean(3));
            Source source = (Source) getBlobAsAmqpObject(resultSet, 4);
            Target target = (Target) getBlobAsAmqpObject(resultSet, 5);
            links.add(new LinkDefinitionImpl<>(remoteContainerId, linkName, role, source, target));
        }
    } catch (IllegalArgumentException e) {
        throw new StoreException("Cannot load links from store", e);
    }
    return links;
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) StoreException(org.apache.qpid.server.store.StoreException) Role(org.apache.qpid.server.protocol.v1_0.type.transport.Role) LinkDefinition(org.apache.qpid.server.protocol.v1_0.LinkDefinition) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget) ResultSet(java.sql.ResultSet)

Aggregations

LinkDefinition (org.apache.qpid.server.protocol.v1_0.LinkDefinition)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 StoreException (org.apache.qpid.server.store.StoreException)2 Cursor (com.sleepycat.je.Cursor)1 Database (com.sleepycat.je.Database)1 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 DatabaseNotFoundException (com.sleepycat.je.DatabaseNotFoundException)1 Transaction (com.sleepycat.je.Transaction)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ModelVersion (org.apache.qpid.server.model.ModelVersion)1 LinkDefinitionImpl (org.apache.qpid.server.protocol.v1_0.LinkDefinitionImpl)1 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)1 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)1 BaseTarget (org.apache.qpid.server.protocol.v1_0.type.BaseTarget)1