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


java.lang.Object
   org.springframework.jdbc.datasource.DelegatingDataSource
      org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy

LazyConnectionDataSourceProxy
public class LazyConnectionDataSourceProxy extends DelegatingDataSource (Code)
Proxy for a target DataSource, fetching actual JDBC Connections lazily, i.e. not until first creation of a Statement. Connection initialization properties like auto-commit mode, transaction isolation and read-only mode will be kept and applied to the actual JDBC Connection as soon as an actual Connection is fetched (if ever). Consequently, commit and rollback calls will be ignored if no Statements have been created.

This DataSource proxy allows to avoid fetching JDBC Connections from a pool unless actually necessary. JDBC transaction control can happen without fetching a Connection from the pool or communicating with the database; this will be done lazily on first creation of a JDBC Statement.

If you configure both a LazyConnectionDataSourceProxy and a TransactionAwareDataSourceProxy, make sure that the latter is the outermost DataSource. In such a scenario, data access code will talk to the transaction-aware DataSource, which will in turn work with the LazyConnectionDataSourceProxy.

Lazy fetching of physical JDBC Connections is particularly beneficial in a generic transaction demarcation environment. It allows you to demarcate transactions on all methods that could potentially perform data access, without paying a performance penalty if no actual data access happens.

This DataSource proxy gives you behavior analogous to JTA and a transactional JNDI DataSource (as provided by the J2EE server), even with a local transaction strategy like DataSourceTransactionManager or HibernateTransactionManager. It does not add value with Spring's JtaTransactionManager as transaction strategy.

Lazy fetching of JDBC Connections is also recommended for read-only operations with Hibernate, in particular if the chances of resolving the result in the second-level cache are high. This avoids the need to communicate with the database at all for such read-only operations. You will get the same effect with non-transactional reads, but lazy fetching of JDBC Connections allows you to still perform reads in transactions.

NOTE: This DataSource proxy needs to return wrapped Connections to handle lazy fetching of an actual JDBC Connection. Therefore, the returned Connections cannot be cast to a native JDBC Connection type like OracleConnection, or to a connection pool implementation type. Use a corresponding NativeJdbcExtractor to retrieve the native JDBC Connection.
author:
   Juergen Hoeller
since:
   1.1.4
See Also:   ConnectionProxy
See Also:   DataSourceTransactionManager
See Also:   org.springframework.orm.hibernate.HibernateTransactionManager
See Also:   org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor




Constructor Summary
public  LazyConnectionDataSourceProxy()
     Create a new LazyConnectionDataSourceProxy.
public  LazyConnectionDataSourceProxy(DataSource targetDataSource)
     Create a new LazyConnectionDataSourceProxy.

Method Summary
public  voidafterPropertiesSet()
    
protected synchronized  voidcheckDefaultConnectionProperties(Connection con)
     Check the default connection properties (auto-commit, transaction isolation), keeping them to be able to expose them correctly without fetching an actual JDBC Connection from the target DataSource.

This will be invoked once on startup, but also for each retrieval of a target Connection.

protected  BooleandefaultAutoCommit()
     Expose the default auto-commit value.
protected  IntegerdefaultTransactionIsolation()
     Expose the default transaction isolation value.
public  ConnectiongetConnection()
     Return a Connection handle that lazily fetches an actual JDBC Connection when asked for a Statement (or PreparedStatement or CallableStatement).
public  ConnectiongetConnection(String username, String password)
     Return a Connection handle that lazily fetches an actual JDBC Connection when asked for a Statement (or PreparedStatement or CallableStatement).
public  voidsetDefaultAutoCommit(boolean defaultAutoCommit)
     Set the default auto-commit mode to expose when no target Connection has been fetched yet (-> actual JDBC Connection default not known yet).

If not specified, the default gets determined by checking a target Connection on startup.

public  voidsetDefaultTransactionIsolation(int defaultTransactionIsolation)
     Set the default transaction isolation level to expose when no target Connection has been fetched yet (-> actual JDBC Connection default not known yet).

If not specified, the default gets determined by checking a target Connection on startup.



Constructor Detail
LazyConnectionDataSourceProxy
public LazyConnectionDataSourceProxy()(Code)
Create a new LazyConnectionDataSourceProxy.
See Also:   LazyConnectionDataSourceProxy.setTargetDataSource



LazyConnectionDataSourceProxy
public LazyConnectionDataSourceProxy(DataSource targetDataSource)(Code)
Create a new LazyConnectionDataSourceProxy.
Parameters:
  targetDataSource - the target DataSource




Method Detail
afterPropertiesSet
public void afterPropertiesSet()(Code)



checkDefaultConnectionProperties
protected synchronized void checkDefaultConnectionProperties(Connection con) throws SQLException(Code)
Check the default connection properties (auto-commit, transaction isolation), keeping them to be able to expose them correctly without fetching an actual JDBC Connection from the target DataSource.

This will be invoked once on startup, but also for each retrieval of a target Connection. If the check failed on startup (because the database was down), we'll lazily retrieve those settings.
Parameters:
  con - the Connection to use for checking
throws:
  SQLException - if thrown by Connection methods




defaultAutoCommit
protected Boolean defaultAutoCommit()(Code)
Expose the default auto-commit value.



defaultTransactionIsolation
protected Integer defaultTransactionIsolation()(Code)
Expose the default transaction isolation value.



getConnection
public Connection getConnection() throws SQLException(Code)
Return a Connection handle that lazily fetches an actual JDBC Connection when asked for a Statement (or PreparedStatement or CallableStatement).

The returned Connection handle implements the ConnectionProxy interface, allowing to retrieve the underlying target Connection. a lazy Connection handle
See Also:   ConnectionProxy.getTargetConnection




getConnection
public Connection getConnection(String username, String password) throws SQLException(Code)
Return a Connection handle that lazily fetches an actual JDBC Connection when asked for a Statement (or PreparedStatement or CallableStatement).

The returned Connection handle implements the ConnectionProxy interface, allowing to retrieve the underlying target Connection.
Parameters:
  username - the per-Connection username
Parameters:
  password - the per-Connection password a lazy Connection handle
See Also:   ConnectionProxy.getTargetConnection




setDefaultAutoCommit
public void setDefaultAutoCommit(boolean defaultAutoCommit)(Code)
Set the default auto-commit mode to expose when no target Connection has been fetched yet (-> actual JDBC Connection default not known yet).

If not specified, the default gets determined by checking a target Connection on startup. If that check fails, the default will be determined lazily on first access of a Connection.
See Also:   java.sql.Connection.getAutoCommit




setDefaultTransactionIsolation
public void setDefaultTransactionIsolation(int defaultTransactionIsolation)(Code)
Set the default transaction isolation level to expose when no target Connection has been fetched yet (-> actual JDBC Connection default not known yet).

If not specified, the default gets determined by checking a target Connection on startup. If that check fails, the default will be determined lazily on first access of a Connection.
See Also:   java.sql.Connection.getTransactionIsolation




Methods inherited from org.springframework.jdbc.datasource.DelegatingDataSource
public void afterPropertiesSet()(Code)(Java Doc)
public Connection getConnection() throws SQLException(Code)(Java Doc)
public Connection getConnection(String username, String password) throws SQLException(Code)(Java Doc)
public PrintWriter getLogWriter() throws SQLException(Code)(Java Doc)
public int getLoginTimeout() throws SQLException(Code)(Java Doc)
public DataSource getTargetDataSource()(Code)(Java Doc)
public void setLogWriter(PrintWriter out) throws SQLException(Code)(Java Doc)
public void setLoginTimeout(int seconds) throws SQLException(Code)(Java Doc)
final public void setTargetDataSource(DataSource targetDataSource)(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.