01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdo;
12:
13: import javax.jdo.PersistenceManager;
14: import javax.jdo.spi.PersistenceCapable;
15:
16: import com.versant.core.common.BindingSupportImpl;
17: import com.versant.core.jdo.VersantDetachable;
18: import com.versant.core.jdo.VersantDetachedStateManager;
19:
20: /**
21: * JDO Genie specific static utility methods.
22: */
23: public class VersantHelper {
24:
25: /**
26: * Delete an instance. This method will delete both detached and managed
27: * instances.
28: */
29: public static void deletePersistent(Object detachedPC) {
30: if (detachedPC instanceof VersantDetachable) {
31: VersantDetachable detachable = (VersantDetachable) detachedPC;
32: VersantDetachedStateManager sm = detachable
33: .versantGetDetachedStateManager();
34: if (sm != null) {
35: Object oid = detachable.versantGetOID();
36: if (oid != null) {
37: sm.versantAddDeleted(oid);
38: }
39: } else {
40: deletePC(detachedPC);
41: }
42: } else {
43: deletePC(detachedPC);
44: }
45: }
46:
47: private static void deletePC(Object detachedPC) {
48: if (detachedPC instanceof PersistenceCapable) {
49: PersistenceCapable pc = (PersistenceCapable) detachedPC;
50: PersistenceManager pm = pc.jdoGetPersistenceManager();
51: if (pm != null) {
52: pm.deletePersistent(pc);
53: } else {
54: throw BindingSupportImpl.getInstance()
55: .invalidOperation(
56: "Unmanaged objects can not be "
57: + "deleted. (class='"
58: + detachedPC.getClass()
59: + "' object='" + detachedPC
60: + "'");
61: }
62: } else {
63: throw BindingSupportImpl
64: .getInstance()
65: .invalidOperation(
66: "Can not delete an object that is not "
67: + "VersantDetachable or PersistenceCapable (class='"
68: + detachedPC.getClass()
69: + "' object='" + detachedPC + "'");
70: }
71: }
72:
73: }
|