Coverage Report - org.mule.providers.oracle.jms.OracleJmsConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
OracleJmsConnector
69%
18/26
100%
2/2
1.857
 
 1  
 /*
 2  
  * $Id: OracleJmsConnector.java 10464 2008-01-22 19:36:24Z tcarlson $
 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 org.mule.umo.lifecycle.InitialisationException;
 14  
 
 15  
 import java.sql.Driver;
 16  
 import java.sql.DriverManager;
 17  
 import java.sql.SQLException;
 18  
 
 19  
 import javax.jms.JMSException;
 20  
 import javax.sql.DataSource;
 21  
 
 22  
 import oracle.jdbc.driver.OracleDriver;
 23  
 import oracle.jdbc.pool.OracleDataSource;
 24  
 
 25  
 /**
 26  
  * Extends the standard Mule JMS Provider with functionality specific to Oracle's JMS
 27  
  * implementation based on Advanced Queueing (Oracle AQ).
 28  
  * 
 29  
  * @see OracleJmsSupport
 30  
  * @see org.mule.providers.jms.JmsConnector
 31  
  * @see <a href="http://otn.oracle.com/pls/db102/">Streams Advanced Queuing</a>
 32  
  */
 33  
 public class OracleJmsConnector extends AbstractOracleJmsConnector
 34  
 {
 35  
     /**
 36  
      * The JDBC URL for the Oracle database. For example,
 37  
      * {@code jdbc:oracle:oci:@myhost}
 38  
      */
 39  
     private String url;
 40  
 
 41  
     /**
 42  
      * DataSource used to obtain JDBC connections to the Oracle database.
 43  
      */
 44  
     private DataSource dataSource;
 45  
 
 46  
     public OracleJmsConnector()
 47  
     {
 48  30
         super();
 49  30
     }
 50  
 
 51  
     protected void doInitialise() throws InitialisationException
 52  
     {
 53  
         try
 54  
         {
 55  
             // Register the Oracle JDBC driver.
 56  30
             Driver oracleDriver = new OracleDriver();
 57  
             // Deregister first just in case the driver has already been registered.
 58  30
             DriverManager.deregisterDriver(oracleDriver);
 59  30
             DriverManager.registerDriver(oracleDriver);
 60  
 
 61  30
             if (dataSource == null)
 62  
             {
 63  
                 // Since many connections are opened and closed, we use a connection pool to
 64  
                 // obtain the JDBC connection.
 65  16
                 dataSource = new OracleDataSource();
 66  16
                 ((OracleDataSource) dataSource).setDataSourceName("Mule Oracle AQ Provider");
 67  16
                 ((OracleDataSource) dataSource).setUser(username);
 68  16
                 ((OracleDataSource) dataSource).setPassword(password);
 69  16
                 ((OracleDataSource) dataSource).setURL(url);
 70  
             }
 71  
         }
 72  0
         catch (SQLException e)
 73  
         {
 74  0
             throw new InitialisationException(e, this);
 75  30
         }
 76  30
         super.doInitialise();
 77  30
     }
 78  
 
 79  
     public java.sql.Connection getJdbcConnection() throws JMSException
 80  
     {
 81  
         try
 82  
         {
 83  0
             logger.debug("Getting queue/topic connection");
 84  0
             return dataSource.getConnection();
 85  
         }
 86  0
         catch (SQLException e)
 87  
         {
 88  0
             throw new JMSException("Unable to open JDBC connection: " + e.getMessage());
 89  
         }
 90  
     }
 91  
 
 92  
     ////////////////////////////////////////////////////////////////////////////////////
 93  
     // Getters and Setters
 94  
     ////////////////////////////////////////////////////////////////////////////////////
 95  
     
 96  
     public String getUrl()
 97  
     {
 98  0
         return url;
 99  
     }
 100  
 
 101  
     public void setUrl(String url)
 102  
     {
 103  16
         this.url = url;
 104  16
     }
 105  
 
 106  
     public DataSource getDataSource()
 107  
     {
 108  0
         return dataSource;
 109  
     }
 110  
 
 111  
     public void setDataSource(DataSource dataSource)
 112  
     {
 113  14
         this.dataSource = dataSource;
 114  14
     }
 115  
 }