1 8 package ersatz.resourceadapter; 9 10 import javax.naming.Reference; 11 import javax.naming.NamingException; 12 import javax.resource.ResourceException; 13 import javax.resource.NotSupportedException; 14 import javax.resource.spi.ConnectionManager; 15 import javax.resource.cci.ConnectionFactory; 17 import javax.resource.cci.Connection; 18 import javax.resource.cci.ConnectionSpec; import javax.resource.cci.RecordFactory; 20 import javax.resource.cci.ResourceAdapterMetaData; 21 import java.io.Serializable; 22 import javax.resource.Referenceable; 23 29 public class ConnectionFactoryImpl implements ConnectionFactory, 30 Referenceable, Serializable 31 32 { 33 Reference reference; 34 private ConnectionManager cm; 35 private ManagedConnectionFactoryImpl mcf; private ConnectionSpecImpl cs; protected boolean managed = true; 38 private String userName = ""; 39 private String passWord = ""; 40 String cName = "ConnectionFactoryImpl"; 41 42 public ConnectionFactoryImpl() { 46 } 47 public ConnectionFactoryImpl(ManagedConnectionFactoryImpl mcf, ConnectionManager cm) { 48 this.mcf=mcf; 49 this.cm=cm; 50 51 } 52 public Connection getConnection() 60 throws ResourceException 61 { 62 Utility.log(cName+".getConnection"+" (Container Managed Sign-on)"); 63 ConnectionImpl conn = null; 64 try { 65 conn = (ConnectionImpl)getConnection(null); 66 return conn; 67 } catch (ResourceException ex) { 68 throw ex; 69 } 70 } 71 public Connection getConnection(ConnectionSpec connectionspec) 79 throws ResourceException 80 { 81 ConnectionImpl conn = null; 82 ConnectionSpecImpl cs = null; 83 ConnectionRequestInfoImpl jcri=null; 85 if (connectionspec==null) { 86 mcf.setRes_Auth("Container"); 87 Utility.log(cName+".getConnection detected res-auth='"+mcf.getRes_Auth()+"'"); 88 } else { 91 mcf.setRes_Auth("Application"); 92 Utility.log(cName+".getConnection detected res-auth='"+mcf.getRes_Auth()+"'"); 93 cs = (ConnectionSpecImpl)connectionspec; 94 jcri = new ConnectionRequestInfoImpl(); 96 jcri.setUserName(cs.getUserName()); 97 jcri.setPassword(cs.getPassword()); 98 99 } 100 Utility.log(cName+".getConnection calling cm.allocateConnection"); 101 try { 102 conn = (ConnectionImpl)cm.allocateConnection(mcf, jcri); 103 if (conn==null) { 104 Utility.log(cName+". getConnection, cm.allocateConnection" 105 +" error: Null connection object returned"); 106 throw new ResourceException("Null connection object returned by allocateConnection"); 107 } 108 conn.crii=jcri; 109 return conn; 110 } catch (IllegalStateException is) { 111 Utility.log(cName+".getConnection IllegalStateException"+is); 112 throw is; 113 } catch (ResourceException re) { 114 Utility.log(cName+".getConnection ResourceException="+re); 115 throw re; 116 } 117 } 118 119 public RecordFactory getRecordFactory() 120 throws ResourceException 121 { 122 NotSupportedException nse = new NotSupportedException( 123 "RecordFactory is not currently supported"); 124 Utility.log(cName+".getRecordFactory "+nse); 125 throw nse; 126 } 127 128 public ResourceAdapterMetaData getMetaData() 129 throws ResourceException 130 { 131 Utility.log(cName+".getMetaData"); 132 ResourceAdapterMetaData rd = null; return rd; 134 } 135 public ConnectionManager getCM() { 136 return cm; 137 } 138 public ManagedConnectionFactoryImpl getMcf() { 139 return mcf; 140 } 141 149 public void setReference(javax.naming.Reference ref) 150 { 151 this.reference = ref; 152 } 153 154 157 public Reference getReference() 158 throws NamingException 159 { 160 return reference; 161 } 162 } 163 | Popular Tags |