Source Code Cross Referenced for SpeedoIdentity.java in  » Database-ORM » Speedo_1.4.5 » org » objectweb » speedo » 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 » Speedo_1.4.5 » org.objectweb.speedo.metadata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Speedo: an implementation of JDO compliant personality on top of JORM generic
003:         * I/O sub-system.
004:         * Copyright (C) 2001-2004 France Telecom R&D
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         *
021:         *
022:         * Contact: speedo@objectweb.org
023:         *
024:         * Authors: S.Chassande-Barrioz.
025:         *
026:         */package org.objectweb.speedo.metadata;
027:
028:        import java.util.List;
029:
030:        import org.objectweb.speedo.api.SpeedoException;
031:
032:        /**
033:         * This class corresponds to the description of the policy management for a
034:         * given identity.
035:         * @author	S.Chassande-Barrioz
036:         */
037:        public final class SpeedoIdentity extends SpeedoElement {
038:            public final static byte NO_ID = 0;
039:            public final static byte USER_ID = 1;
040:            public final static byte DATASTORE_OLONG = 2;
041:            public final static byte DATASTORE_LONG = 3;
042:            public final static byte DATASTORE_NATIVE = DATASTORE_LONG;
043:            public final static byte DATASTORE_POLYMORPHID = 4;
044:            public final static byte DATASTORE_SEQUENCE = 5;
045:            public final static byte DATASTORE_AUTO_ASSIGN = 6;
046:            public final static byte DATASTORE_INCREMENT = 7;
047:            public final static byte DATASTORE_UUID_STRING = 8;
048:            public final static byte DATASTORE_UUID_HEX = 9;
049:
050:            /**
051:             * identifier strategy
052:             */
053:            public byte strategy = DATASTORE_NATIVE;
054:
055:            /**
056:             * the class used as identifier
057:             */
058:            public String objectidClass;
059:            public Class objectidJClass;
060:
061:            public boolean oidClassAutoCalculated = false;
062:
063:            /**
064:             * the name of the sequence in case of the strategy is #DATASTORE_SEQUENCE
065:             */
066:            public String sequenceName;
067:
068:            /**
069:             * is the columns used for the identifier which have not been mapped in 
070:             * memory by visible persistent fields. 
071:             */
072:            public SpeedoNoFieldColumn[] columns;
073:
074:            public SpeedoIdentity() {
075:                SpeedoDefaults.setDefaults(this );
076:            }
077:
078:            /**
079:             * Transforms a String into a Byte. The String must corresponds to local variables.
080:             * It returns the byte associated with the variable.
081:             * @param s String to transform.
082:             * @return the byte associated to the String.
083:             */
084:            public static byte getStrategy(String s) {
085:                if (s.equalsIgnoreCase("application"))
086:                    return USER_ID;
087:                else if (s.equalsIgnoreCase("datastore"))
088:                    return DATASTORE_NATIVE;
089:                else if (s.equalsIgnoreCase("sequence"))
090:                    return DATASTORE_SEQUENCE;
091:                else if (s.equalsIgnoreCase("native"))
092:                    return DATASTORE_NATIVE;
093:                else if (s.equalsIgnoreCase("autoassign"))
094:                    return DATASTORE_AUTO_ASSIGN;
095:                else if (s.equalsIgnoreCase("increment"))
096:                    return DATASTORE_INCREMENT;
097:                else if (s.equalsIgnoreCase("uuid-string"))
098:                    return DATASTORE_UUID_STRING;
099:                else if (s.equalsIgnoreCase("uuid-hex"))
100:                    return DATASTORE_UUID_HEX;
101:                else if (s.equalsIgnoreCase("polymorph2l"))
102:                    return DATASTORE_POLYMORPHID;
103:                else
104:                    return DATASTORE_NATIVE;
105:            }
106:
107:            public static String getStrategyName(byte s) {
108:                switch (s) {
109:                case NO_ID:
110:                    return "NO_ID";
111:                case USER_ID:
112:                    return "USER_ID";
113:                case DATASTORE_OLONG:
114:                    return "DATASTORE_OLONG";
115:                case DATASTORE_POLYMORPHID:
116:                    return "DATASTORE_POLYMORPHID";
117:                case DATASTORE_SEQUENCE:
118:                    return "DATASTORE_SEQUENCE";
119:                case DATASTORE_AUTO_ASSIGN:
120:                    return "DATASTORE_AUTO_ASSIGN";
121:                case DATASTORE_INCREMENT:
122:                    return "DATASTORE_INCREMENT";
123:                case DATASTORE_UUID_STRING:
124:                    return "DATASTORE_UUID_STRING";
125:                case DATASTORE_UUID_HEX:
126:                    return "DATASTORE_UUID_HEX";
127:
128:                case DATASTORE_NATIVE:
129:                default:
130:                    return "DATASTORE_NATIVE";
131:                }
132:            }
133:
134:            public void setDatastoreIdSequenceName(String sequencename) {
135:                strategy = DATASTORE_SEQUENCE;
136:                sequenceName = sequencename;
137:            }
138:
139:            public boolean isDataStore() {
140:                return strategy > USER_ID;
141:            }
142:
143:            public String getStrategyName() {
144:                return getStrategyName(strategy);
145:            }
146:
147:            /**
148:             * Assignes SpeedoColumn for the identifier. This list of SpeedoColumn is
149:             * transformed into an array of SpeedoNoFieldColumn 
150:             * @param columns is a list of SpeedoColumn
151:             * @throws SpeedoException if the strategy does not correspond to the 
152:             * specified column (too many column, no strategy defined, 
153:             * application staregy choosen, ...)
154:             * @see #columns
155:             */
156:            public void setColumns(List columns) throws SpeedoException {
157:                switch (strategy) {
158:                case NO_ID:
159:                    throw new SpeedoException(
160:                            "No identifier strategy defined !");
161:                case USER_ID:
162:                    throw new SpeedoException(
163:                            "Application identifier cannot have hidden column(s): "
164:                                    + columns);
165:                case DATASTORE_LONG:
166:                    setNoFieldColumn(columns, new Class[] { Long.TYPE });
167:                    break;
168:                case DATASTORE_OLONG:
169:                case DATASTORE_SEQUENCE:
170:                case DATASTORE_AUTO_ASSIGN:
171:                case DATASTORE_INCREMENT:
172:                    setNoFieldColumn(columns, new Class[] { Long.class });
173:                    break;
174:                case DATASTORE_POLYMORPHID:
175:                    setNoFieldColumn(columns, new Class[] { Long.TYPE,
176:                            Long.TYPE });
177:                    break;
178:
179:                case DATASTORE_UUID_STRING:
180:                case DATASTORE_UUID_HEX:
181:                    setNoFieldColumn(columns, new Class[] { String.class });
182:                    break;
183:                }
184:            }
185:
186:            /**
187:             * Assignes SpeedoColumn for the identifier. This list of SpeedoColumn is
188:             * transformed into an array of SpeedoNoFieldColumn 
189:             * @param columns is a list of SpeedoColumn
190:             * @param memoryTypes is a list of expected memory types corresponding to 
191:             * the column.
192:             * @throws SpeedoException if the strategy does not correspond to the 
193:             * specified column (too many column, no strategy defined, 
194:             * application staregy choosen, ...)
195:             * @see #columns
196:             */
197:            private void setNoFieldColumn(List cols, Class[] memoryTypes)
198:                    throws SpeedoException {
199:                if (cols.size() != memoryTypes.length) {
200:                    throw new SpeedoException("The identity strategy '"
201:                            + getStrategyName(strategy) + "' requires "
202:                            + memoryTypes.length + " column(s): " + columns);
203:                }
204:                SpeedoNoFieldColumn[] nfcs = new SpeedoNoFieldColumn[cols
205:                        .size()];
206:                for (int i = 0; i < nfcs.length; i++) {
207:                    nfcs[i] = new SpeedoNoFieldColumn();
208:                    nfcs[i].column = (SpeedoColumn) cols.get(i);
209:                    if (memoryTypes[i] != null) {
210:                        nfcs[i].type = memoryTypes[i].getName();
211:                    } else {
212:
213:                    }
214:                }
215:                this .columns = nfcs;
216:            }
217:
218:            public String toString() {
219:                StringBuffer sb = new StringBuffer(super .toString());
220:                final String sep = " / ";
221:                sb.append(sep).append("strategy=").append(getStrategyName());
222:                switch (strategy) {
223:                case USER_ID:
224:                    sb.append(sep).append("objectidClass=").append(
225:                            objectidClass);
226:                    break;
227:                case DATASTORE_SEQUENCE:
228:                    sb.append(sep).append("sequenceName=").append(sequenceName);
229:                    break;
230:                }
231:                return sb.toString();
232:            }
233:
234:            public void merge(SpeedoIdentity id) {
235:                this.jdoExtension = id.jdoExtension;
236:                this.objectidClass = id.objectidClass;
237:                this.sequenceName = id.sequenceName;
238:                this.strategy = id.strategy;
239:                if (this.columns == null) {
240:                    this.columns = id.columns;
241:                }
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.