01: /**********************************************************************
02: Copyright (c) 2007 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: Contributors:
16: ...
17: **********************************************************************/package org.jpox;
18:
19: import javax.jdo.JDOHelper;
20: import javax.jdo.PersistenceManager;
21: import javax.jdo.spi.PersistenceCapable;
22:
23: import org.jpox.jdo.AbstractPersistenceManager;
24:
25: /**
26: * Helper methods for accessing the ObjectManager for particular objects.
27: *
28: * @version $Revision: 1.3 $
29: */
30: public class ObjectManagerHelper {
31: /**
32: * Accessor for the ObjectManager for a PersistenceCapable object
33: * @param pc The PersistenceCapable object
34: * @return Its ObjectManager (if any)
35: */
36: public static ObjectManager getObjectManager(PersistenceCapable pc) {
37: if (pc == null) {
38: return null;
39: }
40: PersistenceManager pm = JDOHelper.getPersistenceManager(pc);
41: if (pm == null) {
42: return null;
43: }
44: return ((AbstractPersistenceManager) pm).getObjectManager();
45: }
46:
47: /**
48: * Accessor for the ObjectManager for a PersistenceManager.
49: * @param pm The PM
50: * @return The ObjectManager
51: */
52: public static ObjectManager getObjectManager(PersistenceManager pm) {
53: if (pm == null) {
54: return null;
55: }
56: return ((AbstractPersistenceManager) pm).getObjectManager();
57: }
58:
59: /**
60: * Accessor for the ObjectManager for an Object.
61: * @param obj The Object
62: * @return The ObjectManager
63: */
64: public static ObjectManager getObjectManager(Object obj) {
65: if (obj == null) {
66: return null;
67: }
68: if (obj instanceof PersistenceCapable) {
69: return getObjectManager((PersistenceCapable) obj);
70: } else if (obj instanceof PersistenceManager) {
71: return getObjectManager((PersistenceManager) obj);
72: }
73: return null;
74: }
75: }
|