Source Code Cross Referenced for JdbcDaoSupport.java in  » J2EE » spring-framework-2.0.6 » org » springframework » jdbc » core » 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.jdbc.core.support 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.jdbc.core.support;
018:
019:        import java.sql.Connection;
020:
021:        import javax.sql.DataSource;
022:
023:        import org.springframework.dao.support.DaoSupport;
024:        import org.springframework.jdbc.CannotGetJdbcConnectionException;
025:        import org.springframework.jdbc.core.JdbcTemplate;
026:        import org.springframework.jdbc.datasource.DataSourceUtils;
027:        import org.springframework.jdbc.support.SQLExceptionTranslator;
028:
029:        /**
030:         * Convenient super class for JDBC-based data access objects.
031:         *
032:         * <p>Requires a {@link javax.sql.DataSource} to be set, providing a
033:         * {@link org.springframework.jdbc.core.JdbcTemplate} based on it to
034:         * subclasses through the {@link #getJdbcTemplate()} method.
035:         *
036:         * <p>This base class is mainly intended for JdbcTemplate usage but can
037:         * also be used when working with a Connection directly or when using
038:         * <code>org.springframework.jdbc.object</code> operation objects.
039:         *
040:         * @author Juergen Hoeller
041:         * @since 28.07.2003
042:         * @see #setDataSource
043:         * @see #getJdbcTemplate
044:         * @see org.springframework.jdbc.core.JdbcTemplate
045:         */
046:        public abstract class JdbcDaoSupport extends DaoSupport {
047:
048:            private JdbcTemplate jdbcTemplate;
049:
050:            /**
051:             * Set the JDBC DataSource to be used by this DAO.
052:             */
053:            public final void setDataSource(DataSource dataSource) {
054:                this .jdbcTemplate = createJdbcTemplate(dataSource);
055:                initTemplateConfig();
056:            }
057:
058:            /**
059:             * Create a JdbcTemplate for the given DataSource.
060:             * Only invoked if populating the DAO with a DataSource reference!
061:             * <p>Can be overridden in subclasses to provide a JdbcTemplate instance
062:             * with different configuration, or a custom JdbcTemplate subclass.
063:             * @param dataSource the JDBC DataSource to create a JdbcTemplate for
064:             * @return the new JdbcTemplate instance
065:             * @see #setDataSource
066:             */
067:            protected JdbcTemplate createJdbcTemplate(DataSource dataSource) {
068:                return new JdbcTemplate(dataSource);
069:            }
070:
071:            /**
072:             * Return the JDBC DataSource used by this DAO.
073:             */
074:            public final DataSource getDataSource() {
075:                return (this .jdbcTemplate != null ? this .jdbcTemplate
076:                        .getDataSource() : null);
077:            }
078:
079:            /**
080:             * Set the JdbcTemplate for this DAO explicitly,
081:             * as an alternative to specifying a DataSource.
082:             */
083:            public final void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
084:                this .jdbcTemplate = jdbcTemplate;
085:                initTemplateConfig();
086:            }
087:
088:            /**
089:             * Return the JdbcTemplate for this DAO,
090:             * pre-initialized with the DataSource or set explicitly.
091:             */
092:            public final JdbcTemplate getJdbcTemplate() {
093:                return this .jdbcTemplate;
094:            }
095:
096:            /**
097:             * Initialize the template-based configuration of this DAO.
098:             * Called after a new JdbcTemplate has been set, either directly
099:             * or through a DataSource.
100:             * <p>This implementation is empty. Subclasses may override this
101:             * to configure further objects based on the JdbcTemplate.
102:             * @see #getJdbcTemplate()
103:             */
104:            protected void initTemplateConfig() {
105:            }
106:
107:            protected void checkDaoConfig() {
108:                if (this .jdbcTemplate == null) {
109:                    throw new IllegalArgumentException(
110:                            "'dataSource' or 'jdbcTemplate' is required");
111:                }
112:            }
113:
114:            /**
115:             * Return the SQLExceptionTranslator of this DAO's JdbcTemplate,
116:             * for translating SQLExceptions in custom JDBC access code.
117:             * @see org.springframework.jdbc.core.JdbcTemplate#getExceptionTranslator()
118:             */
119:            protected final SQLExceptionTranslator getExceptionTranslator() {
120:                return getJdbcTemplate().getExceptionTranslator();
121:            }
122:
123:            /**
124:             * Get a JDBC Connection, either from the current transaction or a new one.
125:             * @return the JDBC Connection
126:             * @throws CannotGetJdbcConnectionException if the attempt to get a Connection failed
127:             * @see org.springframework.jdbc.datasource.DataSourceUtils#getConnection(javax.sql.DataSource)
128:             */
129:            protected final Connection getConnection()
130:                    throws CannotGetJdbcConnectionException {
131:                return DataSourceUtils.getConnection(getDataSource());
132:            }
133:
134:            /**
135:             * Close the given JDBC Connection, created via this DAO's DataSource,
136:             * if it isn't bound to the thread.
137:             * @param con Connection to close
138:             * @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
139:             */
140:            protected final void releaseConnection(Connection con) {
141:                DataSourceUtils.releaseConnection(con, getDataSource());
142:            }
143:
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.