Пример #1
0
  // Factory methods:
  public static MemoStorable load(Entity ent) {
    //		long start = System.currentTimeMillis();
    byte[] result;
    Key key = ent.getKey();
    int size = 0;
    long spread = 0;
    //		int count=0;
    try {
      Blob blob = (Blob) ent.getProperty("payload");
      size = (int) ((Long) ent.getProperty("size") % Integer.MAX_VALUE);
      spread = ((Long) ent.getProperty("spread"));

      byte[] data = blob.getBytes();
      result = Arrays.copyOf(data, data.length);
      //			count++;
      while (ent.hasProperty("next")) {
        // Expensive, should not be used too much!
        Key next = (Key) ent.getProperty("next");
        ent = datastore.get(next);
        blob = (Blob) ent.getProperty("payload");
        data = blob.getBytes();
        result = concat(data, result); // Add to front of result, due to
        //				count++;						// the storing order
      }

    } catch (EntityNotFoundException e) {
      e.printStackTrace();
      return null;
    }
    MemoStorable res = _unserialize(result, size);
    res.spread = spread;
    res.storedSize = result.length;
    if (res != null) res.myKey = key;
    return res;
  }
Пример #2
0
 /**
  * Executes a background task.
  *
  * <p>The task payload is either type Deferrable or Key; in the latter case, retrieve (then
  * delete) the Deferrable instance from the datastore.
  */
 @Override
 public void doPost(HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
   try {
     Object payload = deserialize(req);
     if (payload instanceof Key) {
       // get Deferrable from datastore
       Blob taskBlob = (Blob) getDatastoreService().get((Key) payload).getProperty(TASK_PROPERTY);
       deleteEntity((Key) payload);
       if (taskBlob != null) {
         payload = deserialize(taskBlob.getBytes());
       }
     }
     if (payload instanceof Deferrable) {
       ((Deferrable) payload).doTask();
     } else if (payload != null) {
       log.severe("invalid payload type: " + payload.getClass().getName());
       // don't retry task
     }
   } catch (EntityNotFoundException e) {
     log.severe(e.toString()); // don't retry task
   } catch (PermanentTaskFailure e) {
     log.severe(e.toString()); // don't retry task
   }
 }
Пример #3
0
 /**
  * Handles the HTTP <code>POST</code> method.
  *
  * @param request servlet request
  * @param response servlet response
  * @throws ServletException if a servlet-specific error occurs
  * @throws IOException if an I/O error occurs
  */
 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   try {
     String removeKey = request.getParameter(RemoveParameter);
     if (removeKey != null) {
       remove(removeKey, response);
     } else {
       try {
         BlogAuthor blogAuthor = setNamespace(request, response);
         if (blogAuthor == null) {
           return;
         }
         handleMail(request, response, blogAuthor);
       } catch (MessagingException ex) {
         log(ex.getMessage(), ex);
         response.sendError(HttpServletResponse.SC_CONFLICT);
       } catch (EntityNotFoundException ex) {
         log(ex.getMessage(), ex);
         response.sendError(HttpServletResponse.SC_FORBIDDEN);
       }
     }
   } catch (HttpException ex) {
     log(ex.getMessage(), ex);
     ex.sendError(response);
   }
 }
Пример #4
0
 @Override
 public Training getByKey(Key key) {
   try {
     return (new Training(dataStore.get(key)));
   } catch (EntityNotFoundException e) {
     e.printStackTrace();
     return null;
   }
 }
Пример #5
0
  @Override
  public MyUser getMyUser(String email) {
    //	if (!userService.isUserAdmin()) return null;
    MyUser user = null;
    try {
      user = userDao.get(email);
    } catch (EntityNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return user;
  }
Пример #6
0
  @Test
  public void test() {
    Entity parent = new Entity("Parent");
    // set parent properties...
    List<EmbeddedEntity> children = new ArrayList<EmbeddedEntity>();
    for (int i = 0; i < 5; i++) {
      EmbeddedEntity child = new EmbeddedEntity();
      // set child properties...
      children.add(child);
    }
    parent.setUnindexedProperty("children", children);
    parent.setUnindexedProperty("children2", list("tag1", "tag2", "tag3"));

    DatastoreServiceFactory.getDatastoreService().put(parent);

    try {
      Entity e = DatastoreServiceFactory.getDatastoreService().get(parent.getKey());
      e.getKey();
      Object children2 = e.getProperty("children2");
      assertTrue(children2 instanceof List);
    } catch (EntityNotFoundException e1) {
      e1.printStackTrace();
    }
  }