Java Doc for TopLinkTransactionManager.java in  » J2EE » spring-framework-2.0.6 » org » springframework » orm » toplink » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.orm.toplink 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.transaction.support.AbstractPlatformTransactionManager
      org.springframework.orm.toplink.TopLinkTransactionManager

TopLinkTransactionManager
public class TopLinkTransactionManager extends AbstractPlatformTransactionManager implements ResourceTransactionManager,InitializingBean(Code)
org.springframework.transaction.PlatformTransactionManager implementation for a single TopLink SessionFactory . Binds a TopLink Session from the specified factory to the thread, potentially allowing for one thread-bound Session per factory. SessionFactoryUtils and TopLinkTemplate are aware of thread-bound Sessions and participate in such transactions automatically. Using either of those or going through Session.getActiveUnitOfWork() is required for TopLink access code supporting this transaction handling mechanism.

This transaction manager is appropriate for applications that use a single TopLink SessionFactory for transactional data access. JTA (usually through org.springframework.transaction.jta.JtaTransactionManager ) is necessary for accessing multiple transactional resources within the same transaction. Note that you need to configure TopLink with an appropriate external transaction controller in order to make it participate in JTA transactions.

This transaction manager also supports direct DataSource access within a transaction (i.e. plain JDBC code working with the same DataSource), but only for transactions that are not marked as read-only. This allows for mixing services which access TopLink and services which use plain JDBC (without being aware of TopLink)! Application code needs to stick to the same simple Connection lookup pattern as with org.springframework.jdbc.datasource.DataSourceTransactionManager (i.e. org.springframework.jdbc.datasource.DataSourceUtils.getConnection or going through a org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy ).

Note: To be able to register a DataSource's Connection for plain JDBC code, this instance needs to be aware of the DataSource ( TopLinkTransactionManager.setDataSource ). The given DataSource should obviously match the one used by the given TopLink SessionFactory.

On JDBC 3.0, this transaction manager supports nested transactions via JDBC 3.0 Savepoints. The TopLinkTransactionManager.setNestedTransactionAllowed "nestedTransactionAllowed"} flag defaults to "false", though, as nested transactions will just apply to the JDBC Connection, not to the TopLink PersistenceManager and its cached objects. You can manually set the flag to "true" if you want to use nested transactions for JDBC access code which participates in TopLink transactions (provided that your JDBC driver supports Savepoints). Note that TopLink itself does not support nested transactions! Hence, do not expect TopLink access code to semantically participate in a nested transaction.

Thanks to Slavik Markovich for implementing the initial TopLink support prototype!
author:
   Juergen Hoeller
author:
   James Clark
since:
   1.2
See Also:   TopLinkTransactionManager.setSessionFactory
See Also:   TopLinkTransactionManager.setDataSource
See Also:   LocalSessionFactoryBean
See Also:   SessionFactoryUtils.getSession
See Also:   SessionFactoryUtils.releaseSession
See Also:   TopLinkTemplate
See Also:   oracle.toplink.sessions.Session.getActiveUnitOfWork
See Also:   org.springframework.jdbc.datasource.DataSourceUtils.getConnection
See Also:   org.springframework.jdbc.datasource.DataSourceUtils.applyTransactionTimeout
See Also:   org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection
See Also:   org.springframework.jdbc.core.JdbcTemplate
See Also:   org.springframework.jdbc.datasource.DataSourceTransactionManager
See Also:   org.springframework.transaction.jta.JtaTransactionManager




Constructor Summary
public  TopLinkTransactionManager()
     Create a new TopLinkTransactionManager instance.
public  TopLinkTransactionManager(SessionFactory sessionFactory)
     Create a new TopLinkTransactionManager instance.

Method Summary
public  voidafterPropertiesSet()
    
protected  DataAccessExceptionconvertTopLinkAccessException(TopLinkException ex)
     Convert the given TopLinkException to an appropriate exception from the org.springframework.dao hierarchy.
protected  voiddoBegin(Object transaction, TransactionDefinition definition)
    
protected  voiddoCleanupAfterCompletion(Object transaction)
    
protected  voiddoCommit(DefaultTransactionStatus status)
    
protected  ObjectdoGetTransaction()
    
protected  voiddoResume(Object transaction, Object suspendedResources)
    
protected  voiddoRollback(DefaultTransactionStatus status)
    
protected  voiddoSetRollbackOnly(DefaultTransactionStatus status)
    
protected  ObjectdoSuspend(Object transaction)
    
public  DataSourcegetDataSource()
     Return the JDBC DataSource that this instance manages transactions for.
protected  ConnectiongetJdbcConnection(Session session)
     Extract the underlying JDBC Connection from the given TopLink Session.
public  SQLExceptionTranslatorgetJdbcExceptionTranslator()
     Return the JDBC exception translator for this transaction manager, if any.
public  ObjectgetResourceFactory()
    
public  SessionFactorygetSessionFactory()
     Return the SessionFactory that this instance should manage transactions for.
protected  booleanisExistingTransaction(Object transaction)
    
public  booleanisLazyDatabaseTransaction()
     Return whether to lazily start a database transaction within a TopLink transaction.
public  voidsetDataSource(DataSource dataSource)
     Set the JDBC DataSource that this instance should manage transactions for. The DataSource should match the one used by the TopLink SessionFactory: for example, you could specify the same JNDI DataSource for both.

A transactional JDBC Connection for this DataSource will be provided to application code accessing this DataSource directly via DataSourceUtils or JdbcTemplate.

public  voidsetJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
     Set the JDBC exception translator for this transaction manager.

Applied to any SQLException root cause of a TopLink DatabaseException that is thrown on commit.

public  voidsetLazyDatabaseTransaction(boolean lazyDatabaseTransaction)
     Set whether to lazily start a database transaction within a TopLink transaction.

By default, database transactions are started early.

public  voidsetSessionFactory(SessionFactory sessionFactory)
     Set the the TopLink SessionFactory to manage transactions for.


Constructor Detail
TopLinkTransactionManager
public TopLinkTransactionManager()(Code)
Create a new TopLinkTransactionManager instance. A SessionFactory has to be specified to be able to use it.
See Also:   TopLinkTransactionManager.setSessionFactory



TopLinkTransactionManager
public TopLinkTransactionManager(SessionFactory sessionFactory)(Code)
Create a new TopLinkTransactionManager instance.
Parameters:
  sessionFactory - the TopLink SessionFactory to manage transactions for




Method Detail
afterPropertiesSet
public void afterPropertiesSet()(Code)



convertTopLinkAccessException
protected DataAccessException convertTopLinkAccessException(TopLinkException ex)(Code)
Convert the given TopLinkException to an appropriate exception from the org.springframework.dao hierarchy.

Will automatically apply a specified SQLExceptionTranslator to a TopLink DatabaseException, else rely on TopLink's default translation.
Parameters:
  ex - TopLinkException that occured a corresponding DataAccessException
See Also:   SessionFactoryUtils.convertTopLinkAccessException
See Also:   TopLinkTransactionManager.setJdbcExceptionTranslator




doBegin
protected void doBegin(Object transaction, TransactionDefinition definition)(Code)



doCleanupAfterCompletion
protected void doCleanupAfterCompletion(Object transaction)(Code)



doCommit
protected void doCommit(DefaultTransactionStatus status)(Code)



doGetTransaction
protected Object doGetTransaction()(Code)



doResume
protected void doResume(Object transaction, Object suspendedResources)(Code)



doRollback
protected void doRollback(DefaultTransactionStatus status)(Code)



doSetRollbackOnly
protected void doSetRollbackOnly(DefaultTransactionStatus status)(Code)



doSuspend
protected Object doSuspend(Object transaction)(Code)



getDataSource
public DataSource getDataSource()(Code)
Return the JDBC DataSource that this instance manages transactions for.



getJdbcConnection
protected Connection getJdbcConnection(Session session)(Code)
Extract the underlying JDBC Connection from the given TopLink Session.

Default implementation casts to oracle.toplink.publicinterface.Session and fetches the Connection from the DatabaseAccessor exposed there.
Parameters:
  session - the current TopLink Session the underlying JDBC Connection, or null if none found
See Also:   oracle.toplink.publicinterface.Session.getAccessor
See Also:   oracle.toplink.internal.databaseaccess.DatabaseAccessor.getConnection




getJdbcExceptionTranslator
public SQLExceptionTranslator getJdbcExceptionTranslator()(Code)
Return the JDBC exception translator for this transaction manager, if any.



getResourceFactory
public Object getResourceFactory()(Code)



getSessionFactory
public SessionFactory getSessionFactory()(Code)
Return the SessionFactory that this instance should manage transactions for.



isExistingTransaction
protected boolean isExistingTransaction(Object transaction)(Code)



isLazyDatabaseTransaction
public boolean isLazyDatabaseTransaction()(Code)
Return whether to lazily start a database transaction within a TopLink transaction.



setDataSource
public void setDataSource(DataSource dataSource)(Code)
Set the JDBC DataSource that this instance should manage transactions for. The DataSource should match the one used by the TopLink SessionFactory: for example, you could specify the same JNDI DataSource for both.

A transactional JDBC Connection for this DataSource will be provided to application code accessing this DataSource directly via DataSourceUtils or JdbcTemplate. The Connection will be taken from the TopLink Session. This will only happen for transactions that are not marked as read-only. TopLink does not support database transactions for pure read-only operations on a Session (that is, without a UnitOfWork).

Note that you need to use a TopLink Session with a DatabaseAccessor to allow for exposing TopLink transactions as JDBC transactions. This is the case of all standard TopLink configurations.

The DataSource specified here should be the target DataSource to manage transactions for, not a TransactionAwareDataSourceProxy. Only data access code may work with TransactionAwareDataSourceProxy, while the transaction manager needs to work on the underlying target DataSource. If there's nevertheless a TransactionAwareDataSourceProxy passed in, it will be unwrapped to extract its target DataSource.
See Also:   org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
See Also:   org.springframework.jdbc.datasource.DataSourceUtils
See Also:   org.springframework.jdbc.core.JdbcTemplate




setJdbcExceptionTranslator
public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)(Code)
Set the JDBC exception translator for this transaction manager.

Applied to any SQLException root cause of a TopLink DatabaseException that is thrown on commit. The default is to rely on TopLink's native exception translation.
Parameters:
  jdbcExceptionTranslator - the exception translator
See Also:   oracle.toplink.exceptions.DatabaseException
See Also:   org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
See Also:   org.springframework.jdbc.support.SQLStateSQLExceptionTranslator
See Also:   TopLinkTransactionManager.setDataSource(javax.sql.DataSource)




setLazyDatabaseTransaction
public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction)(Code)
Set whether to lazily start a database transaction within a TopLink transaction.

By default, database transactions are started early. This allows for reusing the same JDBC Connection throughout an entire transaction, including read operations, and also for exposing TopLink transactions to JDBC access code (working on the same DataSource).

It is only recommended to switch this flag to "true" when no JDBC access code is involved in any of the transactions, and when it is acceptable to perform read operations outside of the transactional JDBC Connection.
See Also:   TopLinkTransactionManager.setDataSource(javax.sql.DataSource)
See Also:   oracle.toplink.sessions.UnitOfWork.beginEarlyTransaction




setSessionFactory
public void setSessionFactory(SessionFactory sessionFactory)(Code)
Set the the TopLink SessionFactory to manage transactions for. This will usually be a ServerSessionFactory.

The passed-in SessionFactory will be asked for a plain Session in case of a read-only transaction (where no active UnitOfWork is supposed to be available), and for a managed Session else (with an active UnitOfWork that will be committed by this transaction manager).
See Also:   ServerSessionFactory
See Also:   SessionFactory.createSession
See Also:   SessionFactory.createManagedClientSession




Fields inherited from org.springframework.transaction.support.AbstractPlatformTransactionManager
final public static int SYNCHRONIZATION_ALWAYS(Code)(Java Doc)
final public static int SYNCHRONIZATION_NEVER(Code)(Java Doc)
final public static int SYNCHRONIZATION_ON_ACTUAL_TRANSACTION(Code)(Java Doc)
protected transient Log logger(Code)(Java Doc)

Methods inherited from org.springframework.transaction.support.AbstractPlatformTransactionManager
final public void commit(TransactionStatus status) throws TransactionException(Code)(Java Doc)
protected int determineTimeout(TransactionDefinition definition)(Code)(Java Doc)
abstract protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException(Code)(Java Doc)
protected void doCleanupAfterCompletion(Object transaction)(Code)(Java Doc)
abstract protected void doCommit(DefaultTransactionStatus status) throws TransactionException(Code)(Java Doc)
abstract protected Object doGetTransaction() throws TransactionException(Code)(Java Doc)
protected void doResume(Object transaction, Object suspendedResources) throws TransactionException(Code)(Java Doc)
abstract protected void doRollback(DefaultTransactionStatus status) throws TransactionException(Code)(Java Doc)
protected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException(Code)(Java Doc)
protected Object doSuspend(Object transaction) throws TransactionException(Code)(Java Doc)
final public int getDefaultTimeout()(Code)(Java Doc)
final public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException(Code)(Java Doc)
final public int getTransactionSynchronization()(Code)(Java Doc)
final protected void invokeAfterCompletion(List synchronizations, int completionStatus)(Code)(Java Doc)
protected boolean isExistingTransaction(Object transaction) throws TransactionException(Code)(Java Doc)
final public boolean isFailEarlyOnGlobalRollbackOnly()(Code)(Java Doc)
final public boolean isGlobalRollbackOnParticipationFailure()(Code)(Java Doc)
final public boolean isNestedTransactionAllowed()(Code)(Java Doc)
final public boolean isRollbackOnCommitFailure()(Code)(Java Doc)
protected DefaultTransactionStatus newTransactionStatus(TransactionDefinition definition, Object transaction, boolean newTransaction, boolean newSynchronization, boolean debug, Object suspendedResources)(Code)(Java Doc)
protected void registerAfterCompletionWithExistingTransaction(Object transaction, List synchronizations) throws TransactionException(Code)(Java Doc)
final protected void resume(Object transaction, SuspendedResourcesHolder resourcesHolder) throws TransactionException(Code)(Java Doc)
final public void rollback(TransactionStatus status) throws TransactionException(Code)(Java Doc)
final public void setDefaultTimeout(int defaultTimeout)(Code)(Java Doc)
final public void setFailEarlyOnGlobalRollbackOnly(boolean failEarlyOnGlobalRollbackOnly)(Code)(Java Doc)
final public void setGlobalRollbackOnParticipationFailure(boolean globalRollbackOnParticipationFailure)(Code)(Java Doc)
final public void setNestedTransactionAllowed(boolean nestedTransactionAllowed)(Code)(Java Doc)
final public void setRollbackOnCommitFailure(boolean rollbackOnCommitFailure)(Code)(Java Doc)
final public void setTransactionSynchronization(int transactionSynchronization)(Code)(Java Doc)
final public void setTransactionSynchronizationName(String constantName)(Code)(Java Doc)
protected boolean shouldCommitOnGlobalRollbackOnly()(Code)(Java Doc)
final protected SuspendedResourcesHolder suspend(Object transaction) throws TransactionException(Code)(Java Doc)
final protected void triggerBeforeCommit(DefaultTransactionStatus status)(Code)(Java Doc)
final protected void triggerBeforeCompletion(DefaultTransactionStatus status)(Code)(Java Doc)
protected boolean useSavepointForNestedTransaction()(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.