1 2 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 24 public class VersantHelper { 25 26 30 public static void deletePersistent(Object detachedPC) { 31 if (detachedPC instanceof VersantDetachable) { 32 VersantDetachable detachable = (VersantDetachable)detachedPC; 33 VersantDetachedStateManager sm = detachable.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().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 |