org.jboss.messaging.core.plugin
Class JDBCPersistenceManager

java.lang.Object
  extended byorg.jboss.messaging.core.plugin.JDBCSupport
      extended byorg.jboss.messaging.core.plugin.JDBCPersistenceManager
All Implemented Interfaces:
MessagingComponent, PersistenceManager

public class JDBCPersistenceManager
extends JDBCSupport
implements PersistenceManager

JDBC implementation of PersistenceManager.

Version:
1.1 JDBCPersistenceManager.java,v 1.1 2006/02/22 17:33:41 timfox Exp
Author:
Ovidiu Feodorov, Tim Fox, Adrian Brock, Juha Lindfors

Nested Class Summary
 
Nested classes inherited from class org.jboss.messaging.core.plugin.JDBCSupport
JDBCSupport.TransactionWrapper
 
Nested classes inherited from class org.jboss.messaging.core.plugin.contract.PersistenceManager
PersistenceManager.InitialLoadInfo, PersistenceManager.MessageChannelPair, PersistenceManager.ReferenceInfo
 
Field Summary
 
Fields inherited from class org.jboss.messaging.core.plugin.JDBCSupport
ds, sqlProperties
 
Constructor Summary
JDBCPersistenceManager(javax.sql.DataSource ds, TransactionManager tm, java.util.Properties sqlProperties, boolean createTablesOnStartup, boolean usingBatchUpdates, boolean usingBinaryStream, boolean usingTrailingByte, int maxParams)
           
 
Method Summary
protected  void addReference(long channelID, MessageReference ref, java.sql.PreparedStatement ps, boolean paged)
           
 void addReference(long channelID, MessageReference ref, Transaction tx)
           
protected  void addTXRecord(java.sql.Connection conn, Transaction tx)
           
protected  java.util.HashMap bytesToMap(byte[] bytes)
           
protected  void commitPreparedTransaction(Transaction tx, java.sql.Connection conn)
           
protected  void decrementChannelCount(Message m, java.sql.PreparedStatement ps)
           
protected  byte[] getBytes(java.sql.ResultSet rs, int columnIndex)
           
protected  org.jboss.messaging.core.plugin.JDBCPersistenceManager.TransactionCallback getCallback(Transaction tx)
           
protected  java.util.Map getDefaultDDLStatements()
           
protected  java.util.Map getDefaultDMLStatements()
           
protected  void getLocks(java.util.List refs)
           
 java.util.List getMessageChannelPairAcksForTx(long transactionId)
           
 java.util.List getMessageChannelPairRefsForTx(long transactionId)
           
 java.util.List getMessages(java.util.List messageIds)
           
 java.util.List getPagedReferenceInfos(long channelID, long orderStart, int number)
           
protected  byte[] getVarBinaryColumn(java.sql.ResultSet rs, int columnIndex)
           
protected  void handleBeforeCommit1PC(java.util.List refsToAdd, java.util.List refsToRemove, Transaction tx)
           
protected  void handleBeforeCommit2PC(java.util.List refsToRemove, Transaction tx)
           
protected  void handleBeforePrepare(java.util.List refsToAdd, java.util.List refsToRemove, Transaction tx)
           
protected  void handleBeforeRollback(java.util.List refsToAdd, Transaction tx)
           
protected  void incrementChannelCount(Message m, java.sql.PreparedStatement ps)
           
 PersistenceManager.InitialLoadInfo loadFromStart(long channelID, int number)
           
protected  void logBatchUpdate(java.lang.String name, int[] rows, java.lang.String action)
           
protected  byte[] mapToBytes(java.util.Map map)
           
 PersistenceManager.InitialLoadInfo mergeAndLoad(long fromChannelID, long toChannelID, int numberToLoad, long firstPagingOrder, long nextPagingOrder)
           
protected  void orderReferences(java.util.List references)
          We order the list of references in ascending message order thus preventing deadlock when 2 or more channels are updating the same messages in different transactions.
 void pageReferences(long channelID, java.util.List references, boolean paged)
           
protected  void prepareToAddReference(long channelID, MessageReference ref, Transaction tx, java.sql.PreparedStatement ps)
           
protected  void prepareToRemoveReference(long channelID, MessageReference ref, Transaction tx, java.sql.PreparedStatement ps)
           
 boolean referenceExists(long messageID)
           
 boolean referenceExists(long channelID, long messageID)
           
protected  void releaseLocks(java.util.List refs)
           
 void removeDepagedReferences(long channelID, java.util.List references)
           
protected  void removeMessage(Message message, java.sql.PreparedStatement ps)
          Removes the message from the MESSAGE table.
protected  void removeReference(long channelID, MessageReference ref, java.sql.PreparedStatement ps)
           
 void removeReference(long channelID, MessageReference ref, Transaction tx)
           
protected  void removeTXRecord(java.sql.Connection conn, Transaction tx)
           
 long reserveIDBlock(java.lang.String counterName, int size)
           
 java.util.List retrievePreparedTransactions()
           
protected  void rollbackPreparedTransaction(Transaction tx, java.sql.Connection conn)
           
protected  void setBytes(java.sql.PreparedStatement ps, int columnIndex, byte[] bytes)
           
protected  void setVarBinaryColumn(int column, java.sql.PreparedStatement ps, byte[] bytes)
           
 void start()
           
 void stop()
           
protected  void storeMessage(Message m, java.sql.PreparedStatement ps)
          Stores the message in the MESSAGE table.
 java.lang.String toString()
           
 void updateDeliveryCount(long channelID, MessageReference ref)
           
 void updatePageOrder(long channelID, java.util.List references)
           
 void updateReferencesNotPagedInRange(long channelID, long orderStart, long orderEnd, long num)
           
protected  int updateWithRetry(java.sql.PreparedStatement ps)
           
protected  int[] updateWithRetryBatch(java.sql.PreparedStatement ps)
           
 
Methods inherited from class org.jboss.messaging.core.plugin.JDBCSupport
closeConnection, closeResultSet, closeStatement, getSQLStatement, ignoreVerificationOnStartup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JDBCPersistenceManager

public JDBCPersistenceManager(javax.sql.DataSource ds,
                              TransactionManager tm,
                              java.util.Properties sqlProperties,
                              boolean createTablesOnStartup,
                              boolean usingBatchUpdates,
                              boolean usingBinaryStream,
                              boolean usingTrailingByte,
                              int maxParams)
Method Detail

start

public void start()
           throws java.lang.Exception
Specified by:
start in interface MessagingComponent
Overrides:
start in class JDBCSupport
Throws:
java.lang.Exception

stop

public void stop()
          throws java.lang.Exception
Specified by:
stop in interface MessagingComponent
Overrides:
stop in class JDBCSupport
Throws:
java.lang.Exception

getMessageChannelPairRefsForTx

public java.util.List getMessageChannelPairRefsForTx(long transactionId)
                                              throws java.lang.Exception
Specified by:
getMessageChannelPairRefsForTx in interface PersistenceManager
Throws:
java.lang.Exception

getMessageChannelPairAcksForTx

public java.util.List getMessageChannelPairAcksForTx(long transactionId)
                                              throws java.lang.Exception
Specified by:
getMessageChannelPairAcksForTx in interface PersistenceManager
Throws:
java.lang.Exception

retrievePreparedTransactions

public java.util.List retrievePreparedTransactions()
                                            throws java.lang.Exception
Specified by:
retrievePreparedTransactions in interface PersistenceManager
Throws:
java.lang.Exception

reserveIDBlock

public long reserveIDBlock(java.lang.String counterName,
                           int size)
                    throws java.lang.Exception
Specified by:
reserveIDBlock in interface PersistenceManager
Throws:
java.lang.Exception

getMessages

public java.util.List getMessages(java.util.List messageIds)
                           throws java.lang.Exception
Specified by:
getMessages in interface PersistenceManager
Throws:
java.lang.Exception

pageReferences

public void pageReferences(long channelID,
                           java.util.List references,
                           boolean paged)
                    throws java.lang.Exception
Specified by:
pageReferences in interface PersistenceManager
Throws:
java.lang.Exception

removeDepagedReferences

public void removeDepagedReferences(long channelID,
                                    java.util.List references)
                             throws java.lang.Exception
Specified by:
removeDepagedReferences in interface PersistenceManager
Throws:
java.lang.Exception

updateReferencesNotPagedInRange

public void updateReferencesNotPagedInRange(long channelID,
                                            long orderStart,
                                            long orderEnd,
                                            long num)
                                     throws java.lang.Exception
Specified by:
updateReferencesNotPagedInRange in interface PersistenceManager
Throws:
java.lang.Exception

mergeAndLoad

public PersistenceManager.InitialLoadInfo mergeAndLoad(long fromChannelID,
                                                       long toChannelID,
                                                       int numberToLoad,
                                                       long firstPagingOrder,
                                                       long nextPagingOrder)
                                                throws java.lang.Exception
Specified by:
mergeAndLoad in interface PersistenceManager
Throws:
java.lang.Exception

updatePageOrder

public void updatePageOrder(long channelID,
                            java.util.List references)
                     throws java.lang.Exception
Specified by:
updatePageOrder in interface PersistenceManager
Throws:
java.lang.Exception

getPagedReferenceInfos

public java.util.List getPagedReferenceInfos(long channelID,
                                             long orderStart,
                                             int number)
                                      throws java.lang.Exception
Specified by:
getPagedReferenceInfos in interface PersistenceManager
Throws:
java.lang.Exception

loadFromStart

public PersistenceManager.InitialLoadInfo loadFromStart(long channelID,
                                                        int number)
                                                 throws java.lang.Exception
Specified by:
loadFromStart in interface PersistenceManager
Throws:
java.lang.Exception

addReference

public void addReference(long channelID,
                         MessageReference ref,
                         Transaction tx)
                  throws java.lang.Exception
Specified by:
addReference in interface PersistenceManager
Throws:
java.lang.Exception

updateDeliveryCount

public void updateDeliveryCount(long channelID,
                                MessageReference ref)
                         throws java.lang.Exception
Specified by:
updateDeliveryCount in interface PersistenceManager
Throws:
java.lang.Exception

removeReference

public void removeReference(long channelID,
                            MessageReference ref,
                            Transaction tx)
                     throws java.lang.Exception
Specified by:
removeReference in interface PersistenceManager
Throws:
java.lang.Exception

referenceExists

public boolean referenceExists(long channelID,
                               long messageID)
                        throws java.lang.Exception
Specified by:
referenceExists in interface PersistenceManager
Throws:
java.lang.Exception

referenceExists

public boolean referenceExists(long messageID)
                        throws java.lang.Exception
Specified by:
referenceExists in interface PersistenceManager
Throws:
java.lang.Exception

toString

public java.lang.String toString()

getCallback

protected org.jboss.messaging.core.plugin.JDBCPersistenceManager.TransactionCallback getCallback(Transaction tx)

orderReferences

protected void orderReferences(java.util.List references)
We order the list of references in ascending message order thus preventing deadlock when 2 or more channels are updating the same messages in different transactions.


handleBeforeCommit1PC

protected void handleBeforeCommit1PC(java.util.List refsToAdd,
                                     java.util.List refsToRemove,
                                     Transaction tx)
                              throws java.lang.Exception
Throws:
java.lang.Exception

handleBeforeCommit2PC

protected void handleBeforeCommit2PC(java.util.List refsToRemove,
                                     Transaction tx)
                              throws java.lang.Exception
Throws:
java.lang.Exception

handleBeforePrepare

protected void handleBeforePrepare(java.util.List refsToAdd,
                                   java.util.List refsToRemove,
                                   Transaction tx)
                            throws java.lang.Exception
Throws:
java.lang.Exception

handleBeforeRollback

protected void handleBeforeRollback(java.util.List refsToAdd,
                                    Transaction tx)
                             throws java.lang.Exception
Throws:
java.lang.Exception

addTXRecord

protected void addTXRecord(java.sql.Connection conn,
                           Transaction tx)
                    throws java.lang.Exception
Throws:
java.lang.Exception

removeTXRecord

protected void removeTXRecord(java.sql.Connection conn,
                              Transaction tx)
                       throws java.lang.Exception
Throws:
java.lang.Exception

addReference

protected void addReference(long channelID,
                            MessageReference ref,
                            java.sql.PreparedStatement ps,
                            boolean paged)
                     throws java.lang.Exception
Throws:
java.lang.Exception

removeReference

protected void removeReference(long channelID,
                               MessageReference ref,
                               java.sql.PreparedStatement ps)
                        throws java.lang.Exception
Throws:
java.lang.Exception

prepareToAddReference

protected void prepareToAddReference(long channelID,
                                     MessageReference ref,
                                     Transaction tx,
                                     java.sql.PreparedStatement ps)
                              throws java.lang.Exception
Throws:
java.lang.Exception

prepareToRemoveReference

protected void prepareToRemoveReference(long channelID,
                                        MessageReference ref,
                                        Transaction tx,
                                        java.sql.PreparedStatement ps)
                                 throws java.lang.Exception
Throws:
java.lang.Exception

commitPreparedTransaction

protected void commitPreparedTransaction(Transaction tx,
                                         java.sql.Connection conn)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

rollbackPreparedTransaction

protected void rollbackPreparedTransaction(Transaction tx,
                                           java.sql.Connection conn)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

mapToBytes

protected byte[] mapToBytes(java.util.Map map)
                     throws java.lang.Exception
Throws:
java.lang.Exception

bytesToMap

protected java.util.HashMap bytesToMap(byte[] bytes)
                                throws java.lang.Exception
Throws:
java.lang.Exception

incrementChannelCount

protected void incrementChannelCount(Message m,
                                     java.sql.PreparedStatement ps)
                              throws java.lang.Exception
Throws:
java.lang.Exception

decrementChannelCount

protected void decrementChannelCount(Message m,
                                     java.sql.PreparedStatement ps)
                              throws java.lang.Exception
Throws:
java.lang.Exception

storeMessage

protected void storeMessage(Message m,
                            java.sql.PreparedStatement ps)
                     throws java.lang.Exception
Stores the message in the MESSAGE table.

Throws:
java.lang.Exception

removeMessage

protected void removeMessage(Message message,
                             java.sql.PreparedStatement ps)
                      throws java.lang.Exception
Removes the message from the MESSAGE table.

Throws:
java.lang.Exception

setVarBinaryColumn

protected void setVarBinaryColumn(int column,
                                  java.sql.PreparedStatement ps,
                                  byte[] bytes)
                           throws java.lang.Exception
Throws:
java.lang.Exception

getVarBinaryColumn

protected byte[] getVarBinaryColumn(java.sql.ResultSet rs,
                                    int columnIndex)
                             throws java.lang.Exception
Throws:
java.lang.Exception

setBytes

protected void setBytes(java.sql.PreparedStatement ps,
                        int columnIndex,
                        byte[] bytes)
                 throws java.lang.Exception
Throws:
java.lang.Exception

getBytes

protected byte[] getBytes(java.sql.ResultSet rs,
                          int columnIndex)
                   throws java.lang.Exception
Throws:
java.lang.Exception

getLocks

protected void getLocks(java.util.List refs)

releaseLocks

protected void releaseLocks(java.util.List refs)

logBatchUpdate

protected void logBatchUpdate(java.lang.String name,
                              int[] rows,
                              java.lang.String action)

updateWithRetry

protected int updateWithRetry(java.sql.PreparedStatement ps)
                       throws java.lang.Exception
Throws:
java.lang.Exception

updateWithRetryBatch

protected int[] updateWithRetryBatch(java.sql.PreparedStatement ps)
                              throws java.lang.Exception
Throws:
java.lang.Exception

getDefaultDDLStatements

protected java.util.Map getDefaultDDLStatements()
Overrides:
getDefaultDDLStatements in class JDBCSupport

getDefaultDMLStatements

protected java.util.Map getDefaultDMLStatements()
Overrides:
getDefaultDMLStatements in class JDBCSupport


Copyright © 2006 JBoss Inc. All Rights Reserved.