0
votes

I have some simple code that handles the upload of a profile image (it's the callback after BlobstoreService has done its voodoo).

protected void doPost(HttpServletRequest req, HttpServletResponse res)
                throws ServletException, IOException {
        BlobstoreService blobSvc = BlobstoreServiceFactory.getBlobstoreService();
        Map<String, List<BlobKey>> blobs = blobSvc.getUploads(req);
        List<BlobKey> blobKeys = blobs.get(UserSvc.fieldProfileImg);
        String principalKey = req.getParameter(UserSvc.fieldPrincipalKey);

        boolean failure = true;
        if (null != blobKeys && blobKeys.size() > 0) {
                Optional<Principal> princi = GaeDataUtil.getByWebKey(principalKey);
                if (princi.isPresent()) {
                        log.info("Before adding BlobKey: " + princi.get());
                        princi.get().setProfileImgKey(blobKeys.get(0));
                        princi.get().setMiddleName("Saved"); // just to test if any other value will update
                        ofy().save().entity(princi.get()).now();
                        log.info("After adding BlobKey and saving: " + princi.get());
                        failure = false;
                        res.getWriter().print("SUCCESS");
                } else {
                        log.warning("Failed to find Principal with web key: " + principalKey);
                }
        }
        if (failure) {
                res.getWriter().print("FAIL");
        }

}

Everything works, except the re-saving of the retrieved entity.

Background Infomation

My own server-side code is submitting the profile image data to the BlobstoreService (let's not get into why that is so). The submission/upload works, am able to see it in the admin/Datastore of the devserver, I get the BlobKey I want, can even retrieve the Principal from the webKey, but can't seem to save the updated entity. No exceptions either.

Initially when I tried this I wasn't retrieving the BlobKey and I noticed that the Datastore would show two special entities: __BlobInfo__ and another one whose name I can't recall but it began and ended with __ (double underscore). After I flushed memcache, I could see only __BlobInfo__ entities, the other one was nowhere to be seen. I deleted the target\<appname>-1.0-SNAPSHOT\WEB-INF\appengine-generated\local_db.bin trying to reset the Datastore, but I still couldn't see any sign of the other special entity in the Datastore.

Is there a way to reset the Datastore and Blobstore on development server?

Environment:

  • Development server
  • Java 7
  • Windows 7
  • Objectify 5.1.7
1
Please keep code inlined here, not on pastebin. - zapl
Sometimes other users object if too much code is inlined... what's the yardstick for when to inline and when to use Pastebin and similar services? - markvgti
Never pastebin. If your code is too much you don't have a minimal reproducible example and should strip the code. - zapl
So ofy().save().entity(princi.get()).now() does not fail (The documentation of now() is "If the computation produced an exception, it will be thrown here.") but you don't see the update in the datastore viewer? You can reset your local env: at startup in the logs it says something about creating a sql file, delete that. - zapl
@zapl Exactly! No exceptions, but no updates either. I thought maybe inadvertently (magically) I was doing an async save, but even minutes later the update isn't there. - markvgti

1 Answers

0
votes

If you are looking for a work around for resetting the blob store and data store entries in just the dev server then you can try and change the application name in the appengine-web.xml

<application>appname</application>

If you provide a different(dummy) name here it should reset things in dev server if you re-run the dev server.