Search in sources :

Example 51 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class AbstractJDBCPreferenceStore method performSafeTransaction.

private void performSafeTransaction(final BaseAction<Connection, Exception> transactedAction) {
    Connection connection = null;
    try {
        connection = getTransactedConnection();
        transactedAction.performAction(connection);
        connection.commit();
    } catch (Exception e) {
        try {
            if (connection != null) {
                connection.rollback();
            }
        } catch (SQLException e1) {
            getLogger().error("Failed to rollback transaction", e1);
        }
        throw new StoreException(e);
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            getLogger().warn("Failed to close JDBC connection", e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) SQLException(java.sql.SQLException) StoreException(org.apache.qpid.server.store.StoreException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StoreException(org.apache.qpid.server.store.StoreException)

Example 52 with StoreException

use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.

the class JdbcUtils method createConnectionProvider.

static ConnectionProvider createConnectionProvider(final ConfiguredObject<?> parent, final Logger logger) {
    JDBCSettings settings = (JDBCSettings) parent;
    String connectionPoolType = settings.getConnectionPoolType() == null ? DefaultConnectionProviderFactory.TYPE : settings.getConnectionPoolType();
    JDBCConnectionProviderFactory connectionProviderFactory = JDBCConnectionProviderFactory.FACTORIES.get(connectionPoolType);
    if (connectionProviderFactory == null) {
        logger.warn("Unknown connection pool type: {}.  No connection pooling will be used", connectionPoolType);
        connectionProviderFactory = new DefaultConnectionProviderFactory();
    }
    try {
        Map<String, String> providerAttributes = new HashMap<>();
        Set<String> providerAttributeNames = new HashSet<>(connectionProviderFactory.getProviderAttributeNames());
        providerAttributeNames.retainAll(parent.getContextKeys(false));
        for (String attr : providerAttributeNames) {
            providerAttributes.put(attr, parent.getContextValue(String.class, attr));
        }
        return connectionProviderFactory.getConnectionProvider(settings.getConnectionUrl(), settings.getUsername(), settings.getPassword(), providerAttributes);
    } catch (SQLException e) {
        throw new StoreException(String.format("Failed to create connection provider for connectionUrl: '%s' and username: '%s'", settings.getConnectionUrl(), settings.getUsername()), e);
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) HashSet(java.util.HashSet) StoreException(org.apache.qpid.server.store.StoreException)

Example 53 with StoreException

use of org.apache.qpid.server.store.StoreException 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 54 with StoreException

use of org.apache.qpid.server.store.StoreException 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 55 with StoreException

use of org.apache.qpid.server.store.StoreException 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

StoreException (org.apache.qpid.server.store.StoreException)70 SQLException (java.sql.SQLException)28 Connection (java.sql.Connection)23 PreparedStatement (java.sql.PreparedStatement)21 DatabaseEntry (com.sleepycat.je.DatabaseEntry)20 IOException (java.io.IOException)18 OperationStatus (com.sleepycat.je.OperationStatus)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 ResultSet (java.sql.ResultSet)10 UUID (java.util.UUID)8 Database (com.sleepycat.je.Database)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ModelVersion (org.apache.qpid.server.model.ModelVersion)7 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)7 HashSet (java.util.HashSet)5 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 Cursor (com.sleepycat.je.Cursor)4 DatabaseConfig (com.sleepycat.je.DatabaseConfig)4