I can think of three ways:

1) Iterate over the query results and delete each without the transaction.
2) Make a separate transaction for every group of 5 keys.
3) Use the MapReduce library and a MapOnlyMapper to walk all the keys.

On Monday, February 15, 2016 at 10:23:50 AM UTC-6, Louise Elmose Hedegaard 
wrote:
>
> I have a datastore with a kind "shop", a kind "order" and a kind 
> "transaction".
> One shop has many orders, and one order has many transactions.
> The parent of a transaction is an order, the parent of an order is a shop.
>
> I want to delete all entries in the transactions table:
>
>     public void cleanUp() {
>         Query query = new 
> Query(TransactionDBFields.TRANSACTION_TABLE_NAME);
>         query.setKeysOnly();
>         query.setFilter(
>                 new Query.FilterPredicate(
>                         TransactionDBFields.CREATED_AT,
>                         Query.FilterOperator.LESS_THAN_OR_EQUAL,
>                         new Date())
>         );
>
>         PreparedQuery preparedQuery = datastore.prepare(query);
>         Iterable<Entity> entities = 
> preparedQuery.asIterable(FetchOptions.Builder.withLimit(5));
>
>         TransactionOptions options = 
> TransactionOptions.Builder.withXG(true);
>         Transaction txn = datastore.beginTransaction(options);
>         for (Entity en : entities) {
>             datastore.delete(txn, en.getKey());
>         }
>         txn.commit();
>     }
>
> If I change the limit to anything larger than 5 I get the error:
>
> java.lang.IllegalArgumentException: operating on too many entity groups in 
> a single transaction.
>
> - apparently as GAE does not allow operating on more than 5 entity groups 
> in a single transaction. 
>
> Is there a way to delete more than 5 entities at a time? executing the 
> above code continuously to delete all transaction entities does not seem 
> reasonable, nor when considering performance.
>
> -Louise
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/cb02e609-5245-413d-8bc1-220874c3a1be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to