01: /**********************************************************************
02: Copyright (c) 20026 Erik Bengtson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15:
16: Contributors:
17: ...
18: **********************************************************************/package org.jpox.store.mapping;
19:
20: import org.jpox.ObjectManager;
21: import org.jpox.api.ApiAdapter;
22:
23: /**
24: * Maps to identity objects of PersistenceCapable values.
25: *
26: * Used only from within JDOQL queries on JDOHelper.getObjectId expressions
27: *
28: * @version $Revision: 1.4 $
29: **/
30: public class ObjectIdClassMapping extends PersistenceCapableMapping {
31:
32: /**
33: * Constructor used to generate a PCMapping representing only the identity of the object.
34: * This is typically used where the user has selected the id in a JDOQL query as a result field.
35: * @param pcMapping The mapping to base it on
36: */
37: public ObjectIdClassMapping(PersistenceCapableMapping pcMapping) {
38: super ();
39: initialize(pcMapping.dba, pcMapping.type);
40: datastoreContainer = pcMapping.datastoreContainer;
41:
42: // Add the same field mappings to the identity
43: javaTypeMappings = new JavaTypeMapping[pcMapping.javaTypeMappings.length];
44: System.arraycopy(pcMapping.javaTypeMappings, 0,
45: javaTypeMappings, 0, javaTypeMappings.length);
46: }
47:
48: /**
49: * Returns a instance of a PersistenceCapable class.
50: * Processes a FK field and converts the id stored firstly into an OID/AID
51: * and then into the object that the FK id relates to.
52: * @param om The ObjectManager
53: * @param rs The ResultSet
54: * @param param Array of parameter ids in the ResultSet to retrieve
55: * @return The Persistence Capable object
56: */
57: public Object getObject(ObjectManager om, final Object rs,
58: int[] param) {
59: Object value = super .getObject(om, rs, param);
60: if (value != null) {
61: ApiAdapter api = om.getApiAdapter();
62: return api.getIdForObject(value);
63: }
64: return null;
65: }
66: }
|