View Javadoc

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          super();
49      }
50  
51      protected void doInitialise() throws InitialisationException
52      {
53          try
54          {
55              // Register the Oracle JDBC driver.
56              Driver oracleDriver = new OracleDriver();
57              // Deregister first just in case the driver has already been registered.
58              DriverManager.deregisterDriver(oracleDriver);
59              DriverManager.registerDriver(oracleDriver);
60  
61              if (dataSource == null)
62              {
63                  // Since many connections are opened and closed, we use a connection pool to
64                  // obtain the JDBC connection.
65                  dataSource = new OracleDataSource();
66                  ((OracleDataSource) dataSource).setDataSourceName("Mule Oracle AQ Provider");
67                  ((OracleDataSource) dataSource).setUser(username);
68                  ((OracleDataSource) dataSource).setPassword(password);
69                  ((OracleDataSource) dataSource).setURL(url);
70              }
71          }
72          catch (SQLException e)
73          {
74              throw new InitialisationException(e, this);
75          }
76          super.doInitialise();
77      }
78  
79      public java.sql.Connection getJdbcConnection() throws JMSException
80      {
81          try
82          {
83              logger.debug("Getting queue/topic connection");
84              return dataSource.getConnection();
85          }
86          catch (SQLException e)
87          {
88              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          return url;
99      }
100 
101     public void setUrl(String url)
102     {
103         this.url = url;
104     }
105 
106     public DataSource getDataSource()
107     {
108         return dataSource;
109     }
110 
111     public void setDataSource(DataSource dataSource)
112     {
113         this.dataSource = dataSource;
114     }
115 }