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


001:        //$Id: EntityUniqueKey.java 9194 2006-02-01 19:59:07Z steveebersole $
002:        package org.hibernate.engine;
003:
004:        import org.hibernate.EntityMode;
005:        import org.hibernate.pretty.MessageHelper;
006:        import org.hibernate.type.Type;
007:
008:        import java.io.Serializable;
009:        import java.io.ObjectOutputStream;
010:        import java.io.IOException;
011:        import java.io.ObjectInputStream;
012:
013:        /**
014:         * Used to uniquely key an entity instance in relation to a particular session
015:         * by some unique property reference, as opposed to identifier.
016:         * <p/>
017:         * Uniqueing information consists of the entity-name, the referenced
018:         * property name, and the referenced property value.
019:         *
020:         * @see EntityKey
021:         * @author Gavin King
022:         */
023:        public class EntityUniqueKey implements  Serializable {
024:            private final String uniqueKeyName;
025:            private final String entityName;
026:            private final Object key;
027:            private final Type keyType;
028:            private final EntityMode entityMode;
029:            private final int hashCode;
030:
031:            public EntityUniqueKey(final String entityName,
032:                    final String uniqueKeyName, final Object semiResolvedKey,
033:                    final Type keyType, final EntityMode entityMode,
034:                    final SessionFactoryImplementor factory) {
035:                this .uniqueKeyName = uniqueKeyName;
036:                this .entityName = entityName;
037:                this .key = semiResolvedKey;
038:                this .keyType = keyType.getSemiResolvedType(factory);
039:                this .entityMode = entityMode;
040:                this .hashCode = generateHashCode(factory);
041:            }
042:
043:            public String getEntityName() {
044:                return entityName;
045:            }
046:
047:            public Object getKey() {
048:                return key;
049:            }
050:
051:            public String getUniqueKeyName() {
052:                return uniqueKeyName;
053:            }
054:
055:            public int generateHashCode(SessionFactoryImplementor factory) {
056:                int result = 17;
057:                result = 37 * result + entityName.hashCode();
058:                result = 37 * result + uniqueKeyName.hashCode();
059:                result = 37 * result
060:                        + keyType.getHashCode(key, entityMode, factory);
061:                return result;
062:            }
063:
064:            public int hashCode() {
065:                return hashCode;
066:            }
067:
068:            public boolean equals(Object other) {
069:                EntityUniqueKey that = (EntityUniqueKey) other;
070:                return that.entityName.equals(entityName)
071:                        && that.uniqueKeyName.equals(uniqueKeyName)
072:                        && keyType.isEqual(that.key, key, entityMode);
073:            }
074:
075:            public String toString() {
076:                return "EntityUniqueKey"
077:                        + MessageHelper.infoString(entityName, uniqueKeyName,
078:                                key);
079:            }
080:
081:            private void writeObject(ObjectOutputStream oos) throws IOException {
082:                checkAbilityToSerialize();
083:                oos.defaultWriteObject();
084:            }
085:
086:            private void checkAbilityToSerialize() {
087:                // The unique property value represented here may or may not be
088:                // serializable, so we do an explicit check here in order to generate
089:                // a better error message
090:                if (key != null
091:                        && !Serializable.class.isAssignableFrom(key.getClass())) {
092:                    throw new IllegalStateException(
093:                            "Cannot serialize an EntityUniqueKey which represents a non "
094:                                    + "serializable property value ["
095:                                    + entityName + "." + uniqueKeyName + "]");
096:                }
097:            }
098:
099:            /**
100:             * Custom serialization routine used during serialization of a
101:             * Session/PersistenceContext for increased performance.
102:             *
103:             * @param oos The stream to which we should write the serial data.
104:             * @throws IOException
105:             */
106:            void serialize(ObjectOutputStream oos) throws IOException {
107:                checkAbilityToSerialize();
108:                oos.writeObject(uniqueKeyName);
109:                oos.writeObject(entityName);
110:                oos.writeObject(key);
111:                oos.writeObject(keyType);
112:                oos.writeObject(entityMode);
113:            }
114:
115:            /**
116:             * Custom deserialization routine used during deserialization of a
117:             * Session/PersistenceContext for increased performance.
118:             *
119:             * @param ois The stream from which to read the entry.
120:             * @param session The session being deserialized.
121:             * @return The deserialized EntityEntry
122:             * @throws IOException
123:             * @throws ClassNotFoundException
124:             */
125:            static EntityUniqueKey deserialize(ObjectInputStream ois,
126:                    SessionImplementor session) throws IOException,
127:                    ClassNotFoundException {
128:                return new EntityUniqueKey((String) ois.readObject(),
129:                        (String) ois.readObject(), ois.readObject(), (Type) ois
130:                                .readObject(), (EntityMode) ois.readObject(),
131:                        session.getFactory());
132:            }
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.