KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > VersantHelper


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo;
13
14 import javax.jdo.PersistenceManager;
15 import javax.jdo.spi.PersistenceCapable;
16
17 import com.versant.core.common.BindingSupportImpl;
18 import com.versant.core.jdo.VersantDetachable;
19 import com.versant.core.jdo.VersantDetachedStateManager;
20
21 /**
22  * JDO Genie specific static utility methods.
23  */

24 public class VersantHelper {
25
26     /**
27      * Delete an instance. This method will delete both detached and managed
28      * instances.
29      */

30     public static void deletePersistent(Object JavaDoc detachedPC) {
31         if (detachedPC instanceof VersantDetachable) {
32             VersantDetachable detachable = (VersantDetachable)detachedPC;
33             VersantDetachedStateManager sm = detachable.versantGetDetachedStateManager();
34             if (sm != null) {
35                 Object JavaDoc 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 JavaDoc 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().invalidOperation("Unmanaged objects can not be " +
55                         "deleted. (class='" + detachedPC.getClass() +
56                         "' object='" + detachedPC + "'");
57             }
58         } else {
59             throw BindingSupportImpl.getInstance().invalidOperation("Can not delete an object that is not " +
60                     "VersantDetachable or PersistenceCapable (class='" +
61                     detachedPC.getClass() + "' object='" + detachedPC + "'");
62         }
63     }
64
65 }
66
Popular Tags