/** * Refresh the state of the instance from the database, overwriting changes made to the entity, if any. * @param entity The Entity * @throws IllegalArgumentException if not an entity or entity is not managed * @throws TransactionRequiredException if invoked on a container-managed entity manager * of type PersistenceContextType.TRANSACTION and there is no transaction. * @throws EntityNotFoundException if the entity no longer exists in the database */ public void refresh(Object entity) { assertIsOpen(); assertTransactionNotRequired(); assertEntity(entity); if (om.getApiAdapter().getPersistenceManager(entity) != pm) { throw new IllegalArgumentException(LOCALISER.msg("EM.EntityIsNotManaged", StringUtils.toJVMIDString(entity))); } if (!om.exists(entity)) { throw new EntityNotFoundException(LOCALISER.msg("EM.EntityNotInDatastore", StringUtils.toJVMIDString(entity))); } try { om.refreshObject(entity); } catch (NucleusException jpe) { throw NucleusJPAHelper.getJPAExceptionForNucleusException(jpe); } }
assertTransactionNotRequired(); assertEntity(entity); if (om.exists(entity))
assertTransactionNotRequired(); assertEntity(entity); if (om.exists(entity))
public void refresh(Object entity, LockModeType lock, Map<String, Object> properties) { // TODO Use lock, properties assertLockModeValid(lock); assertIsOpen(); assertTransactionNotRequired(); assertEntity(entity); if (om.getApiAdapter().getPersistenceManager(entity) != pm) { throw new IllegalArgumentException(LOCALISER.msg("EM.EntityIsNotManaged", StringUtils.toJVMIDString(entity))); } if (!om.exists(entity)) { throwException(new EntityNotFoundException(LOCALISER.msg("EM.EntityNotInDatastore", StringUtils.toJVMIDString(entity)))); } try { if (lock != null && lock != LockModeType.NONE) { // Register the object for locking om.getLockManager().lock(om.getApiAdapter().getIdForObject(entity), getLockTypeForJPALockModeType(lock)); } om.refreshObject(entity); } catch (NucleusException ne) { throwException(NucleusJPAHelper.getJPAExceptionForNucleusException(ne)); } }