Coverage Report - org.mule.providers.oracle.jms.OracleJmsConnection
 
Classes in this File Line Coverage Branch Coverage Complexity
OracleJmsConnection
0%
0/55
0%
0/10
1.688
 
 1  
 /*
 2  
  * $Id: OracleJmsConnection.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.providers.oracle.jms;
 12  
 
 13  
 import java.util.ArrayList;
 14  
 import java.util.Iterator;
 15  
 import java.util.List;
 16  
 
 17  
 import javax.jms.Connection;
 18  
 import javax.jms.ConnectionConsumer;
 19  
 import javax.jms.ConnectionMetaData;
 20  
 import javax.jms.ExceptionListener;
 21  
 import javax.jms.JMSException;
 22  
 import javax.jms.Queue;
 23  
 import javax.jms.QueueConnection;
 24  
 import javax.jms.QueueSession;
 25  
 import javax.jms.ServerSessionPool;
 26  
 import javax.jms.Topic;
 27  
 import javax.jms.TopicConnection;
 28  
 import javax.jms.TopicSession;
 29  
 
 30  
 import oracle.jms.AQjmsConnection;
 31  
 import oracle.jms.AQjmsQueueConnectionFactory;
 32  
 import oracle.jms.AQjmsTopicConnectionFactory;
 33  
 import org.apache.commons.logging.Log;
 34  
 import org.apache.commons.logging.LogFactory;
 35  
 
 36  
 public class OracleJmsConnection implements TopicConnection, QueueConnection
 37  
 {
 38  
 
 39  
     private TopicConnection topicConnection;
 40  
     private QueueConnection queueConnection;
 41  
 
 42  
     /**
 43  
      * Instead of a single JMS Connection, the Oracle JMS Connector maintains a list
 44  
      * of open connections.
 45  
      * 
 46  
      * @see OracleJmsConnector#multipleSessionsPerConnection
 47  
      */
 48  
     private List connections;
 49  
 
 50  
     /**
 51  
      * Holds a reference to the Oracle JMS Connector.
 52  
      */
 53  
     private OracleJmsConnector connector;
 54  
 
 55  
     public OracleJmsConnection(OracleJmsConnector connector)
 56  0
     {
 57  0
         this.connector = connector;
 58  0
         connections = new ArrayList();
 59  0
     }
 60  
 
 61  
     /** Iterate through the open connections and start them one by one. */
 62  
     public void start() throws JMSException
 63  
     {
 64  0
         Connection jmsConnection = null;
 65  
 
 66  0
         for (Iterator i = connections.iterator(); i.hasNext();)
 67  
         {
 68  0
             jmsConnection = (Connection)i.next();
 69  0
             if (jmsConnection != null)
 70  
             {
 71  0
                 jmsConnection.start();
 72  
             }
 73  
         }
 74  0
     }
 75  
 
 76  
     /** Iterate through the open connections and stop them one by one. */
 77  
     public void stop() throws JMSException
 78  
     {
 79  0
         Connection jmsConnection = null;
 80  
 
 81  0
         for (Iterator i = connections.iterator(); i.hasNext();)
 82  
         {
 83  0
             jmsConnection = (Connection)i.next();
 84  0
             if (jmsConnection != null)
 85  
             {
 86  0
                 jmsConnection.stop();
 87  
             }
 88  
         }
 89  0
     }
 90  
 
 91  
     /** Iterate through the open connections and close them one by one. */
 92  
     public void close() throws JMSException
 93  
     {
 94  
         Connection jmsConnection;
 95  
 
 96  
         // Iterate through the open connections
 97  0
         for (Iterator i = connections.iterator(); i.hasNext();)
 98  
         {
 99  0
             jmsConnection = (Connection)i.next();
 100  0
             if (jmsConnection != null)
 101  
             {
 102  
                 try
 103  
                 {
 104  
                     // Close the JMS Session (and its underlying JDBC connection).
 105  0
                     connector.close(((AQjmsConnection)jmsConnection).getCurrentJmsSession());
 106  
                     // Close the JMS Connection.
 107  0
                     jmsConnection.close();
 108  
                 }
 109  0
                 catch (JMSException e)
 110  
                 {
 111  0
                     logger.error("Unable to close Oracle JMS connection: " + e.getMessage());
 112  0
                 }
 113  
             }
 114  
         }
 115  0
     }
 116  
 
 117  
     protected QueueConnection getQueueConnection() throws JMSException
 118  
     {
 119  
         QueueConnection connection;
 120  
 
 121  0
         if (connector.isMultipleSessionsPerConnection())
 122  
         {
 123  0
             if (queueConnection == null)
 124  
             {
 125  0
                 queueConnection = AQjmsQueueConnectionFactory.createQueueConnection(connector.getJdbcConnection());
 126  0
                 queueConnection.start();
 127  
             }
 128  0
             connection = queueConnection;
 129  
         }
 130  
         else
 131  
         {
 132  0
             connection = AQjmsQueueConnectionFactory.createQueueConnection(connector.getJdbcConnection());
 133  0
             connection.start();
 134  
             // Add the connection to the list of open JMS connections.
 135  0
             connections.add(connection);
 136  
         }
 137  0
         return connection;
 138  
     }
 139  
 
 140  
     protected TopicConnection getTopicConnection() throws JMSException
 141  
     {
 142  
         TopicConnection connection;
 143  
 
 144  0
         if (connector.isMultipleSessionsPerConnection())
 145  
         {
 146  0
             if (topicConnection == null)
 147  
             {
 148  0
                 topicConnection = AQjmsTopicConnectionFactory.createTopicConnection(connector.getJdbcConnection());
 149  0
                 topicConnection.start();
 150  
             }
 151  0
             connection = topicConnection;
 152  
         }
 153  
         else
 154  
         {
 155  0
             connection = AQjmsTopicConnectionFactory.createTopicConnection(connector.getJdbcConnection());
 156  0
             connection.start();
 157  
             // Add the connection to the list of open JMS connections.
 158  0
             connections.add(connection);
 159  
         }
 160  0
         connection.start();
 161  0
         return connection;
 162  
     }
 163  
 
 164  
     public QueueSession createQueueSession(boolean transacted, int ackMode) throws JMSException
 165  
     {
 166  0
         return getQueueConnection().createQueueSession(transacted, ackMode);
 167  
     }
 168  
 
 169  
     public TopicSession createTopicSession(boolean transacted, int ackMode) throws JMSException
 170  
     {
 171  0
         return getTopicConnection().createTopicSession(transacted, ackMode);
 172  
     }
 173  
 
 174  
     public ConnectionConsumer createConnectionConsumer(Topic arg0,
 175  
                                                        String arg1,
 176  
                                                        ServerSessionPool arg2,
 177  
                                                        int arg3) throws JMSException
 178  
     {
 179  0
         return getTopicConnection().createConnectionConsumer(arg0, arg1, arg2, arg3);
 180  
     }
 181  
 
 182  
     public ConnectionConsumer createDurableConnectionConsumer(Topic arg0,
 183  
                                                               String arg1,
 184  
                                                               String arg2,
 185  
                                                               ServerSessionPool arg3,
 186  
                                                               int arg4) throws JMSException
 187  
     {
 188  0
         return getTopicConnection().createDurableConnectionConsumer(arg0, arg1, arg2, arg3, arg4);
 189  
     }
 190  
 
 191  
     public ConnectionConsumer createConnectionConsumer(Queue arg0,
 192  
                                                        String arg1,
 193  
                                                        ServerSessionPool arg2,
 194  
                                                        int arg3) throws JMSException
 195  
     {
 196  0
         return getQueueConnection().createConnectionConsumer(arg0, arg1, arg2, arg3);
 197  
     }
 198  
 
 199  
     // TODO How do we know which connection to use?
 200  
     public String getClientID() throws JMSException
 201  
     {
 202  0
         return null;
 203  
     }
 204  
 
 205  
     // TODO How do we know which connection to use?
 206  
     public ExceptionListener getExceptionListener() throws JMSException
 207  
     {
 208  0
         return null;
 209  
     }
 210  
 
 211  
     // TODO How do we know which connection to use?
 212  
     public ConnectionMetaData getMetaData() throws JMSException
 213  
     {
 214  0
         return null;
 215  
     }
 216  
 
 217  
     public void setClientID(String arg0) throws JMSException
 218  
     {
 219  
         // TODO How do we know which connection to use?
 220  0
     }
 221  
 
 222  
     public void setExceptionListener(ExceptionListener arg0) throws JMSException
 223  
     {
 224  
         // TODO How do we know which connection to use?
 225  0
     }
 226  
 
 227  0
     private static Log logger = LogFactory.getLog(OracleJmsConnection.class);
 228  
 }