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: XAMCFImpl.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.XADataSource;
037:
038: public class XAMCFImpl extends ManagedConnectionFactoryImpl {
039:
040: XADataSource ds = null;
041:
042: public ManagedConnection createManagedConnection(Subject subject,
043: ConnectionRequestInfo cxReq) throws ResourceException {
044:
045: PasswordCredential pc = Utility.getPasswordCredential(this ,
046: subject, cxReq, pw);
047: if (ds == null) {
048: try {
049: ds = (XADataSource) Utility.getDataSource(this , pc,
050: trace);
051: } catch (Exception ex) {
052: throw new ResourceException(ex.getMessage());
053: }
054: }
055: javax.sql.XAConnection xaConnection = null;
056: java.sql.Connection connection = null;
057: try {
058: if (cxReq != null) {
059: ConnectionRequestInfoImpl cx = (ConnectionRequestInfoImpl) cxReq;
060: xaConnection = ds.getXAConnection(cx.getUser(), cx
061: .getPassword());
062: } else if (pc != null) {
063: xaConnection = ds.getXAConnection(pc.getUserName(),
064: new String(pc.getPassword()));
065: } else if (mcfData.getMCFData(MCFData.USER).length() > 0) {
066: xaConnection = ds.getXAConnection(mcfData
067: .getMCFData(MCFData.USER), mcfData
068: .getMCFData(MCFData.PASSWORD));
069: } else {
070: xaConnection = ds.getXAConnection();
071: }
072: if (xaConnection != null) {
073: connection = xaConnection.getConnection();
074: }
075: } catch (SQLException sqle) {
076: throw new ResourceAllocationException(
077: "The connection could not be allocated: "
078: + sqle.getMessage());
079: }
080: return new ManagedConnectionImpl(this , pc, connection, null,
081: xaConnection, null);
082: }
083:
084: /* Determine if the factories are equal
085: */
086: public boolean equals(Object obj) {
087: if (obj instanceof XAMCFImpl) {
088: return mcfData.equals(((XAMCFImpl) obj).mcfData);
089: } else {
090: return false;
091: }
092: }
093:
094: // JOnAS JDBC RA DataSource config properties
095: public String getDatabaseName() {
096: return mcfData.getMCFData(MCFData.DATABASENAME);
097: }
098:
099: public void setDatabaseName(String val) {
100: mcfData.setMCFData(MCFData.DATABASENAME, val);
101: }
102:
103: public String getDescription() {
104: return mcfData.getMCFData(MCFData.DESCRIPTION);
105: }
106:
107: public void setDescription(String val) {
108: mcfData.setMCFData(MCFData.DESCRIPTION, val);
109: }
110:
111: public String getPortNumber() {
112: return mcfData.getMCFData(MCFData.PORTNUMBER);
113: }
114:
115: public void setPortNumber(String val) {
116: mcfData.setMCFData(MCFData.PORTNUMBER, val);
117: }
118:
119: public String getServerName() {
120: return mcfData.getMCFData(MCFData.SERVERNAME);
121: }
122:
123: public void setServerName(String val) {
124: mcfData.setMCFData(MCFData.SERVERNAME, val);
125: }
126:
127: }
|