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);
}
}
}
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);
}
}
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));
}
}
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);
}
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;
}
Aggregations