1 22 package org.jboss.test.jca.adapter; 23 24 import java.io.PrintWriter ; 25 import java.net.URL ; 26 import java.util.Collection ; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 import java.util.Set ; 30 import javax.resource.ResourceException ; 31 import javax.resource.spi.ConnectionManager ; 32 import javax.resource.spi.ConnectionRequestInfo ; 33 import javax.resource.spi.ManagedConnection ; 34 import javax.resource.spi.ManagedConnectionFactory ; 35 import javax.security.auth.Subject ; 36 37 import org.jboss.logging.Logger; 38 39 import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt; 40 41 48 public class TestManagedConnectionFactory implements ManagedConnectionFactory 49 { 50 51 private static final long serialVersionUID = 1L; 52 53 private Logger log = Logger.getLogger(TestManagedConnectionFactory.class); 54 55 SynchronizedInt id = new SynchronizedInt(0); 57 58 String failure; 59 60 boolean failJoin; 61 62 long sleepInStart; 63 64 long sleepInEnd; 65 66 Map xids = new WrapperMap(new HashMap ()); 67 68 public TestManagedConnectionFactory() 69 { 70 } 71 72 public void setFailure(String failure) 73 { 74 this.failure = failure; 75 } 76 77 public boolean getFailJoin() 78 { 79 return failJoin; 80 } 81 82 public void setFailJoin(boolean failJoin) 83 { 84 this.failJoin = failJoin; 85 } 86 87 public long getSleepInStart() 88 { 89 return sleepInStart; 90 } 91 92 public void setSleepInStart(long sleep) 93 { 94 this.sleepInStart = sleep; 95 } 96 97 public long getSleepInEnd() 98 { 99 return sleepInEnd; 100 } 101 102 public void setSleepInEnd(long sleep) 103 { 104 this.sleepInEnd = sleep; 105 } 106 107 109 public int hashCode() 110 { 111 return getClass().hashCode(); 112 } 113 114 public boolean equals(Object other) 115 { 116 return (other != null) && (other.getClass() == getClass()); 117 } 118 119 public void setLogWriter(PrintWriter param1) throws ResourceException 120 { 121 } 122 123 public PrintWriter getLogWriter() throws ResourceException 124 { 125 return null; 126 } 127 128 public Object createConnectionFactory(ConnectionManager cm) throws ResourceException 129 { 130 return new TestConnectionFactory(cm, this); 131 } 132 133 public Object createConnectionFactory() throws ResourceException 134 { 135 throw new ResourceException ("not yet implemented"); 136 } 137 138 public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException 139 { 140 if (failure != null && failure.equals("createManagedConnectionResource")) 141 throw new ResourceException (""); 142 if (failure != null && failure.equals("createManagedConnectionRuntime")) 143 throw new RuntimeException (""); 144 return new TestManagedConnection(this, subject, (TestConnectionRequestInfo)cri, id.increment()); 145 } 146 147 public ManagedConnection matchManagedConnections(Set candidates, Subject subject, ConnectionRequestInfo cri) throws ResourceException 148 { 149 if (failure != null && failure.equals("matchManagedConnectionResource")) 150 throw new ResourceException (""); 151 if (failure != null && failure.equals("matchManagedConnectionRuntime")) 152 throw new RuntimeException (""); 153 if (candidates.isEmpty()) 154 return null; 155 return (ManagedConnection )candidates.iterator().next(); 156 } 157 158 Integer integerProperty; 159 160 public Integer getIntegerProperty() 161 { 162 return integerProperty; 163 } 164 165 170 public void setIntegerProperty(Integer integerProperty) 171 { 172 this.integerProperty = integerProperty; 173 } 174 175 Integer defaultIntegerProperty; 176 177 182 public Integer getDefaultIntegerProperty() 183 { 184 return defaultIntegerProperty; 185 } 186 187 192 public void setDefaultIntegerProperty(Integer defaultIntegerProperty) 193 { 194 this.defaultIntegerProperty = defaultIntegerProperty; 195 } 196 197 Boolean booleanProperty; 198 199 204 public Boolean getBooleanProperty() 205 { 206 return booleanProperty; 207 } 208 209 214 public void setBooleanProperty(Boolean booleanProperty) 215 { 216 this.booleanProperty = booleanProperty; 217 } 218 219 Long longProperty; 220 221 226 public Long getLongProperty() 227 { 228 return longProperty; 229 } 230 231 236 public void setLongProperty(Long longProperty) 237 { 238 this.longProperty = longProperty; 239 } 240 241 Double doubleProperty; 242 243 248 public Double getDoubleProperty() 249 { 250 return doubleProperty; 251 } 252 253 258 public void setDoubleProperty(Double doubleProperty) 259 { 260 this.doubleProperty = doubleProperty; 261 } 262 263 URL urlProperty; 264 265 270 public URL getUrlProperty() 271 { 272 return urlProperty; 273 } 274 275 280 public void setUrlProperty(URL urlProperty) 281 { 282 this.urlProperty = urlProperty; 283 } 284 285 Map getXids() 286 { 287 return xids; 288 } 289 290 public class WrapperMap implements Map 291 { 292 Map delegate; 293 294 public WrapperMap(Map delegate) 295 { 296 this.delegate = delegate; 297 } 298 299 public void clear() 300 { 301 delegate.clear(); 302 } 303 304 public boolean containsKey(Object key) 305 { 306 return delegate.containsKey(key); 307 } 308 309 public boolean containsValue(Object value) 310 { 311 return delegate.containsValue(value); 312 } 313 314 public Set entrySet() 315 { 316 return delegate.entrySet(); 317 } 318 319 public Object get(Object key) 320 { 321 return delegate.get(key); 322 } 323 324 public boolean isEmpty() 325 { 326 return delegate.isEmpty(); 327 } 328 329 public Set keySet() 330 { 331 return delegate.keySet(); 332 } 333 334 public Object put(Object key, Object value) 335 { 336 Object result = delegate.put(key, value); 337 log.info("Change xid=" + key + " from " + result + " to " + value); 338 return result; 339 } 340 341 public void putAll(Map t) 342 { 343 delegate.putAll(t); 344 } 345 346 public Object remove(Object key) 347 { 348 return delegate.remove(key); 349 } 350 351 public int size() 352 { 353 return delegate.size(); 354 } 355 356 public Collection values() 357 { 358 return delegate.values(); 359 } 360 } 361 } 362 | Popular Tags |