Java Doc for TransactionSynchronizationManager.java in  » J2EE » spring-framework-2.0.6 » org » springframework » transaction » support » 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.transaction.support 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.transaction.support.TransactionSynchronizationManager

TransactionSynchronizationManager
abstract public class TransactionSynchronizationManager (Code)
Central helper that manages resources and transaction synchronizations per thread. To be used by resource management code but not by typical application code.

Supports one resource per key without overwriting, that is, a resource needs to be removed before a new one can be set for the same key. Supports a list of transaction synchronizations if synchronization is active.

Resource management code should check for thread-bound resources, e.g. JDBC Connections or Hibernate Sessions, via getResource. Such code is normally not supposed to bind resources to threads, as this is the responsibility of transaction managers. A further option is to lazily bind on first use if transaction synchronization is active, for performing transactions that span an arbitrary number of resources.

Transaction synchronization must be activated and deactivated by a transaction manager via TransactionSynchronizationManager.initSynchronization() and TransactionSynchronizationManager.clearSynchronization() . This is automatically supported by AbstractPlatformTransactionManager , and thus by all standard Spring transaction managers, such as org.springframework.transaction.jta.JtaTransactionManager and org.springframework.jdbc.datasource.DataSourceTransactionManager .

Resource management code should only register synchronizations when this manager is active, which can be checked via TransactionSynchronizationManager.isSynchronizationActive ; it should perform immediate resource cleanup else. If transaction synchronization isn't active, there is either no current transaction, or the transaction manager doesn't support transaction synchronization.

Synchronization is for example used to always return the same resources within a JTA transaction, e.g. a JDBC Connection or a Hibernate Session for any given DataSource or SessionFactory, respectively.
author:
   Juergen Hoeller
since:
   02.06.2003
See Also:   TransactionSynchronizationManager.isSynchronizationActive
See Also:   TransactionSynchronizationManager.registerSynchronization
See Also:   TransactionSynchronization
See Also:   AbstractPlatformTransactionManager.setTransactionSynchronization
See Also:   org.springframework.transaction.jta.JtaTransactionManager
See Also:   org.springframework.jdbc.datasource.DataSourceTransactionManager
See Also:   org.springframework.jdbc.datasource.DataSourceUtils.getConnection





Method Summary
public static  voidbindResource(Object key, Object value)
     Bind the given resource for the given key to the current thread.
public static  voidclear()
     Clear the entire transaction synchronization state for the current thread: registered synchronizations as well as the various transaction characteristics.
public static  voidclearSynchronization()
     Deactivate transaction synchronization for the current thread.
public static  IntegergetCurrentTransactionIsolationLevel()
     Return the isolation level for the current transaction, if any.
public static  StringgetCurrentTransactionName()
     Return the name of the current transaction, or null if none set.
public static  ObjectgetResource(Object key)
     Retrieve a resource for the given key that is bound to the current thread.
public static  MapgetResourceMap()
     Return all resources that are bound to the current thread.

Mainly for debugging purposes.

public static  ListgetSynchronizations()
     Return an unmodifiable snapshot list of all registered synchronizations for the current thread.
public static  booleanhasResource(Object key)
     Check if there is a resource for the given key bound to the current thread.
public static  voidinitSynchronization()
     Activate transaction synchronization for the current thread.
public static  booleanisActualTransactionActive()
     Return whether there currently is an actual transaction active.
public static  booleanisCurrentTransactionReadOnly()
     Return whether the current transaction is marked as read-only. To be called by resource management code when preparing a newly created resource (for example, a Hibernate Session).

Note that transaction synchronizations receive the read-only flag as argument for the beforeCommit callback, to be able to suppress change detection on commit.

public static  booleanisSynchronizationActive()
     Return if transaction synchronization is active for the current thread.
public static  voidregisterSynchronization(TransactionSynchronization synchronization)
     Register a new transaction synchronization for the current thread.
public static  voidsetActualTransactionActive(boolean active)
     Expose whether there currently is an actual transaction active.
public static  voidsetCurrentTransactionIsolationLevel(Integer isolationLevel)
     Expose an isolation level for the current transaction.
public static  voidsetCurrentTransactionName(String name)
     Expose the name of the current transaction, if any.
public static  voidsetCurrentTransactionReadOnly(boolean readOnly)
     Expose a read-only flag for the current transaction.
public static  ObjectunbindResource(Object key)
     Unbind a resource for the given key from the current thread.



Method Detail
bindResource
public static void bindResource(Object key, Object value) throws IllegalStateException(Code)
Bind the given resource for the given key to the current thread.
Parameters:
  key - the key to bind the value to (usually the resource factory)
Parameters:
  value - the value to bind (usually the active resource object)
throws:
  IllegalStateException - if there is already a value bound to the thread
See Also:   ResourceTransactionManager.getResourceFactory



clear
public static void clear()(Code)
Clear the entire transaction synchronization state for the current thread: registered synchronizations as well as the various transaction characteristics.
See Also:   TransactionSynchronizationManager.clearSynchronization()
See Also:   TransactionSynchronizationManager.setCurrentTransactionName
See Also:   TransactionSynchronizationManager.setCurrentTransactionReadOnly
See Also:   TransactionSynchronizationManager.setCurrentTransactionIsolationLevel
See Also:   TransactionSynchronizationManager.setActualTransactionActive



clearSynchronization
public static void clearSynchronization() throws IllegalStateException(Code)
Deactivate transaction synchronization for the current thread. Called by the transaction manager on transaction cleanup.
throws:
  IllegalStateException - if synchronization is not active



getCurrentTransactionIsolationLevel
public static Integer getCurrentTransactionIsolationLevel()(Code)
Return the isolation level for the current transaction, if any. To be called by resource management code when preparing a newly created resource (for example, a JDBC Connection). the currently exposed isolation level, according to theJDBC Connection constants (equivalent to the corresponding SpringTransactionDefinition constants), or null if none
See Also:   java.sql.Connection.TRANSACTION_READ_UNCOMMITTED
See Also:   java.sql.Connection.TRANSACTION_READ_COMMITTED
See Also:   java.sql.Connection.TRANSACTION_REPEATABLE_READ
See Also:   java.sql.Connection.TRANSACTION_SERIALIZABLE
See Also:   org.springframework.transaction.TransactionDefinition.ISOLATION_READ_UNCOMMITTED
See Also:   org.springframework.transaction.TransactionDefinition.ISOLATION_READ_COMMITTED
See Also:   org.springframework.transaction.TransactionDefinition.ISOLATION_REPEATABLE_READ
See Also:   org.springframework.transaction.TransactionDefinition.ISOLATION_SERIALIZABLE
See Also:   org.springframework.transaction.TransactionDefinition.getIsolationLevel



getCurrentTransactionName
public static String getCurrentTransactionName()(Code)
Return the name of the current transaction, or null if none set. To be called by resource management code for optimizations per use case, for example to optimize fetch strategies for specific named transactions.
See Also:   org.springframework.transaction.TransactionDefinition.getName



getResource
public static Object getResource(Object key)(Code)
Retrieve a resource for the given key that is bound to the current thread.
Parameters:
  key - the key to check (usually the resource factory) a value bound to the current thread (usually the activeresource object), or null if none
See Also:   ResourceTransactionManager.getResourceFactory



getResourceMap
public static Map getResourceMap()(Code)
Return all resources that are bound to the current thread.

Mainly for debugging purposes. Resource managers should always invoke hasResource for a specific resource key that they are interested in. a Map with resource keys (usually the resource factory) and resourcevalues (usually the active resource object), or an empty Map if there arecurrently no resources bound
See Also:   TransactionSynchronizationManager.hasResource




getSynchronizations
public static List getSynchronizations() throws IllegalStateException(Code)
Return an unmodifiable snapshot list of all registered synchronizations for the current thread. unmodifiable List of TransactionSynchronization instances
throws:
  IllegalStateException - if synchronization is not active
See Also:   TransactionSynchronization



hasResource
public static boolean hasResource(Object key)(Code)
Check if there is a resource for the given key bound to the current thread.
Parameters:
  key - the key to check (usually the resource factory) if there is a value bound to the current thread
See Also:   ResourceTransactionManager.getResourceFactory
See Also:   



initSynchronization
public static void initSynchronization() throws IllegalStateException(Code)
Activate transaction synchronization for the current thread. Called by a transaction manager on transaction begin.
throws:
  IllegalStateException - if synchronization is already active



isActualTransactionActive
public static boolean isActualTransactionActive()(Code)
Return whether there currently is an actual transaction active. This indicates whether the current thread is associated with an actual transaction rather than just with active transaction synchronization.

To be called by resource management code that wants to discriminate between active transaction synchronization (with or without backing resource transaction; also on PROPAGATION_SUPPORTS) and an actual transaction being active (with backing resource transaction; on PROPAGATION_REQUIRES, PROPAGATION_REQUIRES_NEW, etc).
See Also:   TransactionSynchronizationManager.isSynchronizationActive()




isCurrentTransactionReadOnly
public static boolean isCurrentTransactionReadOnly()(Code)
Return whether the current transaction is marked as read-only. To be called by resource management code when preparing a newly created resource (for example, a Hibernate Session).

Note that transaction synchronizations receive the read-only flag as argument for the beforeCommit callback, to be able to suppress change detection on commit. The present method is meant to be used for earlier read-only checks, for example to set the flush mode of a Hibernate Session to "FlushMode.NEVER" upfront.
See Also:   org.springframework.transaction.TransactionDefinition.isReadOnly
See Also:   TransactionSynchronization.beforeCommit(boolean)
See Also:   org.hibernate.Session.flush
See Also:   org.hibernate.Session.setFlushMode
See Also:   org.hibernate.FlushMode.NEVER




isSynchronizationActive
public static boolean isSynchronizationActive()(Code)
Return if transaction synchronization is active for the current thread. Can be called before register to avoid unnecessary instance creation.
See Also:   TransactionSynchronizationManager.registerSynchronization



registerSynchronization
public static void registerSynchronization(TransactionSynchronization synchronization) throws IllegalStateException(Code)
Register a new transaction synchronization for the current thread. Typically called by resource management code.

Note that synchronizations can implement the org.springframework.core.Ordered interface. They will be executed in an order according to their order value (if any).
Parameters:
  synchronization - the synchronization object to register
throws:
  IllegalStateException - if transaction synchronization is not active
See Also:   org.springframework.core.Ordered




setActualTransactionActive
public static void setActualTransactionActive(boolean active)(Code)
Expose whether there currently is an actual transaction active. Called by the transaction manager on transaction begin and on cleanup.
Parameters:
  active - true to mark the current thread as being associatedwith an actual transaction; false to reset that marker



setCurrentTransactionIsolationLevel
public static void setCurrentTransactionIsolationLevel(Integer isolationLevel)(Code)
Expose an isolation level for the current transaction. Called by the transaction manager on transaction begin and on cleanup.
Parameters:
  isolationLevel - the isolation level to expose, according to theJDBC Connection constants (equivalent to the corresponding SpringTransactionDefinition constants), or null to reset it
See Also:   java.sql.Connection.TRANSACTION_READ_UNCOMMITTED
See Also:   java.sql.Connection.TRANSACTION_READ_COMMITTED
See Also:   java.sql.Connection.TRANSACTION_REPEATABLE_READ
See Also:   java.sql.Connection.TRANSACTION_SERIALIZABLE
See Also:   org.springframework.transaction.TransactionDefinition.ISOLATION_READ_UNCOMMITTED
See Also:   org.springframework.transaction.TransactionDefinition.ISOLATION_READ_COMMITTED
See Also:   org.springframework.transaction.TransactionDefinition.ISOLATION_REPEATABLE_READ
See Also:   org.springframework.transaction.TransactionDefinition.ISOLATION_SERIALIZABLE
See Also:   org.springframework.transaction.TransactionDefinition.getIsolationLevel



setCurrentTransactionName
public static void setCurrentTransactionName(String name)(Code)
Expose the name of the current transaction, if any. Called by the transaction manager on transaction begin and on cleanup.
Parameters:
  name - the name of the transaction, or null to reset it
See Also:   org.springframework.transaction.TransactionDefinition.getName



setCurrentTransactionReadOnly
public static void setCurrentTransactionReadOnly(boolean readOnly)(Code)
Expose a read-only flag for the current transaction. Called by the transaction manager on transaction begin and on cleanup.
Parameters:
  readOnly - true to mark the current transactionas read-only; false to reset such a read-only marker
See Also:   org.springframework.transaction.TransactionDefinition.isReadOnly



unbindResource
public static Object unbindResource(Object key) throws IllegalStateException(Code)
Unbind a resource for the given key from the current thread.
Parameters:
  key - the key to unbind (usually the resource factory) the previously bound value (usually the active resource object)
throws:
  IllegalStateException - if there is no value bound to the thread
See Also:   ResourceTransactionManager.getResourceFactory



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.