code: static void rollbackIfActive(Transaction transaction) {
      try {
        if (transaction != null && transaction.isActive()) {
          transaction.rollback();
        }
      } catch (DatastoreException exp) {
        throw new EntityManagerException(exp);
      }
    }
docs: Rolls back the given transaction, if it is still active.
  
  @param transaction
  the transaction to roll back.