@Override public SubscriptionInfo[] getAllSubscriptions() throws IOException { TransactionContext c = persistenceAdapter.getTransactionContext(); try { return adapter.doGetAllSubscriptions(c, destination); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to lookup subscriptions. Reason: " + e, e); } finally { c.close(); } }
private Object loadAdapter(FactoryFinder finder, String kind) throws IOException { Object adapter = null; TransactionContext c = getTransactionContext(); try { try { // Make the filename file system safe. String dirverName = c.getConnection().getMetaData().getDriverName(); dirverName = dirverName.replaceAll("[^a-zA-Z0-9\\-]", "_").toLowerCase(Locale.ENGLISH); try { adapter = finder.newInstance(dirverName); LOG.info("Database " + kind + " driver override recognized for : [" + dirverName + "] - adapter: " + adapter.getClass()); } catch (Throwable e) { LOG.info("Database " + kind + " driver override not found for : [" + dirverName + "]. Will use default implementation."); } } catch (SQLException e) { LOG.warn("JDBC error occurred while trying to detect database type for overrides. Will use default implementations: " + e.getMessage()); JDBCPersistenceAdapter.log("Failure Details: ", e); } } finally { c.close(); } return adapter; }
public void initSequenceIdGenerator() { TransactionContext c = null; try { c = getTransactionContext(); getAdapter().doMessageIdScan(c, auditRecoveryDepth, new JDBCMessageIdScanListener() { @Override public void messageId(MessageId id) { audit.isDuplicate(id); } }); } catch (Exception e) { LOG.error("Failed to reload store message audit for JDBC persistence adapter", e); } finally { if (c != null) { try { c.close(); } catch (Throwable e) { } } } }
@Override public void init() throws Exception { getAdapter().setUseExternalMessageReferences(isUseExternalMessageReferences()); if (isCreateTablesOnStartup()) { TransactionContext transactionContext = getTransactionContext(); transactionContext.getExclusiveConnection(); transactionContext.begin(); try { try { getAdapter().doCreateTables(transactionContext); } catch (SQLException e) { LOG.warn("Cannot create tables due to: " + e); JDBCPersistenceAdapter.log("Failure Details: ", e); } } finally { transactionContext.commit(); } } }
long[] getStoreSequenceIdForMessageId(ConnectionContext context, MessageId messageId, ActiveMQDestination destination) throws IOException { long[] result = new long[]{-1, Byte.MAX_VALUE -1}; TransactionContext c = getTransactionContext(context); try { result = adapter.getStoreSequenceId(c, destination, messageId); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to get store sequenceId for messageId: " + messageId +", on: " + destination + ". Reason: " + e, e); } finally { c.close(); } return result; }
public void cleanup() { TransactionContext c = null; try { LOG.debug("Cleaning up old messages."); c = getTransactionContext(); c.getExclusiveConnection(); getAdapter().doDeleteOldMessages(c); } catch (IOException e) { LOG.warn("Old message cleanup failed due to: " + e, e); } catch (SQLException e) { LOG.warn("Old message cleanup failed due to: " + e); JDBCPersistenceAdapter.log("Failure Details: ", e); } finally { if (c != null) { try { c.close(); } catch (Throwable e) { } } LOG.debug("Cleanup done."); } }
protected void createMessageAudit() { if (enableAudit && audit == null) { audit = new ActiveMQMessageAudit(maxAuditDepth,maxProducersToAudit); TransactionContext c = null; try { c = getTransactionContext(); getAdapter().doMessageIdScan(c, auditRecoveryDepth, new JDBCMessageIdScanListener() { @Override public void messageId(MessageId id) { audit.isDuplicate(id); } }); } catch (Exception e) { LOG.error("Failed to reload store message audit for JDBC persistence adapter", e); } finally { if (c != null) { try { c.close(); } catch (Throwable e) { } } } } }
@Override public int getMessageCount() throws IOException { int result = 0; TransactionContext c = persistenceAdapter.getTransactionContext(); try { result = adapter.doGetMessageCount(c, destination); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to get Message Count: " + destination + ". Reason: " + e, e); } finally { c.close(); } return result; }
@Override public Set<ActiveMQDestination> getDestinations() { TransactionContext c = null; try { c = getTransactionContext(); return getAdapter().doGetDestinations(c); } catch (IOException e) { return emptyDestinationSet(); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); return emptyDestinationSet(); } finally { if (c != null) { try { c.close(); } catch (Throwable e) { } } } }
/** * @see org.apache.activemq.store.TopicMessageStore#lookupSubscription(String, * String) */ @Override public SubscriptionInfo lookupSubscription(String clientId, String subscriptionName) throws IOException { TransactionContext c = persistenceAdapter.getTransactionContext(); try { return adapter.doGetSubscriberEntry(c, destination, clientId, subscriptionName); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to lookup subscription for: " + clientId + ". Reason: " + e, e); } finally { c.close(); } }
TransactionContext c = persistenceAdapter.getTransactionContext(); try { if (LOG.isTraceEnabled()) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); } finally { c.close();
/** * @see org.apache.activemq.store.MessageStore#removeAllMessages(ConnectionContext) */ @Override public void removeAllMessages(ConnectionContext context) throws IOException { // Get a connection and remove the message from the DB TransactionContext c = persistenceAdapter.getTransactionContext(context); try { adapter.doRemoveAllMessages(c, destination); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to broker remove all messages: " + e, e); } finally { c.close(); } }
throws Exception { TransactionContext c = persistenceAdapter.getTransactionContext(); JDBCPersistenceAdapter.log("JDBC Failure: ", e); } finally { c.close();
@Override public long getLastProducerSequenceId(ProducerId id) throws IOException { TransactionContext c = getTransactionContext(); try { return getAdapter().doGetLastProducerSequenceId(c, id); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to get last broker message id: " + e, e); } finally { c.close(); } }
public void commitLastAck(ConnectionContext context, long xidLastAck, long priority, ActiveMQDestination destination, String subName, String clientId) throws IOException { TransactionContext c = getTransactionContext(context); try { getAdapter().doSetLastAck(c, destination, null, clientId, subName, xidLastAck, priority); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to commit last ack with priority: " + priority + " on " + destination + " for " + subName + ":" + clientId + ". Reason: " + e,e); } finally { c.close(); } }
public void recover(JdbcMemoryTransactionStore jdbcMemoryTransactionStore) throws IOException { TransactionContext c = getTransactionContext(); try { getAdapter().doRecoverPreparedOps(c, jdbcMemoryTransactionStore); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to recover from: " + jdbcMemoryTransactionStore + ". Reason: " + e,e); } finally { c.close(); } }
@Override public void addSubscription(SubscriptionInfo subscriptionInfo, boolean retroactive) throws IOException { TransactionContext c = persistenceAdapter.getTransactionContext(); try { c = persistenceAdapter.getTransactionContext(); adapter.doSetSubscriberEntry(c, subscriptionInfo, retroactive, isPrioritizedMessages()); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to lookup subscription for info: " + subscriptionInfo.getClientId() + ". Reason: " + e, e); } finally { c.close(); } }
public void commitAdd(ConnectionContext context, final MessageId messageId, final long preparedSequenceId, final long newSequence) throws IOException { TransactionContext c = getTransactionContext(context); try { getAdapter().doCommitAddOp(c, preparedSequenceId, newSequence); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to commit add: " + messageId + ". Reason: " + e, e); } finally { c.close(); } }
public void rollbackLastAck(ConnectionContext context, byte priority, ActiveMQDestination destination, String subName, String clientId) throws IOException { TransactionContext c = getTransactionContext(context); try { getAdapter().doClearLastAck(c, destination, priority, clientId, subName); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to rollback last ack with priority: " + priority + " on " + destination + " for " + subName + ":" + clientId + ". Reason: " + e, e); } finally { c.close(); } }
public void addMessageReference(ConnectionContext context, MessageId messageId, long expirationTime, String messageRef) throws IOException { // Get a connection and insert the message into the DB. TransactionContext c = persistenceAdapter.getTransactionContext(context); try { adapter.doAddMessageReference(c, persistenceAdapter.getNextSequenceId(), messageId, destination, expirationTime, messageRef); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); } finally { c.close(); } }