Source Code Cross Referenced for IdentityStrategy.java in  » Database-ORM » JPOX » org » jpox » metadata » 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 » JPOX » org.jpox.metadata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************
002:        Copyright (c) 2004 Andy Jefferson and others. All rights reserved. 
003:        Licensed under the Apache License, Version 2.0 (the "License");
004:        you may not use this file except in compliance with the License.
005:        You may obtain a copy of the License at
006:
007:            http://www.apache.org/licenses/LICENSE-2.0
008:
009:        Unless required by applicable law or agreed to in writing, software
010:        distributed under the License is distributed on an "AS IS" BASIS,
011:        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        See the License for the specific language governing permissions and
013:        limitations under the License. 
014:         
015:
016:        Contributors:
017:            ...
018:         **********************************************************************/package org.jpox.metadata;
019:
020:        import java.io.Serializable;
021:
022:        /**
023:         * Representation of the values for identity "strategy".
024:         *
025:         * @since 1.1 
026:         * @version $Revision: 1.16 $
027:         */
028:        public class IdentityStrategy implements  Serializable {
029:            /**
030:             * strategy="native" in JDO, and "auto" in JPA
031:             * 
032:             * The value "native" allows the JDO implementation to pick the most
033:             * suitable strategy based on the underlying database.
034:             */
035:            public static final IdentityStrategy NATIVE = new IdentityStrategy(
036:                    1);
037:
038:            /**
039:             * strategy="sequence" in JDO and JPA
040:             * 
041:             * The value "sequence" specifies that a named database sequence is used to
042:             * generate key values for the table. If sequence is used, then the
043:             * sequence-name attribute is required.
044:             */
045:            public static final IdentityStrategy SEQUENCE = new IdentityStrategy(
046:                    2);
047:
048:            /**
049:             * strategy="identity" in JDO and JPA
050:             * 
051:             * The value "identity" specifies that the column identified as the key
052:             * column is managed by the database as an autoincrementing identity type.
053:             */
054:            public static final IdentityStrategy IDENTITY = new IdentityStrategy(
055:                    3);
056:
057:            /**
058:             * strategy="increment" in JDO and "table" in JPA
059:             * 
060:             * The value "increment" specifies a strategy that simply finds the largest
061:             * key already in the database and increments the key value for new
062:             * instances. It can be used with integral column types when the JDO
063:             * application is the only database user inserting new instances.
064:             */
065:            public static final IdentityStrategy INCREMENT = new IdentityStrategy(
066:                    4);
067:
068:            /**
069:             * strategy="uuid-string"
070:             * 
071:             * The value "uuid-string" specifies a strategy that generates a 128-bit
072:             * UUID unique within a network (the IP address of the machine running the
073:             * application is part of the id) and represents the result as a
074:             * 16-character String.
075:             */
076:            public static final IdentityStrategy UUIDSTRING = new IdentityStrategy(
077:                    5);
078:
079:            /**
080:             * strategy="uuid-hex"
081:             * 
082:             * The value "uuid-hex" specifies a strategy that generates a 128-bit UUID
083:             * unique within a network (the IP address of the machine running the
084:             * application is part of the id) and represents the result as a
085:             * 32-character String.
086:             */
087:            public static final IdentityStrategy UUIDHEX = new IdentityStrategy(
088:                    6);
089:
090:            /**
091:             * An extension strategy not in the standard JDO/JPA list.
092:             * Will have the "customName" set to the chosen strategy.
093:             * This object only exists for use in the equals() method to check if something is CUSTOM.
094:             */
095:            public static final IdentityStrategy CUSTOM = new IdentityStrategy(
096:                    7);
097:
098:            /** The type id. */
099:            private final int typeId;
100:
101:            /** The Name of the custom type (if CUSTOM). */
102:            private String customName;
103:
104:            /**
105:             * constructor
106:             * @param i type id
107:             */
108:            private IdentityStrategy(int i) {
109:                this .typeId = i;
110:            }
111:
112:            /**
113:             * Accessor for the custom name (if using strategy type of CUSTOM).
114:             * @return Custom name
115:             */
116:            public String getCustomName() {
117:                return customName;
118:            }
119:
120:            /**
121:             * Indicates whether some other object is "equal to" this one.
122:             * @param o the reference object with which to compare. 
123:             * @return true if this object is the same as the obj argument;
124:             *         false otherwise.
125:             */
126:            public boolean equals(Object o) {
127:                if (o instanceof  IdentityStrategy) {
128:                    return ((IdentityStrategy) o).typeId == typeId;
129:                }
130:                return false;
131:            }
132:
133:            /**
134:             * Returns a string representation of the object.
135:             * @return a string representation of the object.
136:             */
137:            public String toString() {
138:                switch (typeId) {
139:                case 1:
140:                    return "native";
141:                case 2:
142:                    return "sequence";
143:                case 3:
144:                    return "identity";
145:                case 4:
146:                    return "increment";
147:                case 5:
148:                    return "uuid-string";
149:                case 6:
150:                    return "uuid-hex";
151:                case 7:
152:                    return "custom";
153:                }
154:                return "";
155:            }
156:
157:            /**
158:             * Accessor for the type.
159:             * @return Type
160:             **/
161:            public int getType() {
162:                return typeId;
163:            }
164:
165:            /**
166:             * Gets an IdentityStrategy for the given value argument.
167:             * @param value the String representation of IdentityStrategy
168:             * @return the IdentityStrategy corresponding to the value argument. NATIVE
169:             * IdentityStrategy is returned if the value argument is null or no
170:             * corresponding strategy was found
171:             */
172:            public static IdentityStrategy getIdentityStrategy(
173:                    final String value) {
174:                if (value == null) {
175:                    return IdentityStrategy.NATIVE;
176:                } else if (IdentityStrategy.NATIVE.toString().equals(value)) {
177:                    return IdentityStrategy.NATIVE;
178:                } else if (IdentityStrategy.SEQUENCE.toString().equals(value)) {
179:                    return IdentityStrategy.SEQUENCE;
180:                } else if (IdentityStrategy.IDENTITY.toString().equals(value)) {
181:                    return IdentityStrategy.IDENTITY;
182:                } else if (IdentityStrategy.INCREMENT.toString().equals(value)) {
183:                    return IdentityStrategy.INCREMENT;
184:                } else if ("TABLE".equalsIgnoreCase(value)) {
185:                    // JPA "table" strategy equates to JDO "increment"
186:                    return IdentityStrategy.INCREMENT;
187:                } else if (IdentityStrategy.UUIDSTRING.toString().equals(value)) {
188:                    return IdentityStrategy.UUIDSTRING;
189:                } else if (IdentityStrategy.UUIDHEX.toString().equals(value)) {
190:                    return IdentityStrategy.UUIDHEX;
191:                } else {
192:                    // All other strategies have their own strategy object
193:                    IdentityStrategy strategy = new IdentityStrategy(7);
194:                    strategy.customName = value;
195:                    return strategy;
196:                }
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.