1 23 24 package com.sun.enterprise.resource; 25 26 import com.sun.enterprise.log.Log; 27 import com.sun.enterprise.PoolManager; 28 import com.sun.enterprise.deployment.ConnectorDescriptor; 29 30 import javax.resource.spi.*; 31 import javax.resource.ResourceException ; 32 import javax.security.auth.Subject ; 33 import java.util.logging.*; 34 import java.lang.IllegalStateException ; 35 36 39 public class NoTxConnectorAllocator extends AbstractConnectorAllocator { 40 41 class ConnectionListenerImpl implements ConnectionEventListener { 42 private ResourceHandle resource; 43 44 public ConnectionListenerImpl(ResourceHandle resource) { 45 this.resource = resource; 46 } 47 48 public void connectionClosed(ConnectionEvent evt) { 49 poolMgr.putbackResourceToPool(resource, false); 50 } 51 52 public void connectionErrorOccurred(ConnectionEvent evt) { 53 ManagedConnection mc = (ManagedConnection) evt.getSource(); 54 mc.removeConnectionEventListener(this); 55 poolMgr.putbackResourceToPool(resource, true); 56 try { 57 mc.destroy(); 58 } catch (ResourceException ex) { 59 } 61 resource.setConnectionErrorOccurred(); 63 } 64 65 public void localTransactionStarted(ConnectionEvent evt) { 66 throw new IllegalStateException ("local transaction not supported"); 67 } 68 69 public void localTransactionCommitted(ConnectionEvent evt) { 70 throw new IllegalStateException ("local transaction not supported"); 71 } 72 73 public void localTransactionRolledback(ConnectionEvent evt) { 74 throw new IllegalStateException ("local transaction not supported"); 75 } 76 } 77 78 public NoTxConnectorAllocator(PoolManager poolMgr, 79 ManagedConnectionFactory mcf, 80 ResourceSpec spec, 81 Subject subject, 82 ConnectionRequestInfo reqInfo, 83 ClientSecurityInfo info, 84 ConnectorDescriptor desc) { 85 super(poolMgr, mcf, spec, subject, reqInfo, info, desc); 86 } 87 88 89 public ResourceHandle createResource() 90 throws PoolingException { 91 try { 92 ManagedConnection mc = 93 mcf.createManagedConnection(subject, reqInfo); 94 ResourceHandle resource = 95 new ResourceHandle(mc, spec, this, info); 96 ConnectionEventListener l = 97 new ConnectionListenerImpl(resource); 98 mc.addConnectionEventListener(l); 99 return resource; 100 } catch (ResourceException ex) { 101 _logger.log(Level.SEVERE,"poolmgr.create_resource_error",ex); 102 103 if (ex.getLinkedException() != null) { 104 _logger.log(Level.SEVERE,"poolmgr.create_resource_error",ex.getLinkedException()); 105 } 106 Log.err.flush(); 107 throw new PoolingException(ex); 108 } 109 } 110 111 public void fillInResourceObjects(ResourceHandle resource) 112 throws PoolingException { 113 try { 114 ManagedConnection mc = (ManagedConnection) resource.getResource(); 115 Object con = mc.getConnection(subject, reqInfo); 116 resource.fillInResourceObjects(con, null); 117 } catch (ResourceException ex) { 118 throw new PoolingException(ex); 119 } 120 } 121 122 public void destroyResource(ResourceHandle resource) 123 throws PoolingException { 124 125 try { 126 ManagedConnection mc = (ManagedConnection) resource.getResource(); 127 mc.destroy(); 128 } catch (Exception ex) { 129 _logger.log(Level.WARNING, ex.getMessage()); 130 throw new PoolingException(ex); 131 } 132 } 133 134 public boolean isTransactional() { 135 return false; 136 } 137 } 138 | Popular Tags |