1 46 47 package org.mr.ra; 48 49 import org.apache.commons.logging.Log; 50 import org.apache.commons.logging.LogFactory; 51 52 import javax.resource.ResourceException ; 53 import javax.resource.spi.ConnectionEvent ; 54 import javax.resource.spi.ConnectionEventListener ; 55 import javax.resource.spi.ConnectionManager ; 56 import javax.resource.spi.ConnectionRequestInfo ; 57 import javax.resource.spi.ManagedConnection ; 58 import javax.resource.spi.ManagedConnectionFactory ; 59 import javax.security.auth.Subject ; 60 61 62 68 public class ConnectionManagerImpl 69 implements ConnectionManager , ConnectionEventListener 70 { 71 private static final long serialVersionUID = 3257291335445918769L; 72 private static final Log log = LogFactory.getLog(ConnectionManagerImpl.class); 73 74 75 81 84 public Object allocateConnection(ManagedConnectionFactory connectionFactory, ConnectionRequestInfo info) throws ResourceException { 85 Subject subject = null; 86 ManagedConnection connection = connectionFactory.createManagedConnection(subject, info); 87 connection.addConnectionEventListener(this); 88 return connection.getConnection(subject, info); 89 } 90 91 92 98 101 public void connectionClosed(ConnectionEvent event) { 102 try { 103 ((ManagedConnection ) event.getSource()).cleanup(); 104 } 105 catch (ResourceException e) { 106 log.warn("Error occured during the cleanup of a managed connection: ", e); 107 } 108 try { 109 ((ManagedConnection ) event.getSource()).destroy(); 110 } 111 catch (ResourceException e) { 112 log.warn("Error occured during the destruction of a managed connection: ", e); 113 } 114 } 115 116 119 public void localTransactionStarted(ConnectionEvent event) { 120 } 121 122 125 public void localTransactionCommitted(ConnectionEvent event) { 126 } 127 128 131 public void localTransactionRolledback(ConnectionEvent event) { 132 } 133 134 137 public void connectionErrorOccurred(ConnectionEvent event) { 138 log.warn("Managed connection experiened an error: ", event.getException()); 139 try { 140 ((ManagedConnection ) event.getSource()).cleanup(); 141 } 142 catch (ResourceException e) { 143 log.warn("Error occured during the cleanup of a managed connection: ", e); 144 } 145 try { 146 ((ManagedConnection ) event.getSource()).destroy(); 147 } 148 catch (ResourceException e) { 149 log.warn("Error occured during the destruction of a managed connection: ", e); 150 } 151 } 152 153 } 154 | Popular Tags |