1 package org.apache.ojb.otm.connector; 2 3 17 18 import org.apache.ojb.broker.PBKey; 19 import org.apache.ojb.otm.Kit; 20 import org.apache.ojb.otm.OTMConnection; 21 import org.apache.ojb.otm.kit.SimpleKit; 22 23 import javax.resource.ResourceException ; 24 import javax.resource.spi.ConnectionManager ; 25 import javax.resource.spi.ConnectionRequestInfo ; 26 import javax.resource.spi.ManagedConnection ; 27 import javax.resource.spi.ManagedConnectionFactory ; 28 import javax.security.auth.Subject ; 29 import java.io.PrintWriter ; 30 import java.io.Serializable ; 31 import java.sql.DriverManager ; 32 import java.util.Iterator ; 33 import java.util.Set ; 34 35 39 40 public class OTMJCAManagedConnectionFactory 41 implements ManagedConnectionFactory , Serializable 42 { 43 private Kit m_kit; 44 45 private synchronized void initialize() 46 { 47 if (m_kit == null) 48 { 49 m_kit = SimpleKit.getInstance(); 50 } 51 } 52 53 public Kit getKit() throws ResourceException 54 { 55 initialize(); 56 return m_kit; 57 } 58 59 public OTMJCAManagedConnectionFactory() 60 { 61 Util.log("In OTMJCAManagedConnectionFactory.constructor"); 62 } 63 64 public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException 65 { 66 Util.log("In OTMJCAManagedConnectionFactory.createConnectionFactory,1"); 67 return new JCAKit(this, cxManager); 68 } 69 70 public Object createConnectionFactory() throws ResourceException 71 { 72 Util.log("In OTMJCAManagedConnectionFactory.createManagedFactory,2"); 73 return new JCAKit(this, null); 74 } 75 76 83 public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo info) 84 { 85 Util.log("In OTMJCAManagedConnectionFactory.createManagedConnection"); 86 try 87 { 88 Kit kit = getKit(); 89 PBKey key = ((OTMConnectionRequestInfo) info).getPbKey(); 90 OTMConnection connection = kit.acquireConnection(key); 91 return new OTMJCAManagedConnection(this, connection, key); 92 } 93 catch (ResourceException e) 94 { 95 throw new OTMConnectionRuntimeException(e.getMessage()); 96 } 97 } 98 99 public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo info) 100 throws ResourceException 101 { 102 Util.log("OTMJCAManagedConnectionFactory::matchManagedConnections called with " + connectionSet.size() + " connections."); 103 for (Iterator i = connectionSet.iterator(); i.hasNext();) 104 { 105 Object o = i.next(); 106 if (o instanceof OTMJCAManagedConnection) 107 { 108 return (OTMJCAManagedConnection) o; 110 } 111 } 112 Util.log("OTMJCAManagedConnectionFactory::No matched connections"); 113 return null; 114 } 115 116 public void setLogWriter(PrintWriter out) throws ResourceException 117 { 118 Util.log("In OTMJCAManagedConnectionFactory.setLogWriter"); 119 } 120 121 public PrintWriter getLogWriter() throws ResourceException 122 { 123 Util.log("In OTMJCAManagedConnectionFactory.getLogWriter"); 124 return DriverManager.getLogWriter(); 125 } 126 127 public boolean equals(Object obj) 128 { 129 if (obj == null) 130 return false; 131 if (obj instanceof OTMJCAManagedConnectionFactory) 132 { 133 int hash1 = ((OTMJCAManagedConnectionFactory) obj).hashCode(); 134 int hash2 = hashCode(); 135 return hash1 == hash2; 136 } 137 else 138 { 139 return false; 140 } 141 } 142 143 public int hashCode() 144 { 145 return 1; 146 } 147 } 148 | Popular Tags |