1 16 17 package org.springframework.jca.cci.connection; 18 19 import javax.resource.ResourceException ; 20 import javax.resource.cci.Connection ; 21 import javax.resource.cci.ConnectionSpec ; 22 23 63 public class ConnectionSpecConnectionFactoryAdapter extends DelegatingConnectionFactory { 64 65 private ConnectionSpec connectionSpec; 66 67 private final ThreadLocal threadBoundSpec = new ThreadLocal (); 68 69 70 74 public void setConnectionSpec(ConnectionSpec connectionSpec) { 75 this.connectionSpec = connectionSpec; 76 } 77 78 86 public void setConnectionSpecForCurrentThread(ConnectionSpec spec) { 87 this.threadBoundSpec.set(spec); 88 } 89 90 95 public void removeConnectionSpecFromCurrentThread() { 96 this.threadBoundSpec.set(null); 97 } 98 99 100 106 public final Connection getConnection() throws ResourceException { 107 ConnectionSpec threadSpec = (ConnectionSpec ) this.threadBoundSpec.get(); 108 if (threadSpec != null) { 109 return doGetConnection(threadSpec); 110 } 111 else { 112 return doGetConnection(this.connectionSpec); 113 } 114 } 115 116 126 protected Connection doGetConnection(ConnectionSpec spec) throws ResourceException { 127 if (getTargetConnectionFactory() == null) { 128 throw new IllegalStateException ("targetConnectionFactory is required"); 129 } 130 if (spec != null) { 131 return getTargetConnectionFactory().getConnection(spec); 132 } 133 else { 134 return getTargetConnectionFactory().getConnection(); 135 } 136 } 137 138 } 139 | Popular Tags |