org.jboss.messaging.core.plugin
Class JDBCPersistenceManager

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

public class JDBCPersistenceManager
extends ServiceMBeanSupport
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
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.jboss.messaging.core.plugin.contract.PersistenceManager
PersistenceManager.ReferenceInfo
 
Field Summary
protected  java.util.Map channelMultipliers
           
protected  ChannelMapper cm
           
protected  ObjectName cmObjectName
           
protected  java.lang.String commitMessageRef1
           
protected  java.lang.String commitMessageRef2
           
protected  java.lang.String createCounter
           
protected  java.lang.String createIdxMessageRefLoaded
           
protected  java.lang.String createIdxMessageRefMessageId
           
protected  java.lang.String createIdxMessageRefOrd
           
protected  java.lang.String createIdxMessageRefReliable
           
protected  java.lang.String createIdxMessageRefTx
           
protected  java.lang.String createMessage
           
protected  java.lang.String createMessageReference
           
protected  boolean createTablesOnStartup
           
protected  java.lang.String createTransaction
           
protected  java.lang.String dataSourceJNDIName
           
protected  java.lang.String deleteMessage
           
protected  java.lang.String deleteMessageRef
           
protected  java.lang.String deleteTransaction
           
protected  java.lang.String deleteUnreffedMessages
           
protected  java.lang.String deleteUnreliableRefs
           
protected  javax.sql.DataSource ds
           
protected  java.lang.String insertCounter
           
protected  java.lang.String insertMessage
           
protected  java.lang.String insertMessageRef
           
protected  java.lang.String insertTransaction
           
protected  java.lang.String loadMessages
           
protected  java.lang.String loadReferenceInfo
           
protected  int maxParams
           
protected  java.lang.String messageIdColumn
           
protected  int minOrdering
           
protected  java.lang.String rollbackMessageRef1
           
protected  java.lang.String rollbackMessageRef2
           
protected  java.lang.String selectAllChannels
           
protected  java.lang.String selectCounter
           
protected  java.lang.String selectCountReferences
           
protected  java.lang.String selectMinOrdering
           
protected  java.lang.String selectPreparedTransactions
           
protected  java.util.Properties sqlProperties
           
protected  ObjectName tmObjectName
           
protected  java.lang.String updateCounter
           
protected  java.lang.String updateDeliveryCount
           
protected  java.lang.String updateMessageChannelCount
           
protected  java.lang.String updateMessageRef
           
protected  java.lang.String updateMessageRefNotLoaded
           
protected  java.lang.String updateReliableRefs
           
protected  java.lang.String updateReliableRefsNotLoaded
           
protected  java.lang.String updateUnreliableChannelCount
           
protected  boolean usingBatchUpdates
           
protected  boolean usingBinaryStream
           
 
Constructor Summary
JDBCPersistenceManager()
           
JDBCPersistenceManager(javax.sql.DataSource ds, TransactionManager tm)
          Only used for testing.
JDBCPersistenceManager(javax.sql.DataSource ds, TransactionManager tm, ChannelMapper cm)
          Only used for testing.
 
Method Summary
protected  void addReference(long channelID, MessageReference ref, java.sql.PreparedStatement ps, boolean loaded)
           
 void addReference(long channelID, MessageReference ref, Transaction tx)
           
 void addReferences(long channelID, java.util.List references, boolean loaded)
           
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 createSchema()
           
protected  void decPersistentCounts(java.util.List refs)
           
protected  byte[] getBytes(java.sql.ResultSet rs, int columnIndex)
           
protected  org.jboss.messaging.core.plugin.JDBCPersistenceManager.TransactionCallback getCallback(Transaction tx)
           
 ObjectName getChannelMapper()
          Managed attribute.
 java.lang.String getDataSource()
          Managed attribute.
 java.lang.Object getInstance()
          A server plugin will be always accessed via a hard reference, so it is essential that each implementation exposes this method.
protected  void getLocks(java.util.List refs)
           
 int getMaxParams()
           
 java.util.List getMessages(java.util.List messageIds)
          Retrieve a List of messages corresponding to the specified List of message ids.
 long getMinOrdering(long channelID)
           
 int getNumberOfUnloadedReferences(long channelID)
           
 java.util.List getReferenceInfos(long channelID, long minOrdering, int number)
           
 java.lang.String getSqlProperties()
           
 ObjectName getTransactionManager()
          Managed attribute.
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 incPersistentCounts(java.util.List refs)
           
protected  void initSqlProperties()
           
 boolean isCreateTablesOnStartup()
          Managed attribute.
 boolean isUsingBatchUpdates()
          Managed attribute.
protected  void logBatchUpdate(java.lang.String name, int[] rows, java.lang.String action)
           
protected  byte[] mapToBytes(java.util.Map map)
           
protected  void orderReferences(java.util.List references)
           
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)
           
protected  void releaseLocks(java.util.List refs)
           
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)
           
 void removeReferences(long channelID, java.util.List references)
           
protected  void removeTXRecord(java.sql.Connection conn, Transaction tx)
           
protected  void removeUnreliableMessageData()
           
 long reserveIDBlock(java.lang.String counterName, int size)
           
 void resetLoadedStatus(long channelID)
           
 java.util.List retrievePreparedTransactions()
           
protected  void rollbackPreparedTransaction(Transaction tx, java.sql.Connection conn)
           
protected  void setBytes(java.sql.PreparedStatement ps, int columnIndex, byte[] bytes)
           
 void setChannelMapper(ObjectName cmObjectName)
          Managed attribute.
 void setCreateTablesOnStartup(boolean b)
          Managed attribute.
 void setDataSource(java.lang.String dataSourceJNDIName)
          Managed attribute.
 void setMaxParams(int maxParams)
           
 void setSqlProperties(java.util.Properties props)
           
 void setSqlProperties(java.lang.String value)
           
 void setTransactionManager(ObjectName tmObjectName)
          Managed attribute.
 void setUsingBatchUpdates(boolean b)
          Managed attribute.
protected  void startService()
           
protected  void stopService()
           
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)
           
protected  void updateMessageChannelCount(Message m, java.sql.PreparedStatement ps)
           
 void updateReferencesNotLoaded(long channelID, java.util.List references)
           
 void updateReliableReferencesLoadedInRange(long channelID, long orderStart, long orderEnd)
           
protected  int updateWithRetry(java.sql.PreparedStatement ps)
           
protected  int[] updateWithRetryBatch(java.sql.PreparedStatement ps)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

createMessageReference

protected java.lang.String createMessageReference

createIdxMessageRefTx

protected java.lang.String createIdxMessageRefTx

createIdxMessageRefOrd

protected java.lang.String createIdxMessageRefOrd

createIdxMessageRefMessageId

protected java.lang.String createIdxMessageRefMessageId

createIdxMessageRefLoaded

protected java.lang.String createIdxMessageRefLoaded

createIdxMessageRefReliable

protected java.lang.String createIdxMessageRefReliable

insertMessageRef

protected java.lang.String insertMessageRef

deleteMessageRef

protected java.lang.String deleteMessageRef

updateMessageRef

protected java.lang.String updateMessageRef

updateDeliveryCount

protected java.lang.String updateDeliveryCount

updateMessageRefNotLoaded

protected java.lang.String updateMessageRefNotLoaded

commitMessageRef1

protected java.lang.String commitMessageRef1

commitMessageRef2

protected java.lang.String commitMessageRef2

rollbackMessageRef1

protected java.lang.String rollbackMessageRef1

rollbackMessageRef2

protected java.lang.String rollbackMessageRef2

loadReferenceInfo

protected java.lang.String loadReferenceInfo

selectMinOrdering

protected java.lang.String selectMinOrdering

selectCountReferences

protected java.lang.String selectCountReferences

updateReliableRefs

protected java.lang.String updateReliableRefs

updateReliableRefsNotLoaded

protected java.lang.String updateReliableRefsNotLoaded

deleteUnreliableRefs

protected java.lang.String deleteUnreliableRefs

createMessage

protected java.lang.String createMessage

loadMessages

protected java.lang.String loadMessages

insertMessage

protected java.lang.String insertMessage

updateMessageChannelCount

protected java.lang.String updateMessageChannelCount

deleteMessage

protected java.lang.String deleteMessage

messageIdColumn

protected java.lang.String messageIdColumn

updateUnreliableChannelCount

protected java.lang.String updateUnreliableChannelCount

deleteUnreffedMessages

protected java.lang.String deleteUnreffedMessages

createTransaction

protected java.lang.String createTransaction

insertTransaction

protected java.lang.String insertTransaction

deleteTransaction

protected java.lang.String deleteTransaction

selectPreparedTransactions

protected java.lang.String selectPreparedTransactions

createCounter

protected java.lang.String createCounter

updateCounter

protected java.lang.String updateCounter

selectCounter

protected java.lang.String selectCounter

insertCounter

protected java.lang.String insertCounter

selectAllChannels

protected java.lang.String selectAllChannels

dataSourceJNDIName

protected java.lang.String dataSourceJNDIName

ds

protected javax.sql.DataSource ds

tmObjectName

protected ObjectName tmObjectName

cmObjectName

protected ObjectName cmObjectName

cm

protected ChannelMapper cm

sqlProperties

protected java.util.Properties sqlProperties

createTablesOnStartup

protected boolean createTablesOnStartup

usingBatchUpdates

protected boolean usingBatchUpdates

usingBinaryStream

protected boolean usingBinaryStream

maxParams

protected int maxParams

minOrdering

protected int minOrdering

channelMultipliers

protected java.util.Map channelMultipliers
Constructor Detail

JDBCPersistenceManager

public JDBCPersistenceManager()
                       throws java.lang.Exception

JDBCPersistenceManager

public JDBCPersistenceManager(javax.sql.DataSource ds,
                              TransactionManager tm)
                       throws java.lang.Exception
Only used for testing. In a real deployment, the data source and the transaction manager are injected as dependencies.


JDBCPersistenceManager

public JDBCPersistenceManager(javax.sql.DataSource ds,
                              TransactionManager tm,
                              ChannelMapper cm)
                       throws java.lang.Exception
Only used for testing. In a real deployment, the data source and the transaction manager are injected as dependencies.

Method Detail

startService

protected void startService()
                     throws java.lang.Exception
Throws:
java.lang.Exception

stopService

protected void stopService()
                    throws java.lang.Exception
Throws:
java.lang.Exception

getInstance

public java.lang.Object getInstance()
Description copied from interface: ServerPlugin
A server plugin will be always accessed via a hard reference, so it is essential that each implementation exposes this method.

Specified by:
getInstance in interface ServerPlugin

reserveIDBlock

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

updateReliableReferencesLoadedInRange

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

getNumberOfUnloadedReferences

public int getNumberOfUnloadedReferences(long channelID)
                                  throws java.lang.Exception
Specified by:
getNumberOfUnloadedReferences in interface PersistenceManager
Throws:
java.lang.Exception

getMessages

public java.util.List getMessages(java.util.List messageIds)
                           throws java.lang.Exception
Retrieve a List of messages corresponding to the specified List of message ids. The implementation here for HSQLDB does this by using a PreparedStatment with an IN clause with a maximum of 100 elements. If there are more than maxParams message to retrieve this is repeated a number of times. For "Enterprise" databases (Oracle, DB2, Sybase etc) a more sophisticated technique should be used e.g. Oracle ARRAY types in Oracle which can be submitted as a param to an Oracle prepared statement. Although this would all be DB specific.

Specified by:
getMessages in interface PersistenceManager
Throws:
java.lang.Exception

addReferences

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

removeReferences

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

getMinOrdering

public long getMinOrdering(long channelID)
                    throws java.lang.Exception
Specified by:
getMinOrdering in interface PersistenceManager
Throws:
java.lang.Exception

getReferenceInfos

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

updateReferencesNotLoaded

public void updateReferencesNotLoaded(long channelID,
                                      java.util.List references)
                               throws java.lang.Exception
Specified by:
updateReferencesNotLoaded 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

resetLoadedStatus

public void resetLoadedStatus(long channelID)
                       throws java.lang.Exception
Specified by:
resetLoadedStatus 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

setDataSource

public void setDataSource(java.lang.String dataSourceJNDIName)
                   throws java.lang.Exception
Managed attribute.

Throws:
java.lang.Exception

getDataSource

public java.lang.String getDataSource()
Managed attribute.


setTransactionManager

public void setTransactionManager(ObjectName tmObjectName)
                           throws java.lang.Exception
Managed attribute.

Throws:
java.lang.Exception

getTransactionManager

public ObjectName getTransactionManager()
Managed attribute.


setChannelMapper

public void setChannelMapper(ObjectName cmObjectName)
                      throws java.lang.Exception
Managed attribute.

Throws:
java.lang.Exception

getChannelMapper

public ObjectName getChannelMapper()
Managed attribute.


getSqlProperties

public java.lang.String getSqlProperties()

setSqlProperties

public void setSqlProperties(java.lang.String value)

setSqlProperties

public void setSqlProperties(java.util.Properties props)

isCreateTablesOnStartup

public boolean isCreateTablesOnStartup()
                                throws java.lang.Exception
Managed attribute.

Throws:
java.lang.Exception

setCreateTablesOnStartup

public void setCreateTablesOnStartup(boolean b)
                              throws java.lang.Exception
Managed attribute.

Throws:
java.lang.Exception

isUsingBatchUpdates

public boolean isUsingBatchUpdates()
                            throws java.lang.Exception
Managed attribute.

Throws:
java.lang.Exception

setUsingBatchUpdates

public void setUsingBatchUpdates(boolean b)
                          throws java.lang.Exception
Managed attribute.

Throws:
java.lang.Exception

getMaxParams

public int getMaxParams()

setMaxParams

public void setMaxParams(int maxParams)

toString

public java.lang.String toString()

createSchema

protected void createSchema()
                     throws java.lang.Exception
Throws:
java.lang.Exception

initSqlProperties

protected void initSqlProperties()

getCallback

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

orderReferences

protected void orderReferences(java.util.List references)

removeUnreliableMessageData

protected void removeUnreliableMessageData()
                                    throws java.lang.Exception
Throws:
java.lang.Exception

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 loaded)
                     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

updateMessageChannelCount

protected void updateMessageChannelCount(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

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)

incPersistentCounts

protected void incPersistentCounts(java.util.List refs)

decPersistentCounts

protected void decPersistentCounts(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


Copyright © 2006 JBoss Inc. All Rights Reserved.