Source Code Cross Referenced for AbstractLobType.java in  » J2EE » spring-framework-2.5 » org » springframework » orm » hibernate3 » 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.5 » org.springframework.orm.hibernate3.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.hibernate3.support;
018:
019:        import java.io.IOException;
020:        import java.io.Serializable;
021:        import java.sql.PreparedStatement;
022:        import java.sql.ResultSet;
023:        import java.sql.SQLException;
024:
025:        import javax.transaction.Status;
026:        import javax.transaction.TransactionManager;
027:
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:        import org.hibernate.HibernateException;
031:        import org.hibernate.usertype.UserType;
032:        import org.hibernate.util.EqualsHelper;
033:
034:        import org.springframework.dao.DataAccessResourceFailureException;
035:        import org.springframework.jdbc.support.lob.JtaLobCreatorSynchronization;
036:        import org.springframework.jdbc.support.lob.LobCreator;
037:        import org.springframework.jdbc.support.lob.LobHandler;
038:        import org.springframework.jdbc.support.lob.SpringLobCreatorSynchronization;
039:        import org.springframework.jdbc.support.lob.LobCreatorUtils;
040:        import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
041:        import org.springframework.transaction.support.TransactionSynchronizationManager;
042:
043:        /**
044:         * Abstract base class for Hibernate UserType implementations that map to LOBs.
045:         * Retrieves the LobHandler to use from LocalSessionFactoryBean at config time.
046:         *
047:         * <p>For writing LOBs, either an active Spring transaction synchronization
048:         * or an active JTA transaction (with "jtaTransactionManager" specified on
049:         * LocalSessionFactoryBean or a Hibernate TransactionManagerLookup configured
050:         * through the corresponding Hibernate property) is required.
051:         *
052:         * <p>Offers template methods for setting parameters and getting result values,
053:         * passing in the LobHandler or LobCreator to use.
054:         *
055:         * @author Juergen Hoeller
056:         * @since 1.2
057:         * @see org.springframework.jdbc.support.lob.LobHandler
058:         * @see org.springframework.jdbc.support.lob.LobCreator
059:         * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#setLobHandler
060:         * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#setJtaTransactionManager
061:         */
062:        public abstract class AbstractLobType implements  UserType {
063:
064:            protected final Log logger = LogFactory.getLog(getClass());
065:
066:            private final LobHandler lobHandler;
067:
068:            private final TransactionManager jtaTransactionManager;
069:
070:            /**
071:             * Constructor used by Hibernate: fetches config-time LobHandler and
072:             * config-time JTA TransactionManager from LocalSessionFactoryBean.
073:             * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#getConfigTimeLobHandler
074:             * @see org.springframework.orm.hibernate3.LocalSessionFactoryBean#getConfigTimeTransactionManager
075:             */
076:            protected AbstractLobType() {
077:                this (LocalSessionFactoryBean.getConfigTimeLobHandler(),
078:                        LocalSessionFactoryBean
079:                                .getConfigTimeTransactionManager());
080:            }
081:
082:            /**
083:             * Constructor used for testing: takes an explicit LobHandler
084:             * and an explicit JTA TransactionManager (can be <code>null</code>).
085:             */
086:            protected AbstractLobType(LobHandler lobHandler,
087:                    TransactionManager jtaTransactionManager) {
088:                this .lobHandler = lobHandler;
089:                this .jtaTransactionManager = jtaTransactionManager;
090:            }
091:
092:            /**
093:             * This implementation returns false.
094:             */
095:            public boolean isMutable() {
096:                return false;
097:            }
098:
099:            /**
100:             * This implementation delegates to the Hibernate EqualsHelper.
101:             * @see org.hibernate.util.EqualsHelper#equals
102:             */
103:            public boolean equals(Object x, Object y) throws HibernateException {
104:                return EqualsHelper.equals(x, y);
105:            }
106:
107:            /**
108:             * This implementation returns the hashCode of the given objectz.
109:             */
110:            public int hashCode(Object x) throws HibernateException {
111:                return x.hashCode();
112:            }
113:
114:            /**
115:             * This implementation returns the passed-in value as-is.
116:             */
117:            public Object deepCopy(Object value) throws HibernateException {
118:                return value;
119:            }
120:
121:            /**
122:             * This implementation returns the passed-in value as-is.
123:             */
124:            public Serializable disassemble(Object value)
125:                    throws HibernateException {
126:                return (Serializable) value;
127:            }
128:
129:            /**
130:             * This implementation returns the passed-in value as-is.
131:             */
132:            public Object assemble(Serializable cached, Object owner)
133:                    throws HibernateException {
134:                return cached;
135:            }
136:
137:            /**
138:             * This implementation returns the passed-in original as-is.
139:             */
140:            public Object replace(Object original, Object target, Object owner)
141:                    throws HibernateException {
142:                return original;
143:            }
144:
145:            /**
146:             * This implementation delegates to nullSafeGetInternal,
147:             * passing in the LobHandler of this type.
148:             * @see #nullSafeGetInternal
149:             */
150:            public final Object nullSafeGet(ResultSet rs, String[] names,
151:                    Object owner) throws HibernateException, SQLException {
152:
153:                if (this .lobHandler == null) {
154:                    throw new IllegalStateException(
155:                            "No LobHandler found for configuration - "
156:                                    + "lobHandler property must be set on LocalSessionFactoryBean");
157:                }
158:
159:                try {
160:                    return nullSafeGetInternal(rs, names, owner,
161:                            this .lobHandler);
162:                } catch (IOException ex) {
163:                    throw new HibernateException(
164:                            "I/O errors during LOB access", ex);
165:                }
166:            }
167:
168:            /**
169:             * This implementation delegates to nullSafeSetInternal,
170:             * passing in a transaction-synchronized LobCreator for the
171:             * LobHandler of this type.
172:             * @see #nullSafeSetInternal
173:             */
174:            public final void nullSafeSet(PreparedStatement st, Object value,
175:                    int index) throws HibernateException, SQLException {
176:
177:                if (this .lobHandler == null) {
178:                    throw new IllegalStateException(
179:                            "No LobHandler found for configuration - "
180:                                    + "lobHandler property must be set on LocalSessionFactoryBean");
181:                }
182:
183:                LobCreator lobCreator = this .lobHandler.getLobCreator();
184:                try {
185:                    nullSafeSetInternal(st, index, value, lobCreator);
186:                } catch (IOException ex) {
187:                    throw new HibernateException(
188:                            "I/O errors during LOB access", ex);
189:                }
190:                LobCreatorUtils.registerTransactionSynchronization(lobCreator,
191:                        this .jtaTransactionManager);
192:            }
193:
194:            /**
195:             * Template method to extract a value from the given result set.
196:             * @param rs the ResultSet to extract from
197:             * @param names the column names
198:             * @param owner the containing entity
199:             * @param lobHandler the LobHandler to use
200:             * @return the extracted value
201:             * @throws SQLException if thrown by JDBC methods
202:             * @throws IOException if thrown by streaming methods
203:             * @throws HibernateException in case of any other exceptions
204:             */
205:            protected abstract Object nullSafeGetInternal(ResultSet rs,
206:                    String[] names, Object owner, LobHandler lobHandler)
207:                    throws SQLException, IOException, HibernateException;
208:
209:            /**
210:             * Template method to set the given parameter value on the given statement.
211:             * @param ps the PreparedStatement to set on
212:             * @param index the statement parameter index
213:             * @param value the value to set
214:             * @param lobCreator the LobCreator to use
215:             * @throws SQLException if thrown by JDBC methods
216:             * @throws IOException if thrown by streaming methods
217:             * @throws HibernateException in case of any other exceptions
218:             */
219:            protected abstract void nullSafeSetInternal(PreparedStatement ps,
220:                    int index, Object value, LobCreator lobCreator)
221:                    throws SQLException, IOException, HibernateException;
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.