2010-12-09 70 views

回答

2

是的,儘管不像您期待的那麼平常。

限制

  1. 請問time out if it takes more then 30 seconds, 除非你運行它作爲任務,在這種情況下, 它會time out if it takes more then 10 minutes
  2. 有沒有更智能的方法來獲得 您需要更新的實體 您can't query on a property that doesn't exist

解決辦法

  1. 你要考慮的 appengine-mapreduce project到 得到實現,可 完成更多的則10分鐘 掛鐘時間。
  2. 未知。

代碼

void updateNullBarField() { 
    final Text DEFAULT_BAR = new Text("bar"); 

    PersistenceManagerFactory pmfInstance = JDOHelper 
    .getPersistenceManagerFactory("transactions-optional"); 
    PersistenceManager pm = pmfInstance.getPersistenceManager(); 
    Query query = pm.newQuery(Foo.class); 
    @SuppressWarnings("unchecked") 
    Collection<Foo> foos = pm.detachCopyAll((List<Foo>) query.execute()); 

    for (Foo foo : foos) { 
    if (foo.bar == null) { 
     foo.bar = DEFAULT_BAR; 
     pm.detachCopy(pm.makePersistent(foo)); 
    } 
    } 
} 
相關問題