【问题标题】:How to know a operations of Google AppEngine datastore are complete如何知道 Google AppEngine 数据存储区的操作是否完整
【发布时间】:2012-05-18 10:47:37
【问题描述】:

我正在从我的 GWT Web 应用程序中执行方法 Datastore.delete(key),AsyncCallback 调用了 onSuccess() 方法。我立即刷新 http://localhost:8888/_ah/admin,我打算删除的实体仍然存在。类似于,我立即刷新我的 GWT Web 应用程序,我打算删除的项目仍然显示在网页上。注意 onSuccess() 已被调用。

那么,我怎么知道实体何时已被删除?

 public void deleteALocation(int removedIndex,String symbol ){
    if(Window.confirm("Sure ?")){
        System.out.println("XXXXXX  " +symbol);
        loCalservice.deletoALocation(symbol, callback_delete_location);
    }

}
public AsyncCallback<String> callback_delete_location = new AsyncCallback<String>() {      

    public void onFailure(Throwable caught) {
        Window.alert(caught.getMessage());
    }

    public void onSuccess(String result) {
        // TODO Auto-generated method stub
        int removedIndex = ArryList_Location.indexOf(result);
        ArryList_Location.remove(removedIndex);
        LocationTable.removeRow(removedIndex + 1);
        //Window.alert(result+"!!!");
    }
};

服务器:

public String deletoALocation(String name) {
    // TODO Auto-generated method stub
    Transaction tx = Datastore.beginTransaction();
    Key key = Datastore.createKey(Location.class,name);
    Datastore.delete(tx,key); 
    tx.commit();
    return name;
}

对不起,我的英语不好:-)

【问题讨论】:

  • 每次重新加载页面时查询数据库以获取实际数据。

标签: google-app-engine gwt


【解决方案1】:

根据docs

返回与存储的模型实例对应的 Key 对象(如果给出了一个模型实例)或 Key 对象列表(如果给出了实例列表)。

如果您需要一个有效的删除功能示例,这可能是help。 108行

class DeletePost(BaseHandler):

def get(self, post_id):
    iden = int(post_id)
    post = db.get(db.Key.from_path('Posts', iden))
    db.delete(post)
    return webapp2.redirect('/')        

【讨论】:

    【解决方案2】:

    如何检查实体的存在?通过查询?

    HRD 上的查询是eventually consistent,这意味着如果您添加/删除/更改一个实体,然后立即查询它,您可能看不到更改。这样做的原因是当你写入(或删除)一个实体时,GAE 会异步更新索引和实体in several phases。由于这需要一些时间,因此您可能不会立即看到更改。

    链接文章讨论了减轻此限制的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2011-07-02
      • 2011-10-28
      • 1970-01-01
      相关资源
      最近更新 更多