开发者

Bulk entity delete in Google App Engine [duplicate]

This question already has answers here: Delete all data for a kind in Google App Engine (19 answers) Closed 3 years ago.

I'm trying to delete some unwanted data from my datastore with Java and found some code using the DatastoreService that I modified to delete as many entries as possible in 10 seconds:

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Query query = new Query("PostalCodes");
long starttime = (new Date()).getTime();
for (Entity entity : datastore.prepare(query).asIterable()) {
        datastore.delete(entity.getKey());
        if ((new Date().getTime()) > (starttime + 10000))
                break;
}

It seems to work when I run this. I check the console's data viewer and the Kind I'm trying to delete ("PostalCodes") is gone, b开发者_JAVA技巧ut the day after I do this, the whole thing has been restored. Am I missing a call to flush or commit or something?!?

Is there a better way to do this?


It's possible to delete all entitys of certain type within 'DataStore Admin' section :

Select entities and then select ' Delete Entities' :

Bulk entity delete in Google App Engine [duplicate]


public final class PMF {
    private static final PersistenceManagerFactory pmfInstance =
        JDOHelper.getPersistenceManagerFactory("transactions-optional");

    private PMF() {
        PersistenceManagerFactory pmfInstance = PMF.get();
        PersistenceManager pm = pmfInstance.getPersistenceManager();
        pm.deletePersistentAll();/* by using this all the entities which are created earlier will be deleted*/
    }

    public static PersistenceManagerFactory get() {
        return pmfInstance;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜