Source Code Cross Referenced for CompositeCustomType.java in  » Database-ORM » hibernate » org » hibernate » type » 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 » Database ORM » hibernate » org.hibernate.type 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$Id: CompositeCustomType.java 7670 2005-07-29 05:36:14Z oneovthafew $
002:        package org.hibernate.type;
003:
004:        import java.io.Serializable;
005:        import java.lang.reflect.Method;
006:        import java.sql.PreparedStatement;
007:        import java.sql.ResultSet;
008:        import java.sql.SQLException;
009:        import java.util.Map;
010:        import java.util.Properties;
011:
012:        import org.dom4j.Element;
013:        import org.dom4j.Node;
014:        import org.hibernate.EntityMode;
015:        import org.hibernate.FetchMode;
016:        import org.hibernate.HibernateException;
017:        import org.hibernate.MappingException;
018:        import org.hibernate.engine.CascadeStyle;
019:        import org.hibernate.engine.Mapping;
020:        import org.hibernate.engine.SessionFactoryImplementor;
021:        import org.hibernate.engine.SessionImplementor;
022:        import org.hibernate.usertype.CompositeUserType;
023:
024:        /**
025:         * Adapts <tt>CompositeUserType</tt> to <tt>Type</tt> interface
026:         * @author Gavin King
027:         */
028:        public class CompositeCustomType extends AbstractType implements 
029:                AbstractComponentType {
030:
031:            private final CompositeUserType userType;
032:            private final String name;
033:
034:            public CompositeCustomType(Class userTypeClass,
035:                    Properties parameters) throws MappingException {
036:                name = userTypeClass.getName();
037:
038:                if (!CompositeUserType.class.isAssignableFrom(userTypeClass)) {
039:                    throw new MappingException(
040:                            "Custom type does not implement CompositeUserType: "
041:                                    + userTypeClass.getName());
042:                }
043:
044:                try {
045:                    userType = (CompositeUserType) userTypeClass.newInstance();
046:                } catch (InstantiationException ie) {
047:                    throw new MappingException(
048:                            "Cannot instantiate custom type: "
049:                                    + userTypeClass.getName());
050:                } catch (IllegalAccessException iae) {
051:                    throw new MappingException(
052:                            "IllegalAccessException trying to instantiate custom type: "
053:                                    + userTypeClass.getName());
054:                }
055:                TypeFactory.injectParameters(userType, parameters);
056:            }
057:
058:            public boolean isMethodOf(Method method) {
059:                return false;
060:            }
061:
062:            public Type[] getSubtypes() {
063:                return userType.getPropertyTypes();
064:            }
065:
066:            public String[] getPropertyNames() {
067:                return userType.getPropertyNames();
068:            }
069:
070:            public Object[] getPropertyValues(Object component,
071:                    SessionImplementor session) throws HibernateException {
072:                return getPropertyValues(component, session.getEntityMode());
073:            }
074:
075:            public Object[] getPropertyValues(Object component,
076:                    EntityMode entityMode) throws HibernateException {
077:
078:                int len = getSubtypes().length;
079:                Object[] result = new Object[len];
080:                for (int i = 0; i < len; i++) {
081:                    result[i] = getPropertyValue(component, i);
082:                }
083:                return result;
084:            }
085:
086:            public void setPropertyValues(Object component, Object[] values,
087:                    EntityMode entityMode) throws HibernateException {
088:
089:                for (int i = 0; i < values.length; i++) {
090:                    userType.setPropertyValue(component, i, values[i]);
091:                }
092:            }
093:
094:            public Object getPropertyValue(Object component, int i,
095:                    SessionImplementor session) throws HibernateException {
096:                return getPropertyValue(component, i);
097:            }
098:
099:            public Object getPropertyValue(Object component, int i)
100:                    throws HibernateException {
101:                return userType.getPropertyValue(component, i);
102:            }
103:
104:            public CascadeStyle getCascadeStyle(int i) {
105:                return CascadeStyle.NONE;
106:            }
107:
108:            public FetchMode getFetchMode(int i) {
109:                return FetchMode.DEFAULT;
110:            }
111:
112:            public boolean isComponentType() {
113:                return true;
114:            }
115:
116:            public Object deepCopy(Object value, EntityMode entityMode,
117:                    SessionFactoryImplementor factory)
118:                    throws HibernateException {
119:                return userType.deepCopy(value);
120:            }
121:
122:            public Object assemble(Serializable cached,
123:                    SessionImplementor session, Object owner)
124:                    throws HibernateException {
125:
126:                return userType.assemble(cached, session, owner);
127:            }
128:
129:            public Serializable disassemble(Object value,
130:                    SessionImplementor session, Object owner)
131:                    throws HibernateException {
132:                return userType.disassemble(value, session);
133:            }
134:
135:            public Object replace(Object original, Object target,
136:                    SessionImplementor session, Object owner, Map copyCache)
137:                    throws HibernateException {
138:                return userType.replace(original, target, session, owner);
139:            }
140:
141:            public boolean isEqual(Object x, Object y, EntityMode entityMode)
142:                    throws HibernateException {
143:                return userType.equals(x, y);
144:            }
145:
146:            public int getHashCode(Object x, EntityMode entityMode) {
147:                return userType.hashCode(x);
148:            }
149:
150:            public int getColumnSpan(Mapping mapping) throws MappingException {
151:                Type[] types = userType.getPropertyTypes();
152:                int n = 0;
153:                for (int i = 0; i < types.length; i++) {
154:                    n += types[i].getColumnSpan(mapping);
155:                }
156:                return n;
157:            }
158:
159:            public String getName() {
160:                return name;
161:            }
162:
163:            public Class getReturnedClass() {
164:                return userType.returnedClass();
165:            }
166:
167:            public boolean isMutable() {
168:                return userType.isMutable();
169:            }
170:
171:            public Object nullSafeGet(ResultSet rs, String columnName,
172:                    SessionImplementor session, Object owner)
173:                    throws HibernateException, SQLException {
174:
175:                return userType.nullSafeGet(rs, new String[] { columnName },
176:                        session, owner);
177:            }
178:
179:            public Object nullSafeGet(ResultSet rs, String[] names,
180:                    SessionImplementor session, Object owner)
181:                    throws HibernateException, SQLException {
182:
183:                return userType.nullSafeGet(rs, names, session, owner);
184:            }
185:
186:            public void nullSafeSet(PreparedStatement st, Object value,
187:                    int index, SessionImplementor session)
188:                    throws HibernateException, SQLException {
189:
190:                userType.nullSafeSet(st, value, index, session);
191:
192:            }
193:
194:            public void nullSafeSet(PreparedStatement st, Object value,
195:                    int index, boolean[] settable, SessionImplementor session)
196:                    throws HibernateException, SQLException {
197:
198:                userType.nullSafeSet(st, value, index, session);
199:
200:            }
201:
202:            public int[] sqlTypes(Mapping mapping) throws MappingException {
203:                Type[] types = userType.getPropertyTypes();
204:                int[] result = new int[getColumnSpan(mapping)];
205:                int n = 0;
206:                for (int i = 0; i < types.length; i++) {
207:                    int[] sqlTypes = types[i].sqlTypes(mapping);
208:                    for (int k = 0; k < sqlTypes.length; k++)
209:                        result[n++] = sqlTypes[k];
210:                }
211:                return result;
212:            }
213:
214:            public String toLoggableString(Object value,
215:                    SessionFactoryImplementor factory)
216:                    throws HibernateException {
217:
218:                return value == null ? "null" : value.toString();
219:            }
220:
221:            public boolean[] getPropertyNullability() {
222:                return null;
223:            }
224:
225:            public Object fromXMLNode(Node xml, Mapping factory)
226:                    throws HibernateException {
227:                return xml;
228:            }
229:
230:            public void setToXMLNode(Node node, Object value,
231:                    SessionFactoryImplementor factory)
232:                    throws HibernateException {
233:                replaceNode(node, (Element) value);
234:            }
235:
236:            public boolean[] toColumnNullness(Object value, Mapping mapping) {
237:                boolean[] result = new boolean[getColumnSpan(mapping)];
238:                if (value == null)
239:                    return result;
240:                Object[] values = getPropertyValues(value, EntityMode.POJO); //TODO!!!!!!!
241:                int loc = 0;
242:                Type[] propertyTypes = getSubtypes();
243:                for (int i = 0; i < propertyTypes.length; i++) {
244:                    boolean[] propertyNullness = propertyTypes[i]
245:                            .toColumnNullness(values[i], mapping);
246:                    System.arraycopy(propertyNullness, 0, result, loc,
247:                            propertyNullness.length);
248:                    loc += propertyNullness.length;
249:                }
250:                return result;
251:            }
252:
253:            public boolean isDirty(Object old, Object current,
254:                    boolean[] checkable, SessionImplementor session)
255:                    throws HibernateException {
256:                return isDirty(old, current, session);
257:            }
258:
259:            public boolean isEmbedded() {
260:                return false;
261:            }
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.