Search in sources :

Example 26 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source 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)

Example 27 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.

the class JDBCLinkStore method doSaveLink.

@Override
protected void doSaveLink(final LinkDefinition<Source, Target> link) throws StoreException {
    String linkKey = generateLinkKey(link);
    Connection connection = getConnection();
    try {
        connection.setAutoCommit(false);
        connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
        try (PreparedStatement preparedStatement = connection.prepareStatement(String.format("SELECT remote_container_id, link_name, link_role, source, target FROM %s WHERE link_key = ?", getLinksTableName()))) {
            preparedStatement.setString(1, linkKey);
            try (ResultSet resultSet = preparedStatement.executeQuery()) {
                if (resultSet.next()) {
                    update(connection, linkKey, link);
                } else {
                    insert(connection, linkKey, link);
                }
            }
        }
        connection.commit();
    } catch (SQLException e) {
        try {
            connection.rollback();
        } catch (SQLException re) {
            LOGGER.debug("Rollback failed on rolling back saving link transaction", re);
        }
        throw new StoreException(String.format("Cannot save link %s", new LinkKey(link)), e);
    } finally {
        JdbcUtils.closeConnection(connection, LOGGER);
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) StoreException(org.apache.qpid.server.store.StoreException)

Example 28 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.

the class JDBCLinkStore method update.

private void update(final Connection connection, final String linkKey, final LinkDefinition<? extends BaseSource, ? extends BaseTarget> linkDefinition) throws SQLException {
    try (PreparedStatement statement = connection.prepareStatement(String.format("UPDATE %s SET source = ?, target = ? WHERE link_key = ?", getLinksTableName()))) {
        saveObjectAsBlob(statement, 1, linkDefinition.getSource());
        saveObjectAsBlob(statement, 2, linkDefinition.getTarget());
        statement.setString(3, linkKey);
        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 29 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.

the class JDBCLinkStore method doOpenAndLoad.

@Override
protected Collection<LinkDefinition<Source, Target>> doOpenAndLoad(final LinkStoreUpdater updater) throws StoreException {
    Collection<LinkDefinition<Source, Target>> linkDefinitions;
    try {
        checkTransactionIsolationLevel();
        createOrOpenStoreDatabase();
        linkDefinitions = getLinks();
        ModelVersion storedVersion = getStoredVersion();
        ModelVersion currentVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION, BrokerModel.MODEL_MINOR_VERSION);
        if (storedVersion.lessThan(currentVersion)) {
            linkDefinitions = performUpdate(updater, linkDefinitions, storedVersion, currentVersion);
        } else if (currentVersion.lessThan(storedVersion)) {
            throw new StoreException(String.format("Cannot downgrade the store from %s to %s", storedVersion, currentVersion));
        }
    } catch (SQLException e) {
        throw new StoreException("Cannot open link store", e);
    }
    return linkDefinitions;
}
Also used : LinkDefinition(org.apache.qpid.server.protocol.v1_0.LinkDefinition) SQLException(java.sql.SQLException) ModelVersion(org.apache.qpid.server.model.ModelVersion) StoreException(org.apache.qpid.server.store.StoreException)

Example 30 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.

the class JDBCLinkStore method doDeleteLink.

@Override
protected void doDeleteLink(final LinkDefinition<Source, Target> link) throws StoreException {
    try (Connection connection = getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(String.format("DELETE FROM %s WHERE link_key = ?", getLinksTableName()))) {
        preparedStatement.setString(1, generateLinkKey(link));
        preparedStatement.execute();
    } catch (SQLException e) {
        throw new StoreException(String.format("Cannot delete link %s", new LinkKey(link)), e);
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) StoreException(org.apache.qpid.server.store.StoreException)

Aggregations

Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)32 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)16 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)15 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)14 Test (org.junit.Test)14 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)13 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)13 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)11 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)10 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)10 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)10 MessageSource (org.apache.qpid.server.message.MessageSource)9 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)8 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)8 StoreException (org.apache.qpid.server.store.StoreException)8 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)7 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)7 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)6 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)6 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)6