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


001:        /**********************************************************************
002:        Copyright (c) 2003 Erik Bengtson 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:        Contributors:
016:        2003 Andy Jefferson - coding standards
017:        2006 Michael Brown - updated to cater for alternative types in the PK fields
018:        	...
019:         **********************************************************************/package org.jpox.store.mapping;
020:
021:        import javax.jdo.spi.PersistenceCapable;
022:        import javax.jdo.spi.PersistenceCapable.ObjectIdFieldConsumer;
023:
024:        import org.jpox.ObjectManager;
025:        import org.jpox.util.Localiser;
026:
027:        /**
028:         * Parameter setter class to deal with application identity.
029:         * Parameters must be in the same order as the fields.
030:         *
031:         * @version $Revision: 1.8 $ 
032:         */
033:        class AppIDObjectIdFieldConsumer implements  ObjectIdFieldConsumer {
034:            /** Localisation of messages. */
035:            protected static final Localiser LOCALISER = Localiser
036:                    .getInstance("org.jpox.store.Localisation");
037:
038:            /** Parameter positions in the PreparedStatement. */
039:            private int[] params;
040:
041:            /** Next parameter index. Increased each call. */
042:            private int nextParam;
043:
044:            /** The Object Manager */
045:            private ObjectManager om;
046:
047:            /** The PreparedStatement to populate. */
048:            private Object statement;
049:
050:            /** The mappings for the object id */
051:            private JavaTypeMapping[] javaTypeMappings;
052:
053:            /** Number of the mapping being processed. */
054:            private int mappingNum = 0;
055:
056:            /**
057:             * Constructor.
058:             * @param param Parameter positions
059:             * @param om ObjectManager
060:             * @param statement PreparedStatement
061:             * @param javaTypeMappings Java mappings for the PC object
062:             */
063:            public AppIDObjectIdFieldConsumer(int[] param, ObjectManager om,
064:                    Object statement, JavaTypeMapping[] javaTypeMappings) {
065:                this .params = param;
066:                nextParam = 0;
067:                this .om = om;
068:                this .statement = statement;
069:
070:                // Save all mappings in the same order, allowing for PersistenceCapableMapping having sub mappings
071:                int numMappings = 0;
072:                for (int i = 0; i < javaTypeMappings.length; i++) {
073:                    if (javaTypeMappings[i] instanceof  PersistenceCapableMapping) {
074:                        numMappings += ((PersistenceCapableMapping) javaTypeMappings[i])
075:                                .getJavaTypeMapping().length;
076:                    } else {
077:                        numMappings++;
078:                    }
079:                }
080:                this .javaTypeMappings = new JavaTypeMapping[numMappings];
081:                int mappingNum = 0;
082:                for (int i = 0; i < javaTypeMappings.length; i++) {
083:                    if (javaTypeMappings[i] instanceof  PersistenceCapableMapping) {
084:                        PersistenceCapableMapping m = (PersistenceCapableMapping) javaTypeMappings[i];
085:                        JavaTypeMapping[] subMappings = m.javaTypeMappings;
086:                        for (int j = 0; j < subMappings.length; j++) {
087:                            this .javaTypeMappings[mappingNum++] = subMappings[j];
088:                        }
089:                    } else {
090:                        this .javaTypeMappings[mappingNum++] = javaTypeMappings[i];
091:                    }
092:                }
093:            }
094:
095:            /**
096:             * Convenience method to return the statement param position(s) for a field.
097:             * @param mapping The mapping
098:             * @return The param positions
099:             */
100:            private int[] getParamsForField(JavaTypeMapping mapping) {
101:                if (javaTypeMappings.length == 1) {
102:                    return params;
103:                } else {
104:                    int numCols = mapping.getNumberOfDatastoreFields();
105:                    int[] fieldParams = new int[numCols];
106:                    for (int i = 0; i < numCols; i++) {
107:                        fieldParams[i] = params[nextParam++];
108:                    }
109:                    return fieldParams;
110:                }
111:            }
112:
113:            /**
114:             * Method to store a boolean in a field.
115:             * @param fieldNumber Number of the field
116:             * @param value The value to use
117:             */
118:            public void storeBooleanField(int fieldNumber, boolean value) {
119:                JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
120:                mapping.setBoolean(om, statement, getParamsForField(mapping),
121:                        value);
122:            }
123:
124:            /**
125:             * Method to store a byte in a field.
126:             * @param fieldNumber Number of the field
127:             * @param value The value to use
128:             */
129:            public void storeByteField(int fieldNumber, byte value) {
130:                JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
131:                mapping.setByte(om, statement, getParamsForField(mapping),
132:                        value);
133:            }
134:
135:            /**
136:             * Method to store a character in a field.
137:             * @param fieldNumber Number of the field
138:             * @param value The value to use
139:             */
140:            public void storeCharField(int fieldNumber, char value) {
141:                JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
142:                mapping.setChar(om, statement, getParamsForField(mapping),
143:                        value);
144:            }
145:
146:            /**
147:             * Method to store a double in a field.
148:             * @param fieldNumber Number of the field
149:             * @param value The value to use
150:             */
151:            public void storeDoubleField(int fieldNumber, double value) {
152:                JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
153:                mapping.setDouble(om, statement, getParamsForField(mapping),
154:                        value);
155:            }
156:
157:            /**
158:             * Method to store a float in a field.
159:             * @param fieldNumber Number of the field
160:             * @param value The value to use
161:             */
162:            public void storeFloatField(int fieldNumber, float value) {
163:                JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
164:                mapping.setFloat(om, statement, getParamsForField(mapping),
165:                        value);
166:            }
167:
168:            /**
169:             * Method to store an integer in a field.
170:             * @param fieldNumber Number of the field
171:             * @param value The value to use
172:             */
173:            public void storeIntField(int fieldNumber, int value) {
174:                JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
175:                mapping
176:                        .setInt(om, statement, getParamsForField(mapping),
177:                                value);
178:            }
179:
180:            /**
181:             * Method to store a long in a field.
182:             * @param fieldNumber Number of the field
183:             * @param value The value to use
184:             */
185:            public void storeLongField(int fieldNumber, long value) {
186:                JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
187:                mapping.setLong(om, statement, getParamsForField(mapping),
188:                        value);
189:            }
190:
191:            /**
192:             * Method to store a short in a field.
193:             * @param fieldNumber Number of the field
194:             * @param value The value to use
195:             */
196:            public void storeShortField(int fieldNumber, short value) {
197:                JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
198:                mapping.setShort(om, statement, getParamsForField(mapping),
199:                        value);
200:            }
201:
202:            /**
203:             * Method to store a String in a field.
204:             * @param fieldNumber Number of the field
205:             * @param value The value to use
206:             */
207:            public void storeStringField(int fieldNumber, String value) {
208:                JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
209:                mapping.setString(om, statement, getParamsForField(mapping),
210:                        value);
211:            }
212:
213:            /**
214:             * Method to store an object in a field.
215:             * @param fieldNumber Number of the field
216:             * @param value The value to use
217:             */
218:            public void storeObjectField(int fieldNumber, Object value) {
219:                if (om.getApiAdapter().isPersistable(value)) {
220:                    PersistenceCapable pc = (PersistenceCapable) value;
221:                    pc.jdoCopyKeyFieldsFromObjectId(this , pc.jdoGetObjectId());
222:                } else {
223:                    JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
224:                    mapping.setObject(om, statement,
225:                            getParamsForField(mapping), value);
226:                }
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.