Source Code Cross Referenced for EntityKey.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: EntityKey.java 9194 2006-02-01 19:59:07Z steveebersole $
002:        package org.hibernate.engine;
003:
004:        import java.io.Serializable;
005:        import java.io.ObjectOutputStream;
006:        import java.io.IOException;
007:        import java.io.ObjectInputStream;
008:
009:        import org.hibernate.AssertionFailure;
010:        import org.hibernate.EntityMode;
011:        import org.hibernate.util.SerializationHelper;
012:        import org.hibernate.persister.entity.EntityPersister;
013:        import org.hibernate.pretty.MessageHelper;
014:        import org.hibernate.type.Type;
015:
016:        /**
017:         * Uniquely identifies of an entity instance in a particular session by identifier.
018:         * <p/>
019:         * Uniqueing information consists of the entity-name and the identifier value.
020:         *
021:         * @see EntityUniqueKey
022:         * @author Gavin King
023:         */
024:        public final class EntityKey implements  Serializable {
025:            private final Serializable identifier;
026:            private final String rootEntityName;
027:            private final String entityName;
028:            private final Type identifierType;
029:            private final boolean isBatchLoadable;
030:            private final SessionFactoryImplementor factory;
031:            private final int hashCode;
032:            private final EntityMode entityMode;
033:
034:            /**
035:             * Construct a unique identifier for an entity class instance
036:             */
037:            public EntityKey(Serializable id, EntityPersister persister,
038:                    EntityMode entityMode) {
039:                if (id == null) {
040:                    throw new AssertionFailure("null identifier");
041:                }
042:                this .identifier = id;
043:                this .entityMode = entityMode;
044:                this .rootEntityName = persister.getRootEntityName();
045:                this .entityName = persister.getEntityName();
046:                this .identifierType = persister.getIdentifierType();
047:                this .isBatchLoadable = persister.isBatchLoadable();
048:                this .factory = persister.getFactory();
049:                hashCode = generateHashCode(); //cache the hashcode
050:            }
051:
052:            /**
053:             * Used to reconstruct an EntityKey during deserialization.
054:             *
055:             * @param identifier The identifier value
056:             * @param rootEntityName The root entity name
057:             * @param entityName The specific entity name
058:             * @param identifierType The type of the identifier value
059:             * @param batchLoadable Whether represented entity is eligible for batch loading
060:             * @param factory The session factory
061:             * @param entityMode The entity's entity mode
062:             */
063:            private EntityKey(Serializable identifier, String rootEntityName,
064:                    String entityName, Type identifierType,
065:                    boolean batchLoadable, SessionFactoryImplementor factory,
066:                    EntityMode entityMode) {
067:                this .identifier = identifier;
068:                this .rootEntityName = rootEntityName;
069:                this .entityName = entityName;
070:                this .identifierType = identifierType;
071:                this .isBatchLoadable = batchLoadable;
072:                this .factory = factory;
073:                this .entityMode = entityMode;
074:                this .hashCode = generateHashCode();
075:            }
076:
077:            public boolean isBatchLoadable() {
078:                return isBatchLoadable;
079:            }
080:
081:            /**
082:             * Get the user-visible identifier
083:             */
084:            public Serializable getIdentifier() {
085:                return identifier;
086:            }
087:
088:            public String getEntityName() {
089:                return entityName;
090:            }
091:
092:            public boolean equals(Object other) {
093:                EntityKey otherKey = (EntityKey) other;
094:                return otherKey.rootEntityName.equals(this .rootEntityName)
095:                        && identifierType.isEqual(otherKey.identifier,
096:                                this .identifier, entityMode, factory);
097:            }
098:
099:            private int generateHashCode() {
100:                int result = 17;
101:                result = 37 * result + rootEntityName.hashCode();
102:                result = 37
103:                        * result
104:                        + identifierType.getHashCode(identifier, entityMode,
105:                                factory);
106:                return result;
107:            }
108:
109:            public int hashCode() {
110:                return hashCode;
111:            }
112:
113:            public String toString() {
114:                return "EntityKey"
115:                        + MessageHelper.infoString(factory
116:                                .getEntityPersister(entityName), identifier,
117:                                factory);
118:            }
119:
120:            /**
121:             * Custom serialization routine used during serialization of a
122:             * Session/PersistenceContext for increased performance.
123:             *
124:             * @param oos The stream to which we should write the serial data.
125:             * @throws IOException
126:             */
127:            void serialize(ObjectOutputStream oos) throws IOException {
128:                oos.writeObject(identifier);
129:                oos.writeObject(rootEntityName);
130:                oos.writeObject(entityName);
131:                oos.writeObject(identifierType);
132:                oos.writeBoolean(isBatchLoadable);
133:                oos.writeObject(entityMode.toString());
134:            }
135:
136:            /**
137:             * Custom deserialization routine used during deserialization of a
138:             * Session/PersistenceContext for increased performance.
139:             *
140:             * @param ois The stream from which to read the entry.
141:             * @param session The session being deserialized.
142:             * @return The deserialized EntityEntry
143:             * @throws IOException
144:             * @throws ClassNotFoundException
145:             */
146:            static EntityKey deserialize(ObjectInputStream ois,
147:                    SessionImplementor session) throws IOException,
148:                    ClassNotFoundException {
149:                return new EntityKey((Serializable) ois.readObject(),
150:                        (String) ois.readObject(), (String) ois.readObject(),
151:                        (Type) ois.readObject(), ois.readBoolean(), session
152:                                .getFactory(), EntityMode.parse((String) ois
153:                                .readObject()));
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.