public < E > E upsert ( E entity ) { try { entityManager . executeEntityListeners ( CallbackType . PRE_UPSERT , entity ) ; FullEntity < ? > nativeEntity = ( FullEntity < ? > ) Marshaller . marshal ( entityManager , entity , Intent . UPSERT ) ; Entity upsertedNativeEntity = nativeWriter . put ( nativeEntity ) ; @ SuppressWarnings ( "unchecked" ) E upsertedEntity = ( E ) Unmarshaller . unmarshal ( upsertedNativeEntity , entity . getClass ( ) ) ; entityManager . executeEntityListeners ( CallbackType . POST_UPSERT , upsertedEntity ) ; return upsertedEntity ; } catch ( DatastoreException exp ) { throw DatastoreUtils . wrap ( exp ) ; } }
Updates or inserts the given entity in the Cloud Datastore . If the entity does not have an ID it may be generated .