Search in sources :

Example 6 with LinkKey

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

the class BDBLinkStore method save.

private void save(Database database, Transaction txn, final LinkDefinition<Source, Target> link) {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    LinkKey linkKey = new LinkKey(link);
    LinkKeyEntryBinding.getInstance().objectToEntry(linkKey, key);
    LinkValueEntryBinding.getInstance().objectToEntry(new LinkValue(link), value);
    // TODO: create transaction
    OperationStatus status = database.put(txn, key, value);
    if (status != OperationStatus.SUCCESS) {
        throw new StoreException(String.format("Cannot save link %s", linkKey));
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 7 with LinkKey

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

the class LinkKeyEntryBinding method entryToObject.

@Override
public LinkKey entryToObject(final TupleInput input) {
    String remoteContainerId = input.readString();
    String linkName = input.readString();
    Role role = null;
    try {
        role = Role.valueOf(input.readBoolean());
    } catch (IllegalArgumentException e) {
        throw new StoreException("Cannot load link from store", e);
    }
    final String remoteContainerId1 = remoteContainerId;
    final String linkName1 = linkName;
    final Role role1 = role;
    return new LinkKey(remoteContainerId1, linkName1, role1);
}
Also used : Role(org.apache.qpid.server.protocol.v1_0.type.transport.Role) LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) StoreException(org.apache.qpid.server.store.StoreException)

Example 8 with LinkKey

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

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

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

LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)9 StoreException (org.apache.qpid.server.store.StoreException)7 PreparedStatement (java.sql.PreparedStatement)4 Database (com.sleepycat.je.Database)3 DatabaseEntry (com.sleepycat.je.DatabaseEntry)3 OperationStatus (com.sleepycat.je.OperationStatus)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Cursor (com.sleepycat.je.Cursor)1 DatabaseNotFoundException (com.sleepycat.je.DatabaseNotFoundException)1 Transaction (com.sleepycat.je.Transaction)1 ResultSet (java.sql.ResultSet)1 HashSet (java.util.HashSet)1 ModelVersion (org.apache.qpid.server.model.ModelVersion)1 LinkDefinition (org.apache.qpid.server.protocol.v1_0.LinkDefinition)1 LinkDefinitionImpl (org.apache.qpid.server.protocol.v1_0.LinkDefinitionImpl)1 LinkStoreUpdaterImpl (org.apache.qpid.server.protocol.v1_0.store.LinkStoreUpdaterImpl)1 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)1 BaseTarget (org.apache.qpid.server.protocol.v1_0.type.BaseTarget)1 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)1