2012-05-18 29 views
0

我正在执行方法Datastore.delete(键)组成我的GWT Web应用程序,AsyncCallback调用了onSuccess()方法。我立即刷新http://localhost:8888/_ah/admin,实体i意图删除仍然存在。同样,我立即刷新我的GWT Web应用程序,我想删除的项目仍然显示在网页上。请注意onSuccess()已被调用。如何知道Google AppEngine数据存储区的操作已完成

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

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; 
} 

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

+0

每次重新加载页面时,都要查询数据库以获取实际数据。 – kapand

回答

0

不好按照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('/')   
0

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

对HRD的查询是eventually consistent,这意味着如果您添加/删除/更改实体,则立即查询它,您可能看不到更改。原因在于,当您编写(或删除)实体时,GAE会异步更新索引和实体in several phases。由于这需要一些时间,可能会发生,您没有立即看到更改。

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

相关问题