2012-03-11 118 views
4

我使用遠程API和低級別數據存儲區api將一些名稱空間數據從x1複製到x2。應用程序x1無法訪問應用程序x2數據

我訪問X2應用,得到以下錯誤的一些數據

 
java.lang.IllegalArgumentException: app x1 cannot access app x2's data 
    at com.google.appengine.api.datastore.DatastoreApiHelper.translateError(DatastoreApiHelper.java:36) 
    at com.google.appengine.api.datastore.DatastoreApiHelper$1.convertException(DatastoreApiHelper.java:76) 
    at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:106) 
    at com.google.appengine.api.datastore.FutureHelper$CumulativeAggregateFuture.get(FutureHelper.java:145) 

回答

0

您需要修復了鍵,以便他們在他們正確的應用程序ID。

這裏有點Python中的使用:

key = db.Key(k) 
    if key.app() == appname: 
    return db.get(key) 
    logging.info("Fixing up key from old app %s (%s=%s)" % (key.app() , key_attr , k)) 
    fixed_key = db.Key.from_path(*key.to_path()) 
1

在本文章中說:Migration to HRD - How to convert string-encoded keys to new application所有的實體按鍵包含對APP-ID的參考。如果使用以字符串編碼的鍵,則在將數據複製到新應用程序時,該引用將不會更新。但你可以自己做。

只需在新環境中運行一個查詢,即可更新每個單鍵以指向新的應用程序標識。 在這個例子中我假設每個實體實現該接口:

Interface Entity{ 
    public Key getKey(); 
    public void setKey(Key key); 
} 

現在我可以使用的方法是這樣的:

//... 

List<Entity> entities = //... your query 

for (Entity entity : entities){ 
    entity.setKey(generateNewKey(entity.getKey()); 
} 

//... 

//Method written by Nikolay Ivanov in the other post, that recursive generate a new key respecting to parents 

private Key generateNewKey(Key key) { 
    Key parentKey = key.getParent(); 
    if(parentKey == null){ 
     return KeyFactory.createKey(key.getKind(), key.getId()); 
    }else{   
     Key newParentKey = generateKey(parentKey);   
     return KeyFactory.createKey(newParentKey, key.getKind(), key.getId()); 
    } 
} 
相關問題