0
votes

If I want all deletes execute all-or-nothing.

  1. If nothing changed. Will the group of deletes be atomic?
  2. If I remove outer transaction, will something change?
  3. If I remove only inner transaction, will group be atomic?
  4. Ig I replace for-cycle with a batch delete and leave only outer transaction?

    // inside event plan dao
    public void delete(EventPlan eventPlan) {
      final Objectify ofy = Objectify.beginTransaction();
      try {
        final ActivityDAO activityDao = new ActivityDAO();
        for (final Activity activity : eventPlan.getActivities()) {
          activityDao.delete(activity);
        }
        ofy.getTxn().commit();
      } finally {
        if (ofy.getTxn().isActive()) {
          ofy.getTxn().rollback();
        |
      }
    }

   

    // inside activity dao
    public void delete(Activity activity) {
          final Objectify ofy = Objectify.beginTransaction();
       try {
          // do some logic in here, delete activity and commit txn
       } finally {
          // check and rollback as normal
       }
    }

1

1 Answers

0
votes

If you use Objectify 3.1 then all transactions are XG-transactions, which can operate on max 5 different entity groups, i.e. if your Activities do not have common parent (= putting them in the same entity group) then you can only delete max five in one transaction.

  1. No, you are using parallel transactions ( one outer, multiple inner).
  2. No, outer transaction has no operation executed, so it does nothing. There are multiple inner transaction (loop) each doing it's own delete.
  3. Yes, you must perform all operations within one transaction for operations to be atomic. If you remove inner transactions you are on the right path. However, Entity Group transaction limit still applies: all entities touched within a transaction must belong to the same Entity Group, or (since XG is enabled by default) to max five different Entity Groups (see above). Note if you don't explicitly put entity in Entity Group (by setting parent) then every entity gets it's own Entity Group.
  4. Yes, batch delete is better then delete in loop (due to efficiency) but all transaction rules in point 3. still apply.