收录日期:2019/04/20 16:47:18 时间:2010-07-21 21:28:41 标签:java,google-app-engine,gae-datastore

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();

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

what do you mean by "doesn't work," specifically? is there an error message? what does it say? also, what's the value of numberOfRowsToBedeletedAtOnce?

if it's deadlining, or you're getting an error that says the delete is too big, try reducing numberOfRowsToBedeletedAtOnce.