Change your query to something like this:

Query query = pm.newQuery("select ek from " + UploadedContent.class
.getName());

Where "ek" is the entity key name you use in you JDO class. For example,
mine is defined like the following:

    @PrimaryKey

    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)

    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")

    private String ek;

Then, just query for the keys and do a batch delete on the keys. Right now
you're pulling in all the entity data and then deleting the entities which
is unnecessary and will slow you do a lot.

Stephen
CortexConnect (cortexconnect.appspot.com)

On Tue, Aug 2, 2011 at 12:17 AM, Carter <[email protected]> wrote:

> 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.
>
>

-- 
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.

Reply via email to