Is this the most efficient code for bulk delete?
Is there a "SELECT __key__" technique that's faster?
This currently deletes 100 at a time, but it's slow.
public long deleteBefore(Date d, long maxRecords)
throws DaoException {
PersistenceManager pm = pmf.getPersistenceManager();
Query query = pm.newQuery(UploadedContent.class);
query.setFilter("dateCreated < dateCreatedParam");
query.declareParameters("Date dateCreatedParam");
query.declareImports("import java.util.Date;");
if (maxRecords >= 0) {
query.setRange(0, maxRecords);
}
List<UploadedContent> entities = new
ArrayList<UploadedContent>();
try {
entities = (List<UploadedContent>) query.execute(d);
pm.deletePersistentAll(entities);
} catch (Exception e) {
log.log(Level.SEVERE, e.getMessage(), e);
throw new DaoException(e);
} finally {
query.closeAll();
pm.close();
}
return entities.size();
}
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.