Source Code Cross Referenced for DbKey.java in  » Web-Framework » helma » helma » objectmodel » db » 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 » Web Framework » helma » helma.objectmodel.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Helma License Notice
003:         *
004:         * The contents of this file are subject to the Helma License
005:         * Version 2.0 (the "License"). You may not use this file except in
006:         * compliance with the License. A copy of the License is available at
007:         * http://adele.helma.org/download/helma/license.txt
008:         *
009:         * Copyright 1998-2003 Helma Software. All Rights Reserved.
010:         *
011:         * $RCSfile$
012:         * $Author: root $
013:         * $Revision: 8604 $
014:         * $Date: 2007-09-28 15:16:38 +0200 (Fre, 28 Sep 2007) $
015:         */
016:
017:        package helma.objectmodel.db;
018:
019:        import java.io.IOException;
020:        import java.io.ObjectInputStream;
021:        import java.io.ObjectOutputStream;
022:        import java.io.Serializable;
023:
024:        /**
025:         *  This is the internal representation of a database key. It is constructed
026:         *  from the logical table (type) name and the object's primary key
027:         *  within the table. Currently only single keys are supported.
028:         */
029:        public final class DbKey implements  Key, Serializable {
030:            // the name of the prototype which defines the storage of this object.
031:            // this is the name of the object's prototype, or one of its ancestors.
032:            // If null, the object is stored in the embedded db.
033:            private String storageName;
034:
035:            // the id that defines this key's object within the above storage space
036:            private String id;
037:
038:            // lazily initialized hashcode
039:            private transient int hashcode = 0;
040:
041:            static final long serialVersionUID = 1618863960930966588L;
042:
043:            /**
044:             * make a key for a persistent Object, describing its datasource and id.
045:             */
046:            public DbKey(DbMapping dbmap, String id) {
047:                this .id = id;
048:                this .storageName = (dbmap == null) ? null : dbmap
049:                        .getStorageTypeName();
050:            }
051:
052:            /**
053:             *
054:             *
055:             * @param what the other key to be compared with this one
056:             *
057:             * @return true if both keys are identical
058:             */
059:            public boolean equals(Object what) {
060:                if (what == this ) {
061:                    return true;
062:                }
063:
064:                if (!(what instanceof  DbKey)) {
065:                    return false;
066:                }
067:
068:                DbKey k = (DbKey) what;
069:
070:                // storageName is an interned string (by DbMapping, from where we got it)
071:                // so we can compare by using == instead of the equals method.
072:                return (storageName == k.storageName)
073:                        && ((id == k.id) || id.equals(k.id));
074:            }
075:
076:            /**
077:             *
078:             *
079:             * @return this key's hash code
080:             */
081:            public int hashCode() {
082:                if (hashcode == 0) {
083:                    hashcode = (storageName == null) ? (17 + (37 * id
084:                            .hashCode()))
085:                            : (17 + (37 * storageName.hashCode()) + (+37 * id
086:                                    .hashCode()));
087:                }
088:
089:                return hashcode;
090:            }
091:
092:            /**
093:             *
094:             *
095:             * @return the key of this key's object's parent object
096:             */
097:            public Key getParentKey() {
098:                return null;
099:            }
100:
101:            /**
102:             *
103:             *
104:             * @return the unique storage name for this key's object
105:             */
106:            public String getStorageName() {
107:                return storageName;
108:            }
109:
110:            /**
111:             *
112:             *
113:             * @return this key's object's id
114:             */
115:            public String getID() {
116:                return id;
117:            }
118:
119:            /**
120:             *
121:             *
122:             * @return a string representation for this key
123:             */
124:            public String toString() {
125:                return (storageName == null) ? ("[" + id + "]") : (storageName
126:                        + "[" + id + "]");
127:            }
128:
129:            // We implement write/readObject to set storageName
130:            // to the interned version of the string.
131:
132:            private void writeObject(ObjectOutputStream stream)
133:                    throws IOException {
134:                stream.writeObject(storageName);
135:                stream.writeObject(id);
136:            }
137:
138:            private void readObject(ObjectInputStream stream)
139:                    throws IOException, ClassNotFoundException {
140:                storageName = (String) stream.readObject();
141:                id = (String) stream.readObject();
142:                // if storageName is not null, set it to the interned version
143:                if (storageName != null) {
144:                    storageName = storageName.intern();
145:                }
146:            }
147:
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.