protected static void deleteTempDataInTx(DatastoreService ds, Entity entity, Class<? extends TempData> type) {
Transaction txn = ds.beginTransaction(TransactionOptions.Builder.withXG(true));
try {
TempData data = type.newInstance();
data.fromProperties(entity.getProperties());
data.preDelete(ds);
ds.delete(txn, entity.getKey());
data.postDelete(ds);
txn.commit();
} catch (Exception e) {
throw new IllegalStateException(e);