/** * Method to return the object identity for the passed persistable object. * Returns null if it is not persistable, or has no identity. * @param obj The object * @return The identity */ public Object getIdForObject(Object obj) { if (!isPersistable(obj)) { return null; } // TODO Change this to org.datanucleus.jpa.Persistable when we enhance to that return ((PersistenceCapable)obj).jdoGetObjectId(); }
/** * Accessor for the persistence manager for this object. * The returned object will be a JPA EntityManager or null if not managed. * @param obj The object * @return The persistence manager */ public Object getPersistenceManager(Object obj) { // TODO Replace this with a non-JDO class if (obj instanceof PersistenceCapable) { return ((PersistenceCapable)obj).jdoGetPersistenceManager(); } return null; }
/** * Accessor for an object id given the object. * @param pc The object * @return The Object id */ public Object getObjectId(Object pc) { assertIsOpen(); if (pc != null && pc instanceof PersistenceCapable) { PersistenceCapable p = (PersistenceCapable) pc; if (p.jdoIsPersistent() || p.jdoIsDetached()) { return p.jdoGetObjectId(); } } return null; }
/** * Create a new ObjectId instance and copy the key fields from the * persistence capable instance to the objectId instance * @param pc The persistence capable object * @param cmd The AbstractClassMetaData * @return The object id for the persistence capable object */ public static Object getNewObjectId(PersistenceCapable pc, AbstractClassMetaData cmd) { Object userOid = pc.jdoNewObjectIdInstance(); if (!cmd.usesSingleFieldIdentityClass()) { pc.jdoCopyKeyFieldsToObjectId(userOid); } return userOid; }
PersistenceCapable pcCopy = myPC.jdoNewInstance(this, myPC.jdoGetObjectId()); pcCopy.jdoCopyFields(myPC, noncontainerFieldNumbers); pcCopy.jdoReplaceFlags(); pcCopy.jdoReplaceStateManager(null);
assertPersistenceCapable(obj); PersistenceCapable pc = (PersistenceCapable) obj; if (pc.jdoIsDetached()) pc = (PersistenceCapable)getObjectById(pc.jdoGetObjectId()); if (!pc.jdoIsPersistent() && !pc.jdoIsTransactional()) else if (!pc.jdoIsPersistent() && pc.jdoIsTransactional()) if (sm == null) throw new JDOUserException(LOCALISER.msg("PM.DifferentOwner", pc.jdoGetObjectId()));
final StateManager ownerSM = sm; if (pcElement.jdoIsPersistent()) if (pm != pcElement.jdoGetPersistenceManager()) throw new JDOUserException(LOCALISER.msg("RDBMS.SCO.Set.WriteInvalidWithDifferentPM"),pcElement.jdoGetObjectId());
if (pc != null && !pc.jdoIsDetached() && !pc.jdoIsDeleted()) if( sms[i] != null && sms[i].getObject() != null && (sms[i].getObject().jdoIsPersistent() || sms[i].getObject().jdoIsTransactional()))
id = pc.jdoGetObjectId(); if (pc.jdoIsDetached() && ownerSM != null) if (((PersistenceManager)pc.jdoGetPersistenceManager()) != null && pm.getPMHandle() != ((PersistenceManager)pc.jdoGetPersistenceManager()).getPMHandle()) id = pcNew.jdoGetObjectId(); if (pc.jdoIsDetached() && ownerSM != null) pc.jdoCopyKeyFieldsFromObjectId(new AppIDObjectIdFieldConsumer(param, pm, ps, javaTypeMappings), id);
@Override public Object merge(Object entity) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("JPA Merge: - entity: " + entity); } if (entity instanceof PersistenceCapable) { PersistenceCapable pc = (PersistenceCapable) entity; if (pc.jdoIsDetached() && pc.jdoGetObjectId() == null) { throw new IllegalArgumentException("Detached entity with null id cannot be merged."); } // Read id from entity StateManager sm = om.findStateManager(entity); if (sm != null) { // This path is taken by all merge() calls. // We need to isolate merge() calls that were made to Transient object instead of Detached objects AbstractClassMetaData acmd = om.getMetaDataManager() .getMetaDataForClass(entity.getClass(), om.getClassLoaderResolver()); Object id = ForceQueryUtils.getIdFromObject(pc, acmd); if (id != null) { if (sm instanceof ForceJPAStateManagerImpl) { sm.initialiseForDetached(pc, id, sm.getVersion(pc)); entity = sm.getObject(); } } } } return super.merge(entity); }
Object id = pc.jdoGetObjectId(); if (pc.jdoIsDetached() && ownerSM != null) if (((PersistenceManager)pc.jdoGetPersistenceManager()) != null && pm.getPMHandle() != ((PersistenceManager)pc.jdoGetPersistenceManager()).getPMHandle()) id = pcNew.jdoGetObjectId(); if (pc.jdoIsDetached() && ownerSM != null)
PersistenceManager pm = (PersistenceManager) pc.jdoGetPersistenceManager(); if (pm != null && this.getPMHandle() != pm.getPMHandle()) throw new JDOUserException(LOCALISER.msg("PM.DifferentOwner", pc.jdoGetObjectId()));
if (sm.getObject().jdoIsNew()) else if (sm.getObject().jdoIsPersistent() && !sm.getObject().jdoIsDeleted())
/** * Method to make nontransactional an object (internally). * @param obj The object */ private void internalMakeNontransactional(Object obj) { if (obj == null) { return; } try { clr.setPrimary(obj.getClass().getClassLoader()); assertPersistenceCapable(obj); PersistenceCapable pc = (PersistenceCapable) obj; if (!pc.jdoIsPersistent() && pc.jdoIsTransactional() && pc.jdoIsDirty()) { throw new JDOUserException(LOCALISER.msg("PM.MakeNonTransactionalOnTransientDirtyInstances")); } StateManager sm = findStateManager(pc); sm.makeNontransactional(); } finally { clr.unsetPrimary(); } }
if (!pc.jdoIsDetached()) (PersistenceCapable)((PersistenceManager)pc.jdoGetPersistenceManager()).detachCopyInternal(pc, state); arrDetached[j] = pcDetached; ((PersistenceManager)pc.jdoGetPersistenceManager()).detachInternal(pc, state); arrDetached[j] = pc; if (pc.jdoIsDetached()) return ((PersistenceManager)pc.jdoGetPersistenceManager()).detachCopyInternal(pc, state); ((PersistenceManager)pc.jdoGetPersistenceManager()).detachInternal(value, state); return value;
/** * Convenience accessor for whether the object is detached. * @param obj The object * @return Whether it is persistent */ public static boolean isDetached(Object obj) { // TODO Change this to org.datanucleus.jpa.Persistable when we swap over if (obj instanceof PersistenceCapable) { return ((PersistenceCapable)obj).jdoIsDetached(); } return false; }
if (myPC.jdoIsDetached()) PersistenceCapable detachedPC = myPC.jdoNewInstance(this); detachingPC = detachedPC; detachedPC.jdoReplaceStateManager(smDetachedPC); detachedPC.jdoReplaceFlags(); ((Detachable)detachedPC).jdoReplaceDetachedState(); detachedPC.jdoReplaceStateManager(null); if (detachable && !detachedPC.jdoIsDetached())
if (pc.jdoIsPersistent()) ((PersistenceManager)pc.jdoGetPersistenceManager()).internalMakeTransient(pc, state); if (pc.jdoIsPersistent()) ((PersistenceManager)pc.jdoGetPersistenceManager()).internalMakeTransient(pc, state);
/** * Convenience accessor for whether the object is persistent. * @param obj The object * @return Whether it is persistent */ public static boolean isPersistent(Object obj) { // TODO Change this to org.datanucleus.jpa.Persistable when we swap over if (obj instanceof PersistenceCapable) { return ((PersistenceCapable)obj).jdoIsPersistent(); } return false; }
/** * Method to make nontransactional an object. * @param pc The object */ public synchronized void makeNontransactional(Object pc) { assertIsOpen(); if (pc == null) { // JDO2 [12.6.0] Null means do nothing return; } // for non transactional read, tx might be not active // TODO add verification if is non transactional read = true if (tx.isActive()) { assertActiveTransaction(); } // if !transactional and !persistent if (!((PersistenceCapable) pc).jdoIsTransactional() && !((PersistenceCapable) pc).jdoIsPersistent()) { throw new JDOUserException(LOCALISER.msg("PM.MakeNontransactionalOnNontransactionalTransientInstances")); } // if !transactional and persistent, do nothing if (!((PersistenceCapable) pc).jdoIsTransactional() && ((PersistenceCapable) pc).jdoIsPersistent()) { return; } internalMakeNontransactional(pc); }