Source Code Cross Referenced for JdoDaoSupport.java in  » J2EE » spring-framework-2.0.6 » org » springframework » orm » jdo » 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.jdo.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.jdo.support;
018:
019:        import javax.jdo.JDOException;
020:        import javax.jdo.PersistenceManager;
021:        import javax.jdo.PersistenceManagerFactory;
022:
023:        import org.springframework.dao.DataAccessException;
024:        import org.springframework.dao.DataAccessResourceFailureException;
025:        import org.springframework.dao.support.DaoSupport;
026:        import org.springframework.orm.jdo.JdoTemplate;
027:        import org.springframework.orm.jdo.PersistenceManagerFactoryUtils;
028:
029:        /**
030:         * Convenient super class for JDO data access objects.
031:         *
032:         * <p>Requires a PersistenceManagerFactory to be set, providing a JdoTemplate
033:         * based on it to subclasses. Can alternatively be initialized directly with a
034:         * JdoTemplate, to reuse the latter's settings such as the PersistenceManagerFactory,
035:         * JdoDialect, flush mode, etc.
036:         *
037:         * <p>This base class is mainly intended for JdoTemplate usage but can also
038:         * be used when working with PersistenceManagerFactoryUtils directly, for example
039:         * in combination with JdoInterceptor-managed PersistenceManagers. Convenience
040:         * <code>getPersistenceManager</code> and <code>releasePersistenceManager</code>
041:         * methods are provided for that usage style.
042:         *
043:         * <p>This class will create its own JdoTemplate if only a PersistenceManagerFactory
044:         * is passed in. The "allowCreate" flag on that JdoTemplate will be "true" by default.
045:         * A custom JdoTemplate instance can be used through overriding <code>createJdoTemplate</code>.
046:         *
047:         * @author Juergen Hoeller
048:         * @since 28.07.2003
049:         * @see #setPersistenceManagerFactory
050:         * @see #setJdoTemplate
051:         * @see #createJdoTemplate
052:         * @see #getPersistenceManager
053:         * @see #releasePersistenceManager
054:         * @see org.springframework.orm.jdo.JdoTemplate
055:         * @see org.springframework.orm.jdo.JdoInterceptor
056:         */
057:        public abstract class JdoDaoSupport extends DaoSupport {
058:
059:            private JdoTemplate jdoTemplate;
060:
061:            /**
062:             * Set the JDO PersistenceManagerFactory to be used by this DAO.
063:             * Will automatically create a JdoTemplate for the given PersistenceManagerFactory.
064:             * @see #createJdoTemplate
065:             * @see #setJdoTemplate
066:             */
067:            public final void setPersistenceManagerFactory(
068:                    PersistenceManagerFactory persistenceManagerFactory) {
069:                this .jdoTemplate = createJdoTemplate(persistenceManagerFactory);
070:            }
071:
072:            /**
073:             * Create a JdoTemplate for the given PersistenceManagerFactory.
074:             * Only invoked if populating the DAO with a PersistenceManagerFactory reference!
075:             * <p>Can be overridden in subclasses to provide a JdoTemplate instance
076:             * with different configuration, or a custom JdoTemplate subclass.
077:             * @param persistenceManagerFactory the JDO PersistenceManagerFactoryto create a JdoTemplate for
078:             * @return the new JdoTemplate instance
079:             * @see #setPersistenceManagerFactory
080:             */
081:            protected JdoTemplate createJdoTemplate(
082:                    PersistenceManagerFactory persistenceManagerFactory) {
083:                return new JdoTemplate(persistenceManagerFactory);
084:            }
085:
086:            /**
087:             * Return the JDO PersistenceManagerFactory used by this DAO.
088:             */
089:            public final PersistenceManagerFactory getPersistenceManagerFactory() {
090:                return (this .jdoTemplate != null ? this .jdoTemplate
091:                        .getPersistenceManagerFactory() : null);
092:            }
093:
094:            /**
095:             * Set the JdoTemplate for this DAO explicitly,
096:             * as an alternative to specifying a PersistenceManagerFactory.
097:             * @see #setPersistenceManagerFactory
098:             */
099:            public final void setJdoTemplate(JdoTemplate jdoTemplate) {
100:                this .jdoTemplate = jdoTemplate;
101:            }
102:
103:            /**
104:             * Return the JdoTemplate for this DAO, pre-initialized
105:             * with the PersistenceManagerFactory or set explicitly.
106:             */
107:            public final JdoTemplate getJdoTemplate() {
108:                return jdoTemplate;
109:            }
110:
111:            protected final void checkDaoConfig() {
112:                if (this .jdoTemplate == null) {
113:                    throw new IllegalArgumentException(
114:                            "persistenceManagerFactory or jdoTemplate is required");
115:                }
116:            }
117:
118:            /**
119:             * Get a JDO PersistenceManager, either from the current transaction or
120:             * a new one. The latter is only allowed if the "allowCreate" setting
121:             * of this bean's JdoTemplate is true.
122:             * @return the JDO PersistenceManager
123:             * @throws DataAccessResourceFailureException if the PersistenceManager couldn't be created
124:             * @throws IllegalStateException if no thread-bound PersistenceManager found and allowCreate false
125:             * @see org.springframework.orm.jdo.PersistenceManagerFactoryUtils#getPersistenceManager
126:             */
127:            protected final PersistenceManager getPersistenceManager() {
128:                return getPersistenceManager(this .jdoTemplate.isAllowCreate());
129:            }
130:
131:            /**
132:             * Get a JDO PersistenceManager, either from the current transaction or
133:             * a new one. The latter is only allowed if "allowCreate" is true.
134:             * @param allowCreate if a non-transactional PersistenceManager should be created
135:             * when no transactional PersistenceManager can be found for the current thread
136:             * @return the JDO PersistenceManager
137:             * @throws DataAccessResourceFailureException if the PersistenceManager couldn't be created
138:             * @throws IllegalStateException if no thread-bound PersistenceManager found and allowCreate false
139:             * @see org.springframework.orm.jdo.PersistenceManagerFactoryUtils#getPersistenceManager
140:             */
141:            protected final PersistenceManager getPersistenceManager(
142:                    boolean allowCreate)
143:                    throws DataAccessResourceFailureException,
144:                    IllegalStateException {
145:
146:                return PersistenceManagerFactoryUtils.getPersistenceManager(
147:                        getPersistenceManagerFactory(), allowCreate);
148:            }
149:
150:            /**
151:             * Convert the given JDOException to an appropriate exception from the
152:             * org.springframework.dao hierarchy.
153:             * <p>Delegates to the convertJdoAccessException method of this DAO's JdoTemplate.
154:             * @param ex JDOException that occured
155:             * @return the corresponding DataAccessException instance
156:             * @see #setJdoTemplate
157:             * @see org.springframework.orm.jdo.JdoTemplate#convertJdoAccessException
158:             */
159:            protected final DataAccessException convertJdoAccessException(
160:                    JDOException ex) {
161:                return this .jdoTemplate.convertJdoAccessException(ex);
162:            }
163:
164:            /**
165:             * Close the given JDO PersistenceManager, created via this DAO's
166:             * PersistenceManagerFactory, if it isn't bound to the thread.
167:             * @param pm PersistenceManager to close
168:             * @see org.springframework.orm.jdo.PersistenceManagerFactoryUtils#releasePersistenceManager
169:             */
170:            protected final void releasePersistenceManager(PersistenceManager pm) {
171:                PersistenceManagerFactoryUtils.releasePersistenceManager(pm,
172:                        getPersistenceManagerFactory());
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.