Class DefaultJDBCAdapter
- java.lang.Object
-
- org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter
-
- All Implemented Interfaces:
JDBCAdapter
- Direct Known Subclasses:
BlobJDBCAdapter,BytesJDBCAdapter,DB2JDBCAdapter,ImageBasedJDBCAdaptor,MaxDBJDBCAdapter,MySqlJDBCAdapter,OracleJDBCAdapter,SqlServerJDBCAdapter,StreamJDBCAdapter
public class DefaultJDBCAdapter extends Object implements JDBCAdapter
Implements all the default JDBC operations that are used by the JDBCPersistenceAdapter. sub-classing is encouraged to override the default implementation of methods to account for differences in JDBC Driver implementations. The JDBCAdapter inserts and extracts BLOB data using the getBytes()/setBytes() operations. The databases/JDBC drivers that use this adapter are:
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanbatchStatmentsstatic intMAX_ROWSprotected intmaxRowsprotected booleanprioritizedMessagesprotected Statementsstatements
-
Constructor Summary
Constructors Constructor Description DefaultJDBCAdapter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected static voidclose(PreparedStatement s)protected static voidclose(ResultSet rs)voiddoAddMessage(TransactionContext c, long sequence, org.apache.activemq.command.MessageId messageID, org.apache.activemq.command.ActiveMQDestination destination, byte[] data, long expiration, byte priority, org.apache.activemq.command.XATransactionId xid)A non null xid indicated the op is part of 2pc prepare, so ops are flagged pending outcomevoiddoAddMessageReference(TransactionContext c, long sequence, org.apache.activemq.command.MessageId messageID, org.apache.activemq.command.ActiveMQDestination destination, long expirationTime, String messageRef)voiddoClearLastAck(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, byte priority, String clientId, String subName)voiddoCommitAddOp(TransactionContext c, long preparedSequence, long sequence)voiddoCreateTables(TransactionContext transactionContext)voiddoDeleteOldMessages(TransactionContext c)voiddoDeleteSubscription(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName)voiddoDropTables(TransactionContext c)org.apache.activemq.command.SubscriptionInfo[]doGetAllSubscriptions(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination)Set<org.apache.activemq.command.ActiveMQDestination>doGetDestinations(TransactionContext c)intdoGetDurableSubscriberMessageCount(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName, boolean isPrioritizedMessages)longdoGetLastAckedDurableSubscriberMessageId(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriberName)longdoGetLastMessageStoreSequenceId(TransactionContext c)longdoGetLastProducerSequenceId(TransactionContext c, org.apache.activemq.command.ProducerId id)byte[]doGetMessage(TransactionContext c, org.apache.activemq.command.MessageId id)byte[]doGetMessageById(TransactionContext c, long storeSequenceId)intdoGetMessageCount(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination)StringdoGetMessageReference(TransactionContext c, long seq)org.apache.activemq.command.SubscriptionInfodoGetSubscriberEntry(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName)voiddoMessageIdScan(TransactionContext c, int limit, JDBCMessageIdScanListener listener)voiddoRecordDestination(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination)voiddoRecover(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, JDBCMessageRecoveryListener listener)voiddoRecoverNextMessages(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, long[] lastRecoveredEntries, long maxSeq, int maxReturned, boolean isPrioritizedMessages, JDBCMessageRecoveryListener listener)voiddoRecoverNextMessages(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName, long seq, long priority, int maxReturned, JDBCMessageRecoveryListener listener)voiddoRecoverNextMessagesWithPriority(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName, long seq, long priority, int maxReturned, JDBCMessageRecoveryListener listener)voiddoRecoverPreparedOps(TransactionContext c, JdbcMemoryTransactionStore jdbcMemoryTransactionStore)voiddoRecoverSubscription(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName, JDBCMessageRecoveryListener listener)voiddoRemoveAllMessages(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destinationName)voiddoRemoveMessage(TransactionContext c, long seq, org.apache.activemq.command.XATransactionId xid)A non null xid indicated the op is part of 2pc prepare, so ops are flagged pending outcomevoiddoSetLastAck(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, org.apache.activemq.command.XATransactionId xid, String clientId, String subscriptionName, long seq, long priority)voiddoSetLastAckWithPriority(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, org.apache.activemq.command.XATransactionId xid, String clientId, String subscriptionName, long seq, long priority)voiddoSetSubscriberEntry(TransactionContext c, org.apache.activemq.command.SubscriptionInfo info, boolean retroactive, boolean isPrioritizedMessages)voiddoUpdateMessage(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, org.apache.activemq.command.MessageId id, byte[] data)static voiddumpTables(Connection c)static voiddumpTables(Connection c, String destinationName, String clientId, String subscriptionName)protected byte[]getBinaryData(ResultSet rs, int index)intgetMaxRows()StatementsgetStatements()long[]getStoreSequenceId(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, org.apache.activemq.command.MessageId messageID)booleanisBatchStatements()booleanisBatchStatments()StringlimitQuery(String query)static voidprintQuery(Connection c, String query, PrintStream out)static voidprintQuery(PreparedStatement s, PrintStream out)voidsetBatchStatements(boolean batchStatements)Set the number of statements to process as a single batch DB updatevoidsetBatchStatments(boolean batchStatments)Deprecated.protected voidsetBinaryData(PreparedStatement s, int index, byte[] data)voidsetMaxRows(int maxRows)the max value for statement maxRows, used to limit jdbc queriesvoidsetStatements(Statements statements)voidsetUseExternalMessageReferences(boolean useExternalMessageReferences)
-
-
-
Field Detail
-
MAX_ROWS
public static final int MAX_ROWS
- See Also:
- Constant Field Values
-
statements
protected Statements statements
-
batchStatments
protected boolean batchStatments
-
prioritizedMessages
protected boolean prioritizedMessages
-
maxRows
protected int maxRows
-
-
Constructor Detail
-
DefaultJDBCAdapter
public DefaultJDBCAdapter()
-
-
Method Detail
-
setBinaryData
protected void setBinaryData(PreparedStatement s, int index, byte[] data) throws SQLException
- Throws:
SQLException
-
getBinaryData
protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException
- Throws:
SQLException
-
doCreateTables
public void doCreateTables(TransactionContext transactionContext) throws SQLException, IOException
- Specified by:
doCreateTablesin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doDropTables
public void doDropTables(TransactionContext c) throws SQLException, IOException
- Specified by:
doDropTablesin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doGetLastMessageStoreSequenceId
public long doGetLastMessageStoreSequenceId(TransactionContext c) throws SQLException, IOException
- Specified by:
doGetLastMessageStoreSequenceIdin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doGetMessageById
public byte[] doGetMessageById(TransactionContext c, long storeSequenceId) throws SQLException, IOException
- Specified by:
doGetMessageByIdin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doAddMessage
public void doAddMessage(TransactionContext c, long sequence, org.apache.activemq.command.MessageId messageID, org.apache.activemq.command.ActiveMQDestination destination, byte[] data, long expiration, byte priority, org.apache.activemq.command.XATransactionId xid) throws SQLException, IOException
A non null xid indicated the op is part of 2pc prepare, so ops are flagged pending outcome- Specified by:
doAddMessagein interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doUpdateMessage
public void doUpdateMessage(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, org.apache.activemq.command.MessageId id, byte[] data) throws SQLException, IOException
- Specified by:
doUpdateMessagein interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doAddMessageReference
public void doAddMessageReference(TransactionContext c, long sequence, org.apache.activemq.command.MessageId messageID, org.apache.activemq.command.ActiveMQDestination destination, long expirationTime, String messageRef) throws SQLException, IOException
- Specified by:
doAddMessageReferencein interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
getStoreSequenceId
public long[] getStoreSequenceId(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, org.apache.activemq.command.MessageId messageID) throws SQLException, IOException
- Specified by:
getStoreSequenceIdin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doGetMessage
public byte[] doGetMessage(TransactionContext c, org.apache.activemq.command.MessageId id) throws SQLException, IOException
- Specified by:
doGetMessagein interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doGetMessageReference
public String doGetMessageReference(TransactionContext c, long seq) throws SQLException, IOException
- Specified by:
doGetMessageReferencein interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doRemoveMessage
public void doRemoveMessage(TransactionContext c, long seq, org.apache.activemq.command.XATransactionId xid) throws SQLException, IOException
A non null xid indicated the op is part of 2pc prepare, so ops are flagged pending outcome- Specified by:
doRemoveMessagein interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doRecover
public void doRecover(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, JDBCMessageRecoveryListener listener) throws Exception
- Specified by:
doRecoverin interfaceJDBCAdapter- Throws:
Exception
-
doMessageIdScan
public void doMessageIdScan(TransactionContext c, int limit, JDBCMessageIdScanListener listener) throws SQLException, IOException
- Specified by:
doMessageIdScanin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doSetLastAckWithPriority
public void doSetLastAckWithPriority(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, org.apache.activemq.command.XATransactionId xid, String clientId, String subscriptionName, long seq, long priority) throws SQLException, IOException
- Specified by:
doSetLastAckWithPriorityin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doSetLastAck
public void doSetLastAck(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, org.apache.activemq.command.XATransactionId xid, String clientId, String subscriptionName, long seq, long priority) throws SQLException, IOException
- Specified by:
doSetLastAckin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doClearLastAck
public void doClearLastAck(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, byte priority, String clientId, String subName) throws SQLException, IOException
- Specified by:
doClearLastAckin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doRecoverSubscription
public void doRecoverSubscription(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName, JDBCMessageRecoveryListener listener) throws Exception
- Specified by:
doRecoverSubscriptionin interfaceJDBCAdapter- Throws:
Exception
-
doRecoverNextMessages
public void doRecoverNextMessages(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName, long seq, long priority, int maxReturned, JDBCMessageRecoveryListener listener) throws Exception
- Specified by:
doRecoverNextMessagesin interfaceJDBCAdapter- Throws:
Exception
-
doRecoverNextMessagesWithPriority
public void doRecoverNextMessagesWithPriority(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName, long seq, long priority, int maxReturned, JDBCMessageRecoveryListener listener) throws Exception
- Specified by:
doRecoverNextMessagesWithPriorityin interfaceJDBCAdapter- Throws:
Exception
-
doGetDurableSubscriberMessageCount
public int doGetDurableSubscriberMessageCount(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName, boolean isPrioritizedMessages) throws SQLException, IOException
- Specified by:
doGetDurableSubscriberMessageCountin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doSetSubscriberEntry
public void doSetSubscriberEntry(TransactionContext c, org.apache.activemq.command.SubscriptionInfo info, boolean retroactive, boolean isPrioritizedMessages) throws SQLException, IOException
- Specified by:
doSetSubscriberEntryin interfaceJDBCAdapter- Parameters:
c-info-retroactive-- Throws:
SQLExceptionIOException
-
doGetSubscriberEntry
public org.apache.activemq.command.SubscriptionInfo doGetSubscriberEntry(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName) throws SQLException, IOException
- Specified by:
doGetSubscriberEntryin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doGetAllSubscriptions
public org.apache.activemq.command.SubscriptionInfo[] doGetAllSubscriptions(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination) throws SQLException, IOException
- Specified by:
doGetAllSubscriptionsin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doRemoveAllMessages
public void doRemoveAllMessages(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destinationName) throws SQLException, IOException
- Specified by:
doRemoveAllMessagesin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doDeleteSubscription
public void doDeleteSubscription(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriptionName) throws SQLException, IOException
- Specified by:
doDeleteSubscriptionin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doDeleteOldMessages
public void doDeleteOldMessages(TransactionContext c) throws SQLException, IOException
- Specified by:
doDeleteOldMessagesin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doGetLastAckedDurableSubscriberMessageId
public long doGetLastAckedDurableSubscriberMessageId(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, String clientId, String subscriberName) throws SQLException, IOException
- Specified by:
doGetLastAckedDurableSubscriberMessageIdin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
close
protected static void close(PreparedStatement s)
-
doGetDestinations
public Set<org.apache.activemq.command.ActiveMQDestination> doGetDestinations(TransactionContext c) throws SQLException, IOException
- Specified by:
doGetDestinationsin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
isBatchStatements
public boolean isBatchStatements()
- Returns:
- true if batchStatements
-
setBatchStatements
public void setBatchStatements(boolean batchStatements)
Set the number of statements to process as a single batch DB update- Parameters:
batchStatements-
-
isBatchStatments
public boolean isBatchStatments()
- Returns:
- true if batchStements
-
setBatchStatments
public void setBatchStatments(boolean batchStatments)
Deprecated.This value batchStatments is deprecated and will be removed in a future release. Use batchStatements instead (Note the 'e' in Statement)"- Parameters:
batchStatments-
-
setUseExternalMessageReferences
public void setUseExternalMessageReferences(boolean useExternalMessageReferences)
- Specified by:
setUseExternalMessageReferencesin interfaceJDBCAdapter
-
getStatements
public Statements getStatements()
- Returns:
- the statements
-
setStatements
public void setStatements(Statements statements)
- Specified by:
setStatementsin interfaceJDBCAdapter
-
getMaxRows
public int getMaxRows()
- Specified by:
getMaxRowsin interfaceJDBCAdapter
-
setMaxRows
public void setMaxRows(int maxRows)
the max value for statement maxRows, used to limit jdbc queries- Specified by:
setMaxRowsin interfaceJDBCAdapter
-
doRecordDestination
public void doRecordDestination(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination) throws SQLException, IOException
- Specified by:
doRecordDestinationin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doRecoverPreparedOps
public void doRecoverPreparedOps(TransactionContext c, JdbcMemoryTransactionStore jdbcMemoryTransactionStore) throws SQLException, IOException
- Specified by:
doRecoverPreparedOpsin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doCommitAddOp
public void doCommitAddOp(TransactionContext c, long preparedSequence, long sequence) throws SQLException, IOException
- Specified by:
doCommitAddOpin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doGetMessageCount
public int doGetMessageCount(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination) throws SQLException, IOException
- Specified by:
doGetMessageCountin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
doRecoverNextMessages
public void doRecoverNextMessages(TransactionContext c, org.apache.activemq.command.ActiveMQDestination destination, long[] lastRecoveredEntries, long maxSeq, int maxReturned, boolean isPrioritizedMessages, JDBCMessageRecoveryListener listener) throws Exception
- Specified by:
doRecoverNextMessagesin interfaceJDBCAdapter- Throws:
Exception
-
doGetLastProducerSequenceId
public long doGetLastProducerSequenceId(TransactionContext c, org.apache.activemq.command.ProducerId id) throws SQLException, IOException
- Specified by:
doGetLastProducerSequenceIdin interfaceJDBCAdapter- Throws:
SQLExceptionIOException
-
dumpTables
public static void dumpTables(Connection c, String destinationName, String clientId, String subscriptionName) throws SQLException
- Throws:
SQLException
-
dumpTables
public static void dumpTables(Connection c) throws SQLException
- Throws:
SQLException
-
printQuery
public static void printQuery(Connection c, String query, PrintStream out) throws SQLException
- Throws:
SQLException
-
printQuery
public static void printQuery(PreparedStatement s, PrintStream out) throws SQLException
- Throws:
SQLException
-
limitQuery
public String limitQuery(String query)
- Specified by:
limitQueryin interfaceJDBCAdapter
-
-