org.exolab.jms.persistence
Class RDBMSAdapter

java.lang.Object
  extended by org.exolab.jms.persistence.PersistenceAdapter
      extended by org.exolab.jms.persistence.RDBMSAdapter
All Implemented Interfaces:
EventHandler

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.6 $ $Date: 2005/08/31 05:45:50 $
Author:
Jim Mourikis

Field Summary
static java.lang.String SCHEMA_VERSION
          The schema version number.
 
Constructor Summary
RDBMSAdapter(org.exolab.jms.config.DatabaseConfiguration dbConfig, java.lang.String driver, java.lang.String url, java.lang.String userName, java.lang.String password)
          Connects to the given db.
 
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, MessageHandle 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.
 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
 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, MessageHandle 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 MessageHandle 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, MessageHandle 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, MessageHandle 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.

See Also:
Constant Field Values
Constructor Detail

RDBMSAdapter

public RDBMSAdapter(org.exolab.jms.config.DatabaseConfiguration dbConfig,
                    java.lang.String driver,
                    java.lang.String url,
                    java.lang.String userName,
                    java.lang.String password)
             throws PersistenceException
Connects to the given db.

Throws:
PersistenceException - if a connection cannot be establised to the database
Method Detail

close

public void close()
Close the database.

Specified by:
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.

Specified by:
getLastId in class 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.

Specified by:
updateIds in class 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.

Specified by:
addMessage in class PersistenceAdapter
Parameters:
connection - the connection to use
message - 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

Specified by:
updateMessage in class PersistenceAdapter
Parameters:
connection - the connection to use
message - the 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.

Specified by:
getUnprocessedMessages in class 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

Specified by:
removeMessage in class PersistenceAdapter
Parameters:
connection - - the connection to use
id - 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.

Specified by:
getMessage in class PersistenceAdapter
Parameters:
connection - - the connection to use
id - 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,
                                    MessageHandle 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

Specified by:
getMessages in class 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,
                             MessageHandle handle)
                      throws PersistenceException
Description copied from class: PersistenceAdapter
Add the specified persistent message handle.

Specified by:
addMessageHandle in class PersistenceAdapter
Parameters:
connection - - the connection to use
handle - - the persistent handle to add
Throws:
PersistenceException

updateMessageHandle

public void updateMessageHandle(java.sql.Connection connection,
                                MessageHandle handle)
                         throws PersistenceException
Description copied from class: PersistenceAdapter
Update the specified persistent message handle.

Specified by:
updateMessageHandle in class PersistenceAdapter
Parameters:
connection - - the connection to use
handle - - the persistent handle to update
Throws:
PersistenceException

removeMessageHandle

public void removeMessageHandle(java.sql.Connection connection,
                                MessageHandle handle)
                         throws PersistenceException
Description copied from class: PersistenceAdapter
Remove the specified persistent message handle.

Specified by:
removeMessageHandle in class PersistenceAdapter
Parameters:
connection - - the connection to use
handle - - the persistent handle to remove
Throws:
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

Specified by:
getMessageHandles in class 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

Specified by:
addDurableConsumer in class PersistenceAdapter
Parameters:
connection - - the connection to use
topic - - the name of the topic
consumer - 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.

Specified by:
removeDurableConsumer in class 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

Specified by:
getDurableConsumers in class 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

Specified by:
getAllDurableConsumers in class 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

Specified by:
durableConsumerExists in class 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.

Specified by:
addDestination in class 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.

Specified by:
removeDestination in class PersistenceAdapter
Parameters:
connection - - the connection to use
name - - 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

Specified by:
getAllDestinations in class 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

Specified by:
checkDestination in class 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

Specified by:
getQueueMessageCount in class 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.

Specified by:
getDurableConsumerMessageCount in class 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.

Specified by:
removeExpiredMessages in class 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.

Specified by:
removeExpiredMessageHandles in class 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 MessageHandle objects, for the specified destination.

Specified by:
getNonExpiredMessages in class PersistenceAdapter
Parameters:
connection - - the connection to use
destination - - the destination in question
Returns:
Vector - collection of unexpired message handles
Throws:
PersistenceException

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.

Specified by:
handleEvent in interface 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.

Specified by:
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
Specified by:
addUser in class PersistenceAdapter
Throws:
PersistenceException

getAllUsers

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

getUser

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

removeUser

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

updateUser

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

purgeMessages

public int purgeMessages()
Incrementally purge all processed messages from the database.

Specified by:
purgeMessages in class PersistenceAdapter
Returns:
the number of messages deleted


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