View Javadoc

1   /*
2    * $Id: OracleJmsConnector.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 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  
21  import oracle.jdbc.driver.OracleDriver;
22  import oracle.jdbc.pool.OracleDataSource;
23  
24  /**
25   * Extends the standard Mule JMS Provider with functionality specific to Oracle's JMS
26   * implementation based on Advanced Queueing (Oracle AQ).
27   * 
28   * @see OracleJmsSupport
29   * @see org.mule.providers.jms.JmsConnector
30   * @see <a href="http://otn.oracle.com/pls/db102/">Streams Advanced Queuing</a>
31   */
32  public class OracleJmsConnector extends AbstractOracleJmsConnector
33  {
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       * Since many connections are opened and closed, we use a connection pool to
43       * obtain the JDBC connection.
44       */
45      private OracleDataSource jdbcConnectionPool = null;
46  
47      public OracleJmsConnector()
48      {
49          super();
50  
51      }
52  
53      protected void doInitialise() throws InitialisationException
54      {
55          try
56          {
57              // Register the Oracle JDBC driver.
58              Driver oracleDriver = new OracleDriver();
59              // Deregister first just in case the driver has already been registered.
60              DriverManager.deregisterDriver(oracleDriver);
61              DriverManager.registerDriver(oracleDriver);
62  
63              jdbcConnectionPool = new OracleDataSource();
64              jdbcConnectionPool.setDataSourceName("Mule Oracle AQ Provider");
65              jdbcConnectionPool.setUser(username);
66              jdbcConnectionPool.setPassword(password);
67              jdbcConnectionPool.setURL(url);
68  
69          }
70          catch (SQLException e)
71          {
72              throw new InitialisationException(e, this);
73          }
74          super.doInitialise();
75      }
76  
77      public java.sql.Connection getJdbcConnection() throws JMSException
78      {
79          try
80          {
81              logger.debug("Getting queue/topic connection from pool, URL = "
82                           + getJdbcConnectionPool().getURL() + ", user = " + getJdbcConnectionPool().getUser());
83              return getJdbcConnectionPool().getConnection();
84          }
85          catch (SQLException e)
86          {
87              throw new JMSException("Unable to open JDBC connection: " + e.getMessage());
88          }
89      }
90  
91      public String getUrl()
92      {
93          return url;
94      }
95  
96      public void setUrl(String url)
97      {
98          this.url = url;
99      }
100 
101     public OracleDataSource getJdbcConnectionPool()
102     {
103         return jdbcConnectionPool;
104     }
105 
106 }