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


001:        /*
002:         * Copyright 2002-2006 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.orm.toplink.support;
018:
019:        import oracle.toplink.exceptions.TopLinkException;
020:        import oracle.toplink.sessions.Session;
021:
022:        import org.springframework.dao.DataAccessException;
023:        import org.springframework.dao.DataAccessResourceFailureException;
024:        import org.springframework.dao.support.DaoSupport;
025:        import org.springframework.orm.toplink.SessionFactory;
026:        import org.springframework.orm.toplink.SessionFactoryUtils;
027:        import org.springframework.orm.toplink.TopLinkTemplate;
028:
029:        /**
030:         * Convenient super class for TopLink data access objects.
031:         *
032:         * <p>Requires a SessionFactory to be set, providing a TopLinkTemplate
033:         * based on it to subclasses. Can alternatively be initialized directly with
034:         * a TopLinkTemplate, to reuse the latter's settings such as the SessionFactory,
035:         * exception translator, etc.
036:         *
037:         * <p>This base class is mainly intended for TopLinkTemplate usage
038:         * but can also be used when working with SessionFactoryUtils directly,
039:         * for example in combination with TopLinkInterceptor-managed Sessions.
040:         * Convenience <code>getSession</code> and <code>releaseSession</code>
041:         * methods are provided for that usage style.
042:         *
043:         * @author Juergen Hoeller
044:         * @since 1.2
045:         * @see #setSessionFactory
046:         * @see #setTopLinkTemplate
047:         * @see #getSession
048:         * @see #releaseSession
049:         * @see org.springframework.orm.toplink.TopLinkTemplate
050:         * @see org.springframework.orm.toplink.TopLinkInterceptor
051:         */
052:        public abstract class TopLinkDaoSupport extends DaoSupport {
053:
054:            private TopLinkTemplate topLinkTemplate;
055:
056:            /**
057:             * Set the TopLink SessionFactory to be used by this DAO.
058:             * Will automatically create a TopLinkTemplate for the given SessionFactory.
059:             * @see #createTopLinkTemplate
060:             * @see #setTopLinkTemplate
061:             */
062:            public final void setSessionFactory(SessionFactory sessionFactory) {
063:                this .topLinkTemplate = createTopLinkTemplate(sessionFactory);
064:            }
065:
066:            /**
067:             * Create a TopLinkTemplate for the given SessionFactory.
068:             * Only invoked if populating the DAO with a SessionFactory reference!
069:             * <p>Can be overridden in subclasses to provide a TopLinkTemplate instance
070:             * with different configuration, or a custom TopLinkTemplate subclass.
071:             * @param sessionFactory the TopLink SessionFactory to create a TopLinkTemplate for
072:             * @return the new TopLinkTemplate instance
073:             * @see #setSessionFactory
074:             */
075:            protected TopLinkTemplate createTopLinkTemplate(
076:                    SessionFactory sessionFactory) {
077:                return new TopLinkTemplate(sessionFactory);
078:            }
079:
080:            /**
081:             * Return the TopLink SessionFactory used by this DAO.
082:             */
083:            public final SessionFactory getSessionFactory() {
084:                return (this .topLinkTemplate != null ? this .topLinkTemplate
085:                        .getSessionFactory() : null);
086:            }
087:
088:            /**
089:             * Set the TopLinkTemplate for this DAO explicitly,
090:             * as an alternative to specifying a SessionFactory.
091:             * @see #setSessionFactory
092:             */
093:            public final void setTopLinkTemplate(TopLinkTemplate topLinkTemplate) {
094:                this .topLinkTemplate = topLinkTemplate;
095:            }
096:
097:            /**
098:             * Return the TopLinkTemplate for this DAO,
099:             * pre-initialized with the SessionFactory or set explicitly.
100:             */
101:            public final TopLinkTemplate getTopLinkTemplate() {
102:                return topLinkTemplate;
103:            }
104:
105:            protected final void checkDaoConfig() {
106:                if (this .topLinkTemplate == null) {
107:                    throw new IllegalArgumentException(
108:                            "sessionFactory or topLinkTemplate is required");
109:                }
110:            }
111:
112:            /**
113:             * Get a TopLink Session, either from the current transaction or a new one.
114:             * The latter is only allowed if the "allowCreate" setting of this bean's
115:             * TopLinkTemplate is true.
116:             * <p><b>Note that this is not meant to be invoked from TopLinkTemplate code
117:             * but rather just in plain TopLink code.</b> Either rely on a thread-bound
118:             * Session (via TopLinkInterceptor), or use it in combination with
119:             * <code>releaseSession</code>.
120:             * <p>In general, it is recommended to use TopLinkTemplate, either with
121:             * the provided convenience operations or with a custom TopLinkCallback
122:             * that provides you with a Session to work on. TopLinkTemplate will care
123:             * for all resource management and for proper exception conversion.
124:             * @return the TopLink Session
125:             * @throws DataAccessResourceFailureException if the Session couldn't be created
126:             * @throws IllegalStateException if no thread-bound Session found and allowCreate false
127:             * @see TopLinkTemplate
128:             * @see org.springframework.orm.toplink.SessionFactoryUtils#getSession(SessionFactory, boolean)
129:             * @see org.springframework.orm.toplink.TopLinkInterceptor
130:             * @see org.springframework.orm.toplink.TopLinkTemplate
131:             * @see org.springframework.orm.toplink.TopLinkCallback
132:             */
133:            protected final Session getSession()
134:                    throws DataAccessResourceFailureException,
135:                    IllegalStateException {
136:
137:                return getSession(this .topLinkTemplate.isAllowCreate());
138:            }
139:
140:            /**
141:             * Get a TopLink Session, either from the current transaction or a new one.
142:             * The latter is only allowed if "allowCreate" is true.
143:             * <p><b>Note that this is not meant to be invoked from TopLinkTemplate code
144:             * but rather just in plain TopLink code.</b> Either rely on a thread-bound
145:             * Session (via TopLinkInterceptor), or use it in combination with
146:             * <code>releaseSession</code>.
147:             * <p>In general, it is recommended to use TopLinkTemplate, either with
148:             * the provided convenience operations or with a custom TopLinkCallback
149:             * that provides you with a Session to work on. TopLinkTemplate will care
150:             * for all resource management and for proper exception conversion.
151:             * @param allowCreate if a new Session should be created if no thread-bound found
152:             * @return the TopLink Session
153:             * @throws DataAccessResourceFailureException if the Session couldn't be created
154:             * @throws IllegalStateException if no thread-bound Session found and allowCreate false
155:             * @see org.springframework.orm.toplink.SessionFactoryUtils#getSession(SessionFactory, boolean)
156:             * @see org.springframework.orm.toplink.TopLinkInterceptor
157:             * @see org.springframework.orm.toplink.TopLinkTemplate
158:             * @see org.springframework.orm.toplink.TopLinkCallback
159:             */
160:            protected final Session getSession(boolean allowCreate)
161:                    throws DataAccessResourceFailureException,
162:                    IllegalStateException {
163:
164:                return SessionFactoryUtils.getSession(this .getSessionFactory(),
165:                        allowCreate);
166:            }
167:
168:            /**
169:             * Convert the given TopLinkException to an appropriate exception from the
170:             * <code>org.springframework.dao</code> hierarchy. Will automatically detect
171:             * wrapped SQLExceptions and convert them accordingly.
172:             * <p>Delegates to the convertTopLinkAccessException method of this
173:             * DAO's TopLinkTemplate.
174:             * @param ex TopLinkException that occured
175:             * @return the corresponding DataAccessException instance
176:             * @see #setTopLinkTemplate
177:             * @see org.springframework.orm.toplink.TopLinkTemplate#convertTopLinkAccessException
178:             */
179:            protected final DataAccessException convertTopLinkAccessException(
180:                    TopLinkException ex) {
181:                return this .topLinkTemplate.convertTopLinkAccessException(ex);
182:            }
183:
184:            /**
185:             * Close the given TopLink Session, created via this DAO's SessionFactory,
186:             * if it isn't bound to the thread.
187:             * @param session the TopLink Session to close
188:             * @see org.springframework.orm.toplink.SessionFactoryUtils#releaseSession
189:             */
190:            protected final void releaseSession(Session session) {
191:                SessionFactoryUtils
192:                        .releaseSession(session, getSessionFactory());
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.