views:

28

answers:

1

Here is my code fragment. This code works very fine with local development data store. But doesn't work on real app engine. The query filter used here only returns 181 rows.

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.Query.FilterOperator;
Query query = new Query("Share");
query.addFilter("timeOfData", FilterOperator.GREATER_THAN, sdf.parse(date));
query.setKeysOnly();
ArrayList<Key> allKeys = new ArrayList<Key>();
if(numberOfRowsToBedeletedAtOnceString != null)
 numberOfRowsToBedeletedAtOnce = Integer.parseInt(numberOfRowsToBedeletedAtOnceString);
    for (final Entity e : dcc.prepare(query).asIterable(FetchOptions.Builder.withLimit(numberOfRowsToBedeletedAtOnce)))
    {
      allKeys.add(e.getKey());
    }

    allKeys.trimToSize();
    dcc.delete(allKeys);
    out.print("Deleted By Date count : " + allKeys.size());
    out.flush();
    out.close();
A: 

As google documents suggests you can use delete Entities By Query

Query query = pm.newQuery(Person.class); 
query.setFilter("height > maxHeightParam"); 
query.declareParameters("int maxHeightParam"); 
query.deletePersistentAll(maxHeight);

Check here

Manjoor
It looks like the OP is using the low level datastore API and your answer is using the JDO API. I think the OP is looking for an answer using the low level API.
Peter Recore
without the filter both the low level and JDO apis work fine for deleting in chinks. But when I am adding this filter, its not working anymore.
iftee