コード例 #1
0
ファイル: MemoStorable.java プロジェクト: almende/memo-nodes
  // 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
ファイル: Deferred.java プロジェクト: armhold/gwtquickstarter
 /**
  * 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
ファイル: AdminServiceImpl.java プロジェクト: Husarz/cloudcms
  @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
ファイル: MarshallerTest.java プロジェクト: hunchee/twist
  @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();
    }
  }