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.PreparedQuery; import com.google.appengine.api.datastore.Query; .... @SuppressWarnings("serial") public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Query query = new Query("YourKind"); PreparedQuery pq = datastore.prepare(query); // Iterate the date for (Entity result : pq.asIterable()) { Transaction txn = datastore.beginTransaction(); try { datastore.delete(result.getKey()); txn.commit(); } finally { if (txn.isActive()) { txn.rollback(); } } } }// doGet }// Class
Sep 1, 2012
GAE - Truncating Datastore Data
At this time there were no quick truncate for the Entities.
Solution: Create data script in your servlet to delete.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment