001: /*-
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005: *
006: * $Id: JEManagedConnectionFactory.java,v 1.9.2.3 2008/01/07 15:14:11 cwl Exp $
007: */
008:
009: package com.sleepycat.je.jca.ra;
010:
011: import java.io.PrintWriter;
012: import java.io.Serializable;
013: import java.util.Iterator;
014: import java.util.Set;
015:
016: import javax.resource.ResourceException;
017: import javax.resource.spi.ConnectionManager;
018: import javax.resource.spi.ConnectionRequestInfo;
019: import javax.resource.spi.ManagedConnection;
020: import javax.resource.spi.ManagedConnectionFactory;
021: import javax.security.auth.Subject;
022:
023: import com.sleepycat.je.DbInternal;
024: import com.sleepycat.je.dbi.EnvironmentImpl;
025:
026: public class JEManagedConnectionFactory implements
027: ManagedConnectionFactory, Serializable {
028:
029: private String userName;
030: private String password;
031:
032: public JEManagedConnectionFactory() {
033: }
034:
035: public Object createConnectionFactory(ConnectionManager cxManager)
036: throws ResourceException {
037:
038: return new JEConnectionFactoryImpl(cxManager, this );
039: }
040:
041: public Object createConnectionFactory() throws ResourceException {
042:
043: throw new UnsupportedOperationException("must supply a connMgr");
044: }
045:
046: public ManagedConnection createManagedConnection(Subject subject,
047: ConnectionRequestInfo info) throws ResourceException {
048:
049: JERequestInfo jeInfo = (JERequestInfo) info;
050: return new JEManagedConnection(subject, jeInfo);
051: }
052:
053: public ManagedConnection matchManagedConnections(Set connectionSet,
054: Subject subject, ConnectionRequestInfo info)
055: throws ResourceException {
056:
057: JERequestInfo jeInfo = (JERequestInfo) info;
058: Iterator iter = connectionSet.iterator();
059: while (iter.hasNext()) {
060: Object next = iter.next();
061: if (next instanceof JEManagedConnection) {
062: JEManagedConnection mc = (JEManagedConnection) next;
063: EnvironmentImpl nextEnvImpl = DbInternal
064: .envGetEnvironmentImpl(mc.getEnvironment());
065: /* Do we need to match on more than root dir and r/o? */
066: if (nextEnvImpl.getEnvironmentHome().equals(
067: jeInfo.getJERootDir())
068: && nextEnvImpl.isReadOnly() == jeInfo
069: .getEnvConfig().getReadOnly()) {
070: return mc;
071: }
072: }
073: }
074: return null;
075: }
076:
077: public void setUserName(String userName) {
078: this .userName = userName;
079: }
080:
081: public String getUserName() {
082: return userName;
083: }
084:
085: public void setPassword(String password) {
086: this .password = password;
087: }
088:
089: public String getPassword() {
090: return password;
091: }
092:
093: public void setLogWriter(PrintWriter out) throws ResourceException {
094:
095: }
096:
097: public PrintWriter getLogWriter() throws ResourceException {
098:
099: return null;
100: }
101:
102: public boolean equals(Object obj) {
103: if (obj == null) {
104: return false;
105: }
106:
107: if (obj instanceof JEManagedConnectionFactory) {
108: return true;
109: } else {
110: return false;
111: }
112: }
113:
114: public int hashCode() {
115: return 0;
116: }
117: }
|