KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > oracle > jms > OracleJmsConnector


1 /*
2  * $Id: OracleJmsConnector.java 4219 2006-12-09 10:15:14Z lajos $
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 MuleSource MPL
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 oracle.jdbc.pool.OracleDataSource;
14 import oracle.jdbc.driver.OracleDriver;
15 import org.mule.umo.lifecycle.InitialisationException;
16
17 import javax.jms.JMSException JavaDoc;
18 import java.sql.Driver JavaDoc;
19 import java.sql.DriverManager JavaDoc;
20 import java.sql.SQLException JavaDoc;
21
22 /**
23  * Extends the standard Mule JMS Provider with functionality specific to Oracle's JMS
24  * implementation based on Advanced Queueing (Oracle AQ).
25  *
26  * @author <a HREF="mailto:carlson@hotpop.com">Travis Carlson</a>
27  * @author henks
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 JavaDoc 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     public 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 JavaDoc e)
71         {
72             throw new InitialisationException(e, this);
73         }
74         super.doInitialise();
75     }
76
77     public java.sql.Connection JavaDoc getJdbcConnection() throws JMSException JavaDoc
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 JavaDoc e)
86         {
87             throw new JMSException JavaDoc("Unable to open JDBC connection: " + e.getMessage());
88         }
89     }
90
91     public String JavaDoc getUrl()
92     {
93         return url;
94     }
95
96     public void setUrl(String JavaDoc url)
97     {
98         this.url = url;
99     }
100
101     public OracleDataSource getJdbcConnectionPool()
102     {
103         return jdbcConnectionPool;
104     }
105
106 }
107
Popular Tags