org.apache.activemq.store.jdbc.adapter
Class DefaultJDBCAdapter

java.lang.Object
  extended by org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter
All Implemented Interfaces:
JDBCAdapter
Direct Known Subclasses:
BlobJDBCAdapter, BytesJDBCAdapter, DB2JDBCAdapter, ImageBasedJDBCAdaptor, MaxDBJDBCAdapter, MySqlJDBCAdapter, OracleJDBCAdapter, 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
protected  boolean batchStatments
           
protected  ReadWriteLock cleanupExclusiveLock
           
static int MAX_ROWS
           
protected  int maxRows
           
protected  boolean prioritizedMessages
           
protected  Statements statements
           
 
Constructor Summary
DefaultJDBCAdapter()
           
 
Method Summary
protected static void close(PreparedStatement s)
           
protected static void close(ResultSet rs)
           
 void doAddMessage(TransactionContext c, long sequence, MessageId messageID, ActiveMQDestination destination, byte[] data, long expiration, byte priority, XATransactionId xid)
          A non null xid indicated the op is part of 2pc prepare, so ops are flagged pending outcome
 void doAddMessageReference(TransactionContext c, long sequence, MessageId messageID, ActiveMQDestination destination, long expirationTime, String messageRef)
           
 void doClearLastAck(TransactionContext c, ActiveMQDestination destination, byte priority, String clientId, String subName)
           
 void doCommitAddOp(TransactionContext c, long sequence)
           
 void doCreateTables(TransactionContext c)
           
 void doDeleteOldMessages(TransactionContext c)
           
 void doDeleteSubscription(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriptionName)
           
 void doDropTables(TransactionContext c)
           
 SubscriptionInfo[] doGetAllSubscriptions(TransactionContext c, ActiveMQDestination destination)
           
 Set<ActiveMQDestination> doGetDestinations(TransactionContext c)
           
 int doGetDurableSubscriberMessageCount(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriptionName, boolean isPrioritizedMessages)
           
 long doGetLastAckedDurableSubscriberMessageId(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriberName)
           
 long doGetLastMessageStoreSequenceId(TransactionContext c)
           
 long doGetLastProducerSequenceId(TransactionContext c, ProducerId id)
           
 byte[] doGetMessage(TransactionContext c, MessageId id)
           
 byte[] doGetMessageById(TransactionContext c, long storeSequenceId)
           
 int doGetMessageCount(TransactionContext c, ActiveMQDestination destination)
           
 String doGetMessageReference(TransactionContext c, long seq)
           
 SubscriptionInfo doGetSubscriberEntry(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriptionName)
           
 void doMessageIdScan(TransactionContext c, int limit, JDBCMessageIdScanListener listener)
           
 void doRecordDestination(TransactionContext c, ActiveMQDestination destination)
           
 void doRecover(TransactionContext c, ActiveMQDestination destination, JDBCMessageRecoveryListener listener)
           
 void doRecoverNextMessages(TransactionContext c, ActiveMQDestination destination, long nextSeq, long priority, int maxReturned, boolean isPrioritizedMessages, JDBCMessageRecoveryListener listener)
           
 void doRecoverNextMessages(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriptionName, long seq, long priority, int maxReturned, JDBCMessageRecoveryListener listener)
           
 void doRecoverNextMessagesWithPriority(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriptionName, long seq, long priority, int maxReturned, JDBCMessageRecoveryListener listener)
           
 void doRecoverPreparedOps(TransactionContext c, JdbcMemoryTransactionStore jdbcMemoryTransactionStore)
           
 void doRecoverSubscription(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriptionName, JDBCMessageRecoveryListener listener)
           
 void doRemoveAllMessages(TransactionContext c, ActiveMQDestination destinationName)
           
 void doRemoveMessage(TransactionContext c, long seq, XATransactionId xid)
          A non null xid indicated the op is part of 2pc prepare, so ops are flagged pending outcome
 void doSetLastAck(TransactionContext c, ActiveMQDestination destination, XATransactionId xid, String clientId, String subscriptionName, long seq, long priority)
           
 void doSetLastAckWithPriority(TransactionContext c, ActiveMQDestination destination, XATransactionId xid, String clientId, String subscriptionName, long seq, long priority)
           
 void doSetSubscriberEntry(TransactionContext c, SubscriptionInfo info, boolean retroactive, boolean isPrioritizedMessages)
           
protected  byte[] getBinaryData(ResultSet rs, int index)
           
 int getMaxRows()
           
 Statements getStatements()
           
 long[] getStoreSequenceId(TransactionContext c, ActiveMQDestination destination, MessageId messageID)
           
 boolean isBatchStatments()
           
 void setBatchStatments(boolean batchStatments)
           
protected  void setBinaryData(PreparedStatement s, int index, byte[] data)
           
 void setMaxRows(int maxRows)
           
 void setStatements(Statements statements)
           
 void setUseExternalMessageReferences(boolean useExternalMessageReferences)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

cleanupExclusiveLock

protected ReadWriteLock cleanupExclusiveLock

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 c)
                    throws SQLException,
                           IOException
Specified by:
doCreateTables in interface JDBCAdapter
Throws:
SQLException
IOException

doDropTables

public void doDropTables(TransactionContext c)
                  throws SQLException,
                         IOException
Specified by:
doDropTables in interface JDBCAdapter
Throws:
SQLException
IOException

doGetLastMessageStoreSequenceId

public long doGetLastMessageStoreSequenceId(TransactionContext c)
                                     throws SQLException,
                                            IOException
Specified by:
doGetLastMessageStoreSequenceId in interface JDBCAdapter
Throws:
SQLException
IOException

doGetMessageById

public byte[] doGetMessageById(TransactionContext c,
                               long storeSequenceId)
                        throws SQLException,
                               IOException
Specified by:
doGetMessageById in interface JDBCAdapter
Throws:
SQLException
IOException

doAddMessage

public void doAddMessage(TransactionContext c,
                         long sequence,
                         MessageId messageID,
                         ActiveMQDestination destination,
                         byte[] data,
                         long expiration,
                         byte priority,
                         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:
doAddMessage in interface JDBCAdapter
Throws:
SQLException
IOException

doAddMessageReference

public void doAddMessageReference(TransactionContext c,
                                  long sequence,
                                  MessageId messageID,
                                  ActiveMQDestination destination,
                                  long expirationTime,
                                  String messageRef)
                           throws SQLException,
                                  IOException
Specified by:
doAddMessageReference in interface JDBCAdapter
Throws:
SQLException
IOException

getStoreSequenceId

public long[] getStoreSequenceId(TransactionContext c,
                                 ActiveMQDestination destination,
                                 MessageId messageID)
                          throws SQLException,
                                 IOException
Specified by:
getStoreSequenceId in interface JDBCAdapter
Throws:
SQLException
IOException

doGetMessage

public byte[] doGetMessage(TransactionContext c,
                           MessageId id)
                    throws SQLException,
                           IOException
Specified by:
doGetMessage in interface JDBCAdapter
Throws:
SQLException
IOException

doGetMessageReference

public String doGetMessageReference(TransactionContext c,
                                    long seq)
                             throws SQLException,
                                    IOException
Specified by:
doGetMessageReference in interface JDBCAdapter
Throws:
SQLException
IOException

doRemoveMessage

public void doRemoveMessage(TransactionContext c,
                            long seq,
                            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:
doRemoveMessage in interface JDBCAdapter
Throws:
SQLException
IOException

doRecover

public void doRecover(TransactionContext c,
                      ActiveMQDestination destination,
                      JDBCMessageRecoveryListener listener)
               throws Exception
Specified by:
doRecover in interface JDBCAdapter
Throws:
Exception

doMessageIdScan

public void doMessageIdScan(TransactionContext c,
                            int limit,
                            JDBCMessageIdScanListener listener)
                     throws SQLException,
                            IOException
Specified by:
doMessageIdScan in interface JDBCAdapter
Throws:
SQLException
IOException

doSetLastAckWithPriority

public void doSetLastAckWithPriority(TransactionContext c,
                                     ActiveMQDestination destination,
                                     XATransactionId xid,
                                     String clientId,
                                     String subscriptionName,
                                     long seq,
                                     long priority)
                              throws SQLException,
                                     IOException
Specified by:
doSetLastAckWithPriority in interface JDBCAdapter
Throws:
SQLException
IOException

doSetLastAck

public void doSetLastAck(TransactionContext c,
                         ActiveMQDestination destination,
                         XATransactionId xid,
                         String clientId,
                         String subscriptionName,
                         long seq,
                         long priority)
                  throws SQLException,
                         IOException
Specified by:
doSetLastAck in interface JDBCAdapter
Throws:
SQLException
IOException

doClearLastAck

public void doClearLastAck(TransactionContext c,
                           ActiveMQDestination destination,
                           byte priority,
                           String clientId,
                           String subName)
                    throws SQLException,
                           IOException
Specified by:
doClearLastAck in interface JDBCAdapter
Throws:
SQLException
IOException

doRecoverSubscription

public void doRecoverSubscription(TransactionContext c,
                                  ActiveMQDestination destination,
                                  String clientId,
                                  String subscriptionName,
                                  JDBCMessageRecoveryListener listener)
                           throws Exception
Specified by:
doRecoverSubscription in interface JDBCAdapter
Throws:
Exception

doRecoverNextMessages

public void doRecoverNextMessages(TransactionContext c,
                                  ActiveMQDestination destination,
                                  String clientId,
                                  String subscriptionName,
                                  long seq,
                                  long priority,
                                  int maxReturned,
                                  JDBCMessageRecoveryListener listener)
                           throws Exception
Specified by:
doRecoverNextMessages in interface JDBCAdapter
Throws:
Exception

doRecoverNextMessagesWithPriority

public void doRecoverNextMessagesWithPriority(TransactionContext c,
                                              ActiveMQDestination destination,
                                              String clientId,
                                              String subscriptionName,
                                              long seq,
                                              long priority,
                                              int maxReturned,
                                              JDBCMessageRecoveryListener listener)
                                       throws Exception
Specified by:
doRecoverNextMessagesWithPriority in interface JDBCAdapter
Throws:
Exception

doGetDurableSubscriberMessageCount

public int doGetDurableSubscriberMessageCount(TransactionContext c,
                                              ActiveMQDestination destination,
                                              String clientId,
                                              String subscriptionName,
                                              boolean isPrioritizedMessages)
                                       throws SQLException,
                                              IOException
Specified by:
doGetDurableSubscriberMessageCount in interface JDBCAdapter
Throws:
SQLException
IOException

doSetSubscriberEntry

public void doSetSubscriberEntry(TransactionContext c,
                                 SubscriptionInfo info,
                                 boolean retroactive,
                                 boolean isPrioritizedMessages)
                          throws SQLException,
                                 IOException
Specified by:
doSetSubscriberEntry in interface JDBCAdapter
Parameters:
c -
info -
retroactive -
Throws:
SQLException
IOException

doGetSubscriberEntry

public SubscriptionInfo doGetSubscriberEntry(TransactionContext c,
                                             ActiveMQDestination destination,
                                             String clientId,
                                             String subscriptionName)
                                      throws SQLException,
                                             IOException
Specified by:
doGetSubscriberEntry in interface JDBCAdapter
Throws:
SQLException
IOException

doGetAllSubscriptions

public SubscriptionInfo[] doGetAllSubscriptions(TransactionContext c,
                                                ActiveMQDestination destination)
                                         throws SQLException,
                                                IOException
Specified by:
doGetAllSubscriptions in interface JDBCAdapter
Throws:
SQLException
IOException

doRemoveAllMessages

public void doRemoveAllMessages(TransactionContext c,
                                ActiveMQDestination destinationName)
                         throws SQLException,
                                IOException
Specified by:
doRemoveAllMessages in interface JDBCAdapter
Throws:
SQLException
IOException

doDeleteSubscription

public void doDeleteSubscription(TransactionContext c,
                                 ActiveMQDestination destination,
                                 String clientId,
                                 String subscriptionName)
                          throws SQLException,
                                 IOException
Specified by:
doDeleteSubscription in interface JDBCAdapter
Throws:
SQLException
IOException

doDeleteOldMessages

public void doDeleteOldMessages(TransactionContext c)
                         throws SQLException,
                                IOException
Specified by:
doDeleteOldMessages in interface JDBCAdapter
Throws:
SQLException
IOException

doGetLastAckedDurableSubscriberMessageId

public long doGetLastAckedDurableSubscriberMessageId(TransactionContext c,
                                                     ActiveMQDestination destination,
                                                     String clientId,
                                                     String subscriberName)
                                              throws SQLException,
                                                     IOException
Specified by:
doGetLastAckedDurableSubscriberMessageId in interface JDBCAdapter
Throws:
SQLException
IOException

close

protected static void close(PreparedStatement s)

close

protected static void close(ResultSet rs)

doGetDestinations

public Set<ActiveMQDestination> doGetDestinations(TransactionContext c)
                                           throws SQLException,
                                                  IOException
Specified by:
doGetDestinations in interface JDBCAdapter
Throws:
SQLException
IOException

isBatchStatments

public boolean isBatchStatments()
Returns:
true if batchStements

setBatchStatments

public void setBatchStatments(boolean batchStatments)
Parameters:
batchStatments -

setUseExternalMessageReferences

public void setUseExternalMessageReferences(boolean useExternalMessageReferences)
Specified by:
setUseExternalMessageReferences in interface JDBCAdapter

getStatements

public Statements getStatements()
Returns:
the statements

setStatements

public void setStatements(Statements statements)
Specified by:
setStatements in interface JDBCAdapter

getMaxRows

public int getMaxRows()
Specified by:
getMaxRows in interface JDBCAdapter

setMaxRows

public void setMaxRows(int maxRows)
Specified by:
setMaxRows in interface JDBCAdapter

doRecordDestination

public void doRecordDestination(TransactionContext c,
                                ActiveMQDestination destination)
                         throws SQLException,
                                IOException
Specified by:
doRecordDestination in interface JDBCAdapter
Throws:
SQLException
IOException

doRecoverPreparedOps

public void doRecoverPreparedOps(TransactionContext c,
                                 JdbcMemoryTransactionStore jdbcMemoryTransactionStore)
                          throws SQLException,
                                 IOException
Specified by:
doRecoverPreparedOps in interface JDBCAdapter
Throws:
SQLException
IOException

doCommitAddOp

public void doCommitAddOp(TransactionContext c,
                          long sequence)
                   throws SQLException,
                          IOException
Specified by:
doCommitAddOp in interface JDBCAdapter
Throws:
SQLException
IOException

doGetMessageCount

public int doGetMessageCount(TransactionContext c,
                             ActiveMQDestination destination)
                      throws SQLException,
                             IOException
Specified by:
doGetMessageCount in interface JDBCAdapter
Throws:
SQLException
IOException

doRecoverNextMessages

public void doRecoverNextMessages(TransactionContext c,
                                  ActiveMQDestination destination,
                                  long nextSeq,
                                  long priority,
                                  int maxReturned,
                                  boolean isPrioritizedMessages,
                                  JDBCMessageRecoveryListener listener)
                           throws Exception
Specified by:
doRecoverNextMessages in interface JDBCAdapter
Throws:
Exception

doGetLastProducerSequenceId

public long doGetLastProducerSequenceId(TransactionContext c,
                                        ProducerId id)
                                 throws SQLException,
                                        IOException
Specified by:
doGetLastProducerSequenceId in interface JDBCAdapter
Throws:
SQLException
IOException


Copyright © 2005-2012 The Apache Software Foundation. All Rights Reserved.