1 23 24 package org.objectweb.speedo.jca; 25 26 import org.objectweb.util.monolog.api.BasicLevel; 27 import org.objectweb.util.monolog.api.Logger; 28 import org.objectweb.speedo.api.Debug; 29 import org.objectweb.speedo.api.SpeedoProperties; 30 31 import javax.naming.NamingException ; 32 import javax.naming.Reference ; 33 import javax.resource.NotSupportedException ; 34 import javax.resource.ResourceException ; 35 import javax.resource.cci.Connection ; 36 import javax.resource.cci.ConnectionFactory ; 37 import javax.resource.cci.ConnectionSpec ; 38 import javax.resource.cci.RecordFactory ; 39 import javax.resource.cci.ResourceAdapterMetaData ; 40 import javax.resource.spi.ConnectionManager ; 41 import javax.resource.spi.ConnectionRequestInfo ; 42 import javax.jdo.datastore.DataStoreCache; 43 import javax.jdo.listener.InstanceLifecycleListener; 44 import javax.jdo.PersistenceManagerFactory; 45 import javax.jdo.PersistenceManager; 46 import javax.jdo.JDOException; 47 import java.util.Properties ; 48 import java.util.Collection ; 49 50 53 public class JdoConnectionFactory 54 implements ConnectionFactory , ResourceAdapterMetaData , 55 PersistenceManagerFactory { 56 59 private Logger logger; 60 63 private final static String JDOADAPTERVERSION = "1.00"; 64 67 private final static String JDOADAPTERVENDORNAME = "The ObjectWeb Consortium"; 68 71 private final static String JDOADAPTERNAME = "OW Java Data Object (JDO) Adapter"; 72 75 private final static String JDOADAPTERSHORTDESCRIPTION = "It provides a JCA wrapper to any JDO compliant implementation."; 76 79 private final static String JDOSPECVERSION = "1.00"; 80 81 84 private Reference jndiReference = null; 85 88 private ConnectionManager connectionManager = null; 89 92 private JdoManagedConnectionFactory mcf; 93 94 97 private byte transactionMode = SpeedoProperties.TRANSACTION_BMODE_NORMAL; 98 99 108 JdoConnectionFactory(Logger logger, 109 JdoManagedConnectionFactory fmcf, 110 ConnectionManager cm, 111 byte transactionMode) throws ResourceException { 112 this.logger = logger; 113 if (Debug.ON) 114 logger.log(BasicLevel.DEBUG, 115 "Constructs a new JdoConnectionFactory."); 116 mcf = fmcf; 117 setConnectionManager(cm); 118 this.transactionMode = transactionMode; 119 } 120 121 124 JdoConnection createConnection() throws ResourceException { 125 JdoConnection res = new JdoConnection(logger, this); 126 if (Debug.ON) 127 logger.log(BasicLevel.DEBUG, "New JdoConnection created: " + res); 128 return res; 129 } 130 131 private void checkMCFStarted() { 132 if (!mcf.started) { 133 try { 134 mcf.start(); 135 } catch (ResourceException e) { 136 throw new JDOException("JDO Connector: cannot initialize the ManagedConnectionFactory.", e); 137 } 138 } 139 } 140 141 public void setConnectionManager(ConnectionManager connectionManager) { 142 if (connectionManager != null) { 143 logger.log(BasicLevel.DEBUG, 144 "Linked the ConnectionFactory to the ConnectionManager: " 145 + connectionManager); 146 } 147 this.connectionManager = connectionManager; 148 } 149 150 152 156 public Connection getConnection() throws ResourceException { 157 if (!mcf.started) { 158 mcf.start(); 159 } 160 PersistenceManager pm = (PersistenceManager) 161 connectionManager.allocateConnection(mcf, null); 162 pm.currentTransaction(); 163 return (Connection ) pm; 164 } 165 166 171 public Connection getConnection(ConnectionSpec spec) throws ResourceException { 172 if (!mcf.started) { 173 mcf.start(); 174 } 175 ConnectionRequestInfo cri = null; 176 if (spec instanceof ConnectionRequestInfo ) { 177 cri = (ConnectionRequestInfo ) spec; 178 } 179 PersistenceManager pm = (PersistenceManager) 180 connectionManager.allocateConnection(mcf, cri); 181 pm.currentTransaction(); 182 return (Connection ) pm; 183 } 184 185 189 public void setReference(Reference reference) { 190 jndiReference = reference; 191 } 192 193 197 public Reference getReference() throws NamingException { 198 return jndiReference; 199 } 200 201 204 public RecordFactory getRecordFactory() throws ResourceException { 205 throw new NotSupportedException ("JDO Connector: no support for record."); 206 } 207 208 211 public ResourceAdapterMetaData getMetaData() throws ResourceException { 212 return this; 213 } 214 215 217 221 public String getAdapterVersion() { 222 return JDOADAPTERVERSION; 223 } 224 225 229 public String getAdapterVendorName() { 230 return JDOADAPTERVENDORNAME; 231 } 232 233 237 public String getAdapterName() { 238 return JDOADAPTERNAME; 239 } 240 241 245 public String getAdapterShortDescription() { 246 return JDOADAPTERSHORTDESCRIPTION; 247 } 248 249 253 public String getSpecVersion() { 254 return JDOSPECVERSION; 255 } 256 257 260 public String [] getInteractionSpecsSupported() { 261 return new String [0]; 262 } 263 264 267 public boolean supportsExecuteWithInputAndOutputRecord() { 268 return false; 269 } 270 271 274 public boolean supportsExecuteWithInputRecordOnly() { 275 return false; 276 } 277 278 281 public boolean supportsLocalTransactionDemarcation() { 282 return true; 283 } 284 285 287 public PersistenceManager getPersistenceManager() { 288 try { 289 return (PersistenceManager) getConnection(); 290 } catch (ResourceException e) { 291 throw new JDOException("JDO Connector: problem while getting a PersistenceManager.", e); 292 } 293 } 294 295 public PersistenceManager getPersistenceManager(String s, String s1) { 296 try { 297 PersistenceManager pm = (PersistenceManager) 298 getConnection(new JDOConnectionSpec(s, s1)); 299 pm.currentTransaction(); 300 return pm; 301 } catch (ResourceException e) { 302 throw new JDOException("JDO Connector: problem while getting a PersistenceManager.", e); 303 } 304 } 305 306 public void setConnectionUserName(String s) { 307 checkMCFStarted(); 308 mcf.pmf.setConnectionUserName(s); 309 } 310 311 public String getConnectionUserName() { 312 checkMCFStarted(); 313 return mcf.pmf.getConnectionUserName(); 314 } 315 316 public void setConnectionPassword(String s) { 317 checkMCFStarted(); 318 mcf.pmf.setConnectionPassword(s); 319 } 320 321 public void setConnectionURL(String s) { 322 checkMCFStarted(); 323 mcf.pmf.setConnectionURL(s); 324 } 325 326 public String getConnectionURL() { 327 checkMCFStarted(); 328 return mcf.pmf.getConnectionURL(); 329 } 330 331 public void setConnectionDriverName(String s) { 332 checkMCFStarted(); 333 mcf.pmf.setConnectionDriverName(s); 334 } 335 336 public String getConnectionDriverName() { 337 checkMCFStarted(); 338 return mcf.pmf.getConnectionDriverName(); 339 } 340 341 public void setConnectionFactoryName(String s) { 342 checkMCFStarted(); 343 mcf.pmf.setConnectionFactoryName(s); 344 } 345 346 public String getConnectionFactoryName() { 347 checkMCFStarted(); 348 return mcf.pmf.getConnectionFactoryName(); 349 } 350 351 public void setConnectionFactory(Object o) { 352 checkMCFStarted(); 353 mcf.pmf.setConnectionFactory(o); 354 } 355 356 public Object getConnectionFactory() { 357 checkMCFStarted(); 358 return mcf.pmf.getConnectionFactory(); 359 } 360 361 public void setConnectionFactory2Name(String s) { 362 checkMCFStarted(); 363 mcf.pmf.setConnectionFactory2Name(s); 364 } 365 366 public String getConnectionFactory2Name() { 367 checkMCFStarted(); 368 return mcf.pmf.getConnectionFactory2Name(); 369 } 370 371 public void setConnectionFactory2(Object o) { 372 checkMCFStarted(); 373 mcf.pmf.setConnectionFactory2(o); 374 } 375 376 public Object getConnectionFactory2() { 377 checkMCFStarted(); 378 return mcf.pmf.getConnectionFactory2(); 379 } 380 381 public void setMultithreaded(boolean b) { 382 checkMCFStarted(); 383 mcf.pmf.setMultithreaded(b); 384 } 385 386 public boolean getMultithreaded() { 387 checkMCFStarted(); 388 return mcf.pmf.getMultithreaded(); 389 } 390 391 public void setOptimistic(boolean b) { 392 checkMCFStarted(); 393 mcf.pmf.setOptimistic(b); 394 } 395 396 public boolean getOptimistic() { 397 checkMCFStarted(); 398 return mcf.pmf.getOptimistic(); 399 } 400 401 public void setRetainValues(boolean b) { 402 checkMCFStarted(); 403 mcf.pmf.setRetainValues(b); 404 } 405 406 public boolean getRetainValues() { 407 checkMCFStarted(); 408 return mcf.pmf.getRetainValues(); 409 } 410 411 public void setRestoreValues(boolean b) { 412 checkMCFStarted(); 413 mcf.pmf.setRestoreValues(b); 414 } 415 416 public boolean getRestoreValues() { 417 checkMCFStarted(); 418 return mcf.pmf.getRestoreValues(); 419 } 420 421 public void setNontransactionalRead(boolean b) { 422 checkMCFStarted(); 423 mcf.pmf.setNontransactionalRead(b); 424 } 425 426 public boolean getNontransactionalRead() { 427 checkMCFStarted(); 428 return mcf.pmf.getNontransactionalRead(); 429 } 430 431 public void setNontransactionalWrite(boolean b) { 432 checkMCFStarted(); 433 mcf.pmf.setNontransactionalWrite(b); 434 } 435 436 public boolean getNontransactionalWrite() { 437 checkMCFStarted(); 438 return mcf.pmf.getNontransactionalWrite(); 439 } 440 441 public void setIgnoreCache(boolean b) { 442 checkMCFStarted(); 443 mcf.pmf.setIgnoreCache(b); 444 } 445 446 public boolean getIgnoreCache() { 447 checkMCFStarted(); 448 return mcf.pmf.getIgnoreCache(); 449 } 450 451 public Properties getProperties() { 452 checkMCFStarted(); 453 return mcf.pmf.getProperties(); 454 } 455 456 public Collection supportedOptions() { 457 checkMCFStarted(); 458 return mcf.pmf.supportedOptions(); 459 } 460 461 public void close() { 462 checkMCFStarted(); 463 mcf.pmf.close(); 464 } 465 466 public DataStoreCache getDataStoreCache() { 467 checkMCFStarted(); 468 return mcf.pmf.getDataStoreCache(); 469 } 470 public String getMapping() { 471 checkMCFStarted(); 472 return mcf.pmf.getMapping(); 473 } 474 public boolean isClosed() { 475 checkMCFStarted(); 476 return mcf.pmf.isClosed(); 477 } 478 public void setMapping(String arg0) { 479 checkMCFStarted(); 480 mcf.pmf.setMapping(arg0); 481 } 482 public void addInstanceLifecycleListener(InstanceLifecycleListener arg0, 483 Class [] arg1) { 484 checkMCFStarted(); 485 mcf.pmf.addInstanceLifecycleListener(arg0, arg1); 486 } 487 public void removeInstanceLifecycleListener(InstanceLifecycleListener arg0) { 488 checkMCFStarted(); 489 mcf.pmf.removeInstanceLifecycleListener(arg0); 490 } 491 492 public byte getTransactionMode() { 493 return transactionMode; 494 } 495 } 496 | Popular Tags |