001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Eric HARDESTY
022: * --------------------------------------------------------------------------
023: * $Id: ConnectionPoolMCFImpl.java 5947 2004-12-14 16:13:51Z ehardesty $
024: * --------------------------------------------------------------------------
025: */
026: package org.objectweb.jonas.jdbc;
027:
028: import java.sql.SQLException;
029:
030: import javax.resource.ResourceException;
031: import javax.resource.spi.ConnectionRequestInfo;
032: import javax.resource.spi.ManagedConnection;
033: import javax.resource.spi.ResourceAllocationException;
034: import javax.resource.spi.security.PasswordCredential;
035: import javax.security.auth.Subject;
036: import javax.sql.ConnectionPoolDataSource;
037:
038: /**
039: * JDBC RA connection pool MCF implmentation
040: * @author Eric Hardesty
041: * Contributor(s):
042: *
043: */
044: public class ConnectionPoolMCFImpl extends ManagedConnectionFactoryImpl {
045:
046: ConnectionPoolDataSource ds = null;
047:
048: public ManagedConnection createManagedConnection(Subject subject,
049: ConnectionRequestInfo cxReq) throws ResourceException {
050:
051: PasswordCredential pc = Utility.getPasswordCredential(this ,
052: subject, cxReq, pw);
053: if (ds == null) {
054: try {
055: ds = (ConnectionPoolDataSource) Utility.getDataSource(
056: this , pc, trace);
057: } catch (Exception ex) {
058: throw new ResourceException(ex.getMessage());
059: }
060: }
061:
062: javax.sql.PooledConnection pConnection = null;
063: java.sql.Connection connection = null;
064: try {
065: if (cxReq != null) {
066: ConnectionRequestInfoImpl cx = (ConnectionRequestInfoImpl) cxReq;
067: pConnection = ds.getPooledConnection(cx.getUser(), cx
068: .getPassword());
069: } else if (pc != null) {
070: pConnection = ds.getPooledConnection(pc.getUserName(),
071: new String(pc.getPassword()));
072: } else if (mcfData.getMCFData(MCFData.USER).length() > 0) {
073: pConnection = ds.getPooledConnection(mcfData
074: .getMCFData(MCFData.USER), mcfData
075: .getMCFData(MCFData.PASSWORD));
076: } else {
077: pConnection = ds.getPooledConnection();
078: }
079: if (pConnection != null) {
080: connection = pConnection.getConnection();
081: }
082: } catch (SQLException sqle) {
083: throw new ResourceAllocationException(
084: "The connection could not be allocated: "
085: + sqle.getMessage());
086: }
087: return new ManagedConnectionImpl(this , pc, connection,
088: pConnection, null, null);
089: }
090:
091: /* Determine if the factories are equal
092: */
093: public boolean equals(Object obj) {
094: if (obj instanceof ConnectionPoolMCFImpl) {
095: return mcfData
096: .equals(((ConnectionPoolMCFImpl) obj).mcfData);
097: } else {
098: return false;
099: }
100: }
101:
102: // JOnAS JDBC RA ConnectionPool config properties
103: public String getDatabaseName() {
104: return mcfData.getMCFData(MCFData.DATABASENAME);
105: }
106:
107: public void setDatabaseName(String val) {
108: mcfData.setMCFData(MCFData.DATABASENAME, val);
109: }
110:
111: public String getDescription() {
112: return mcfData.getMCFData(MCFData.DESCRIPTION);
113: }
114:
115: public void setDescription(String val) {
116: mcfData.setMCFData(MCFData.DESCRIPTION, val);
117: }
118:
119: public String getPortNumber() {
120: return mcfData.getMCFData(MCFData.PORTNUMBER);
121: }
122:
123: public void setPortNumber(String val) {
124: mcfData.setMCFData(MCFData.PORTNUMBER, val);
125: }
126:
127: public String getServerName() {
128: return mcfData.getMCFData(MCFData.SERVERNAME);
129: }
130:
131: public void setServerName(String val) {
132: mcfData.setMCFData(MCFData.SERVERNAME, val);
133: }
134:
135: }
|