org.exolab.jms.persistence
Class RDBMSAdapter

java.lang.Object
  |
  +--org.exolab.jms.persistence.PersistenceAdapter
        |
        +--org.exolab.jms.persistence.RDBMSAdapter
All Implemented Interfaces:
EventHandler, java.io.Serializable

public class RDBMSAdapter
extends PersistenceAdapter
implements EventHandler

This adapter is a wrapper class around the persistency mechanism. It isolates the client from the working specifics of the database, by providing a simple straight forward interface. Furure changes to the database will only require changes to the adapter.

Version:
$Revision: 1.54 $ $Date: 2004/01/08 05:55:07 $
Author:
Jim Mourikis
See Also:
Serialized Form

Field Summary
static java.lang.String SCHEMA_VERSION
          The schema version number.
 
Method Summary
 void addDestination(java.sql.Connection connection, java.lang.String name, boolean queue)
          Add a new destination to the database.
 void addDurableConsumer(java.sql.Connection connection, java.lang.String topic, java.lang.String consumer)
          Add the specified durable consumer
 void addMessage(java.sql.Connection connection, MessageImpl message)
          Add a new message to the database.
 void addMessageHandle(java.sql.Connection connection, PersistentMessageHandle handle)
          Add the specified persistent message handle.
 void addUser(java.sql.Connection connection, User user)
           
 boolean checkDestination(java.sql.Connection connection, java.lang.String name)
          Determine if a particular destination name exists
 void close()
          Close the database if open.
 boolean durableConsumerExists(java.sql.Connection connection, java.lang.String name)
          Check if the durable consumer exists
 java.util.Enumeration getAllDestinations(java.sql.Connection connection)
          Get a list of all destinations stored in the database
 java.util.HashMap getAllDurableConsumers(java.sql.Connection connection)
          Return a dictionary of all registered durable consumers.
 java.util.Enumeration getAllUsers(java.sql.Connection connection)
           
 java.sql.Connection getConnection()
          Return a connection to the database from the pool of connections.
 DBConnectionManager getDBConnectionManager()
          Return a reference to the DBConnectionManager
 int getDurableConsumerMessageCount(java.sql.Connection connection, java.lang.String destination, java.lang.String name)
          Return the number of unsent message for the specified durable consumer.
 java.util.Enumeration getDurableConsumers(java.sql.Connection connection, java.lang.String topic)
          Get an enumerated list of all durable consumers for the specified JmsTopic destination
 org.exolab.core.foundation.HandleIfc getHandle()
          Return a handle to this event handler for the purpose of storing and restoring it.
 long getLastId(java.sql.Connection connection)
          Check to see if the root is created.
 MessageImpl getMessage(java.sql.Connection connection, java.lang.String id)
          Get a message from the persistence store.
 java.util.Vector getMessageHandles(java.sql.Connection connection, JmsDestination destination, java.lang.String name)
          Get all the persistent message handles for the specified destination and consumer name.
 java.util.Vector getMessages(java.sql.Connection connection, PersistentMessageHandle handle)
          Get at least the next message given the specified persistent handle.
 java.util.Vector getNonExpiredMessages(java.sql.Connection connection, JmsDestination destination)
          Retrieve a list of unexpired PersistentMessageHandle objects, for the specified destination.
 int getQueueMessageCount(java.sql.Connection connection, java.lang.String name)
          Get the number of unsent messages for a the specified queue
 java.util.Vector getUnprocessedMessages(java.sql.Connection connection)
          Return a list of unprocessed messages.
 User getUser(java.sql.Connection connection, User user)
           
 void handleEvent(int event, java.lang.Object callback, long time)
          Handle the specified event, generated by the EventManager.
 int purgeMessages()
          Incrementally purge all processed messages from the database.
 void removeDestination(java.sql.Connection connection, java.lang.String name)
          Remove the destination with the specified name and all registered consumers from the database.
 void removeDurableConsumer(java.sql.Connection connection, java.lang.String consumer)
          Remove the durable consumer for the specified topic.
 void removeExpiredMessageHandles(java.sql.Connection connection, java.lang.String consumer)
          Remove all expired messages handles associated with this durable consumer.
 void removeExpiredMessages(java.sql.Connection connection)
          Remove all expired messages and associated references from the database.
 void removeMessage(java.sql.Connection connection, java.lang.String id)
          Remove the message with the specified identity from the database
 void removeMessageHandle(java.sql.Connection connection, PersistentMessageHandle handle)
          Remove the specified persistent message handle.
 void removeUser(java.sql.Connection connection, User user)
           
 void updateIds(java.sql.Connection connection, long id)
          Update the given id.
 void updateMessage(java.sql.Connection connection, MessageImpl message)
          Update this message in the database
 void updateMessageHandle(java.sql.Connection connection, PersistentMessageHandle handle)
          Update the specified persistent message handle.
 void updateUser(java.sql.Connection connection, User user)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCHEMA_VERSION

public static final java.lang.String SCHEMA_VERSION
The schema version number. Note this must be incremented whenever The schema changes.
Method Detail

close

public void close()
Close the database if open.
Overrides:
close in class PersistenceAdapter

getLastId

public long getLastId(java.sql.Connection connection)
               throws PersistenceException
Description copied from class: PersistenceAdapter
Check to see if the root is created. If its not then create it and initialise it to 0. Return the value of this root id.
Overrides:
getLastId in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Returns:
long The id of the last batch.
Throws:
PersistenceException -  

updateIds

public void updateIds(java.sql.Connection connection,
                      long id)
               throws PersistenceException
Description copied from class: PersistenceAdapter
Update the given id.
Overrides:
updateIds in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
id - The id to set in the database.
Throws:
PersistenceException -  

addMessage

public void addMessage(java.sql.Connection connection,
                       MessageImpl message)
                throws PersistenceException
Description copied from class: PersistenceAdapter
Add a new message to the database.
Overrides:
addMessage in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
MessageImpl - the new message to add
Throws:
PersistenceException -  

updateMessage

public void updateMessage(java.sql.Connection connection,
                          MessageImpl message)
                   throws PersistenceException
Description copied from class: PersistenceAdapter
Update this message in the database
Overrides:
updateMessage in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
MessageImpl - the new message to update
Throws:
PersistenceException -  

getUnprocessedMessages

public java.util.Vector getUnprocessedMessages(java.sql.Connection connection)
                                        throws PersistenceException
Description copied from class: PersistenceAdapter
Return a list of unprocessed messages. These are messages that have been stored in the database but not processed.
Overrides:
getUnprocessedMessages in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
Returns:
Vector - a collection of un processed messages
Throws:
PersistenceException -  

removeMessage

public void removeMessage(java.sql.Connection connection,
                          java.lang.String id)
                   throws PersistenceException
Description copied from class: PersistenceAdapter
Remove the message with the specified identity from the database
Overrides:
removeMessage in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
name - - the identity of the message to remove.
Throws:
PersistenceException -  

getMessage

public MessageImpl getMessage(java.sql.Connection connection,
                              java.lang.String id)
                       throws PersistenceException
Description copied from class: PersistenceAdapter
Get a message from the persistence store.
Overrides:
getMessage in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
String - The id of the message to search for
Returns:
MessageImpl The message if found otherwise null
Throws:
PersistenceException -  

getMessages

public java.util.Vector getMessages(java.sql.Connection connection,
                                    PersistentMessageHandle handle)
                             throws PersistenceException
Description copied from class: PersistenceAdapter
Get at least the next message given the specified persistent handle. The handle encodes all the information, including destination and timestamp, required to fetch that and successive messages. This will fault in more than one message for performance
Overrides:
getMessages in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
handle - - the persistent handle to resolve
Returns:
Vector - a vector of MessageImpl
Throws:
PersistenceException -  

addMessageHandle

public void addMessageHandle(java.sql.Connection connection,
                             PersistentMessageHandle handle)
                      throws PersistenceException
Description copied from class: PersistenceAdapter
Add the specified persistent message handle.
Overrides:
addMessageHandle in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
handle - - the persistent handle to add
Throws:
PersistenceException -  

updateMessageHandle

public void updateMessageHandle(java.sql.Connection connection,
                                PersistentMessageHandle handle)
                         throws PersistenceException
Description copied from class: PersistenceAdapter
Update the specified persistent message handle.
Overrides:
updateMessageHandle in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
handle - - the persistent handle to update
Throws:
PersistenceException -  

removeMessageHandle

public void removeMessageHandle(java.sql.Connection connection,
                                PersistentMessageHandle handle)
                         throws PersistenceException
Description copied from class: PersistenceAdapter
Remove the specified persistent message handle.
Overrides:
removeMessageHandle in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
handle - - the persistent handle to remove
Throws:
PersistenceException -  
PersistenceException -  

getMessageHandles

public java.util.Vector getMessageHandles(java.sql.Connection connection,
                                          JmsDestination destination,
                                          java.lang.String name)
                                   throws PersistenceException
Description copied from class: PersistenceAdapter
Get all the persistent message handles for the specified destination and consumer name.

The returned messages reference unacked or unsent messages

NEED A STRATEGY WHEN WE HAVE LOTS OF MESSAGE HANDLES

Overrides:
getMessageHandles in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
destination - - the destination to reference
name - - the consumer name
Throws:
PersistenceException -  

addDurableConsumer

public void addDurableConsumer(java.sql.Connection connection,
                               java.lang.String topic,
                               java.lang.String consumer)
                        throws PersistenceException
Description copied from class: PersistenceAdapter
Add the specified durable consumer
Overrides:
addDurableConsumer in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
topic - - the name of the topic
name - - the name of the consumer
Throws:
PersistenceException -  

removeDurableConsumer

public void removeDurableConsumer(java.sql.Connection connection,
                                  java.lang.String consumer)
                           throws PersistenceException
Description copied from class: PersistenceAdapter
Remove the durable consumer for the specified topic.
Overrides:
removeDurableConsumer in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
consumer - - the consumer name
Throws:
PersistenceException -  

getDurableConsumers

public java.util.Enumeration getDurableConsumers(java.sql.Connection connection,
                                                 java.lang.String topic)
                                          throws PersistenceException
Description copied from class: PersistenceAdapter
Get an enumerated list of all durable consumers for the specified JmsTopic destination
Overrides:
getDurableConsumers in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
topic - - the topic to query
Returns:
Vector - list of durable subscriber names
Throws:
PersistenceException -  

getAllDurableConsumers

public java.util.HashMap getAllDurableConsumers(java.sql.Connection connection)
                                         throws PersistenceException
Description copied from class: PersistenceAdapter
Return a dictionary of all registered durable consumers. The dictionary is keyed on consumer name and maps to the underlying destination name. The destination name maybe a wildcard
Overrides:
getAllDurableConsumers in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
Returns:
HashMap key=consumer name and value is destination
Throws:
PersistenceException -  

durableConsumerExists

public boolean durableConsumerExists(java.sql.Connection connection,
                                     java.lang.String name)
                              throws PersistenceException
Description copied from class: PersistenceAdapter
Check if the durable consumer exists
Overrides:
durableConsumerExists in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
name - - durable consumer name
Returns:
boolean - true if it exists and false otherwise
Throws:
PersistenceException -  

addDestination

public void addDestination(java.sql.Connection connection,
                           java.lang.String name,
                           boolean queue)
                    throws PersistenceException
Description copied from class: PersistenceAdapter
Add a new destination to the database.
Overrides:
addDestination in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
name - - the destination name
queue - - true if it pertains to a queue
Throws:
PersistenceException -  

removeDestination

public void removeDestination(java.sql.Connection connection,
                              java.lang.String name)
                       throws PersistenceException
Description copied from class: PersistenceAdapter
Remove the destination with the specified name and all registered consumers from the database. Consumer registrations.
Overrides:
removeDestination in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
destination - - the name of the destination
Throws:
PersistenceException -  

getAllDestinations

public java.util.Enumeration getAllDestinations(java.sql.Connection connection)
                                         throws PersistenceException
Description copied from class: PersistenceAdapter
Get a list of all destinations stored in the database
Overrides:
getAllDestinations in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
Returns:
Enumeration - the list of destinations
Throws:
PersistenceException -  

checkDestination

public boolean checkDestination(java.sql.Connection connection,
                                java.lang.String name)
                         throws PersistenceException
Description copied from class: PersistenceAdapter
Determine if a particular destination name exists
Overrides:
checkDestination in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
name - - the name to query
Returns:
boolean - true if it exists; false otherwise
Throws:
PersistenceException -  

getQueueMessageCount

public int getQueueMessageCount(java.sql.Connection connection,
                                java.lang.String name)
                         throws PersistenceException
Description copied from class: PersistenceAdapter
Get the number of unsent messages for a the specified queue
Overrides:
getQueueMessageCount in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
name - - the name of the queue
Returns:
int - the number of unsent or unacked messages
Throws:
PersistenceException -  

getDurableConsumerMessageCount

public int getDurableConsumerMessageCount(java.sql.Connection connection,
                                          java.lang.String destination,
                                          java.lang.String name)
                                   throws PersistenceException
Description copied from class: PersistenceAdapter
Return the number of unsent message for the specified durable consumer.
Overrides:
getDurableConsumerMessageCount in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
destination - - the destination name
name - - the name of the durable subscriber
Returns:
int - the nmber of unsent or unacked messages
Throws:
PersistenceException -  

removeExpiredMessages

public void removeExpiredMessages(java.sql.Connection connection)
                           throws PersistenceException
Description copied from class: PersistenceAdapter
Remove all expired messages and associated references from the database. It uses the current time to determine messages that have exipred.
Overrides:
removeExpiredMessages in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
Throws:
PersistenceException -  

removeExpiredMessageHandles

public void removeExpiredMessageHandles(java.sql.Connection connection,
                                        java.lang.String consumer)
                                 throws PersistenceException
Description copied from class: PersistenceAdapter
Remove all expired messages handles associated with this durable consumer.
Overrides:
removeExpiredMessageHandles in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
consumer - - the durable consumer name
Throws:
PersistenceException -  

getNonExpiredMessages

public java.util.Vector getNonExpiredMessages(java.sql.Connection connection,
                                              JmsDestination destination)
                                       throws PersistenceException
Description copied from class: PersistenceAdapter
Retrieve a list of unexpired PersistentMessageHandle objects, for the specified destination.
Overrides:
getNonExpiredMessages in class PersistenceAdapter
Following copied from class: org.exolab.jms.persistence.PersistenceAdapter
Parameters:
connection - - the connection to use
destination - - the destination in question
Returns:
Vector - collection of unexpired message handles
Throws:
PersistenceException -  

getHandle

public org.exolab.core.foundation.HandleIfc getHandle()
Description copied from interface: EventHandler
Return a handle to this event handler for the purpose of storing and restoring it. If you want event handlers to persist across subsequent invocations of the EventManager then you must support this method, otherwise this method can simply return null.
Specified by:
getHandle in interface EventHandler
Following copied from interface: org.exolab.jms.events.EventHandler
Returns:
HandleIfc return a reference to the handle.

handleEvent

public void handleEvent(int event,
                        java.lang.Object callback,
                        long time)
Description copied from interface: EventHandler
Handle the specified event, generated by the EventManager. The event handler pressumably knows how to handle the callback object and should cast it appropriately before using it.

This methodshould not throw any exceptions

Specified by:
handleEvent in interface EventHandler
Following copied from interface: org.exolab.jms.events.EventHandler
Parameters:
event - the event to handle
callback - the callback object
time - the absolute time, in ms, that the event fired.

getConnection

public java.sql.Connection getConnection()
                                  throws PersistenceException
Return a connection to the database from the pool of connections. It will throw an PersistenceException if it cannot retrieve a connection. The client should close the connection normally, since the pool is a connection event listener.
Overrides:
getConnection in class PersistenceAdapter
Returns:
Connection - a pooled connection or null
Throws:
PersistenceException - - if it cannot retrieve a connection

getDBConnectionManager

public DBConnectionManager getDBConnectionManager()
Return a reference to the DBConnectionManager
Returns:
DBConnectionManager

addUser

public void addUser(java.sql.Connection connection,
                    User user)
             throws PersistenceException
Overrides:
addUser in class PersistenceAdapter

getAllUsers

public java.util.Enumeration getAllUsers(java.sql.Connection connection)
                                  throws PersistenceException
Overrides:
getAllUsers in class PersistenceAdapter

getUser

public User getUser(java.sql.Connection connection,
                    User user)
             throws PersistenceException
Overrides:
getUser in class PersistenceAdapter

removeUser

public void removeUser(java.sql.Connection connection,
                       User user)
                throws PersistenceException
Overrides:
removeUser in class PersistenceAdapter

updateUser

public void updateUser(java.sql.Connection connection,
                       User user)
                throws PersistenceException
Overrides:
updateUser in class PersistenceAdapter

purgeMessages

public int purgeMessages()
Incrementally purge all processed messages from the database.
Overrides:
purgeMessages in class PersistenceAdapter
Returns:
the number of messages deleted


Copyright © 1999-2004 The OpenJMS Group. All Rights Reserved.