code: @SuppressWarnings("unchecked")
    public <E> List<E> upsert(List<E> entities) {
      if (entities == null || entities.isEmpty()) {
        return new ArrayList<>();
      }
      try {
        entityManager.executeEntityListeners(CallbackType.PRE_UPSERT, entities);
        FullEntity<?>[] nativeEntities = toNativeFullEntities(entities, entityManager, Intent.UPSERT);
        Class<?> entityClass = entities.get(0).getClass();
        List<Entity> upsertedNativeEntities = nativeWriter.put(nativeEntities);
        List<E> upsertedEntities = (List<E>) toEntities(entityClass, upsertedNativeEntities);
        entityManager.executeEntityListeners(CallbackType.POST_UPSERT, upsertedEntities);
        return upsertedEntities;
      } catch (DatastoreException exp) {
        throw DatastoreUtils.wrap(exp);
      }
    }
docs: Updates or inserts the given list of entities in the Cloud Datastore. If the entities do not
  have a valid ID, IDs may be generated.
  
  @param entities
  the entities to update/or insert.
  @return the updated or inserted entities
  @throws EntityManagerException
  if any error occurs while saving.