我的具體問題(其他一切只是上下文,如果你知道我的問題的答案可以忽略):如何確定一個對象是否是瞬態的或不使用JDO(或者我怎麼寫一個簡短的方法來做到這一點)?確定對象是否屬於持久性管理器
語境對於那些誰是好奇或不understance爲什麼我會想這樣的:
我的工作瓦特/ JDO在GAE/J和我目前正在實施使用App Engine內存緩存的API。我遇到了一個問題,我從我的數據存儲區中緩存了一個實體的實例。在請求結束時,我的持久性管理器被關閉,並且 - 據我所知,緩存的對象變成了暫時的(我對此可能是錯誤的)並掛在緩存中。
在路上,緩存的對象用於構建我的視圖等,但是當我去對對象進行更新並嘗試並堅持時;該對象不會持續(正確如此)。我正在嘗試在執行更新操作之前嘗試重新獲取緩存的對象。但是這引入了另一個問題,因爲現在當我更新一個沒有被緩存的對象時,它被我的持久性管理器管理,當我獲取新對象時,我執行的任何更新操作都會被覆蓋。基本上,如果有,我應該嘗試這樣做,或者如果我在考慮這個錯了,請隨時指出來一些其他的方式,我做這個....
// valueWithChangesToUpdate is an object that could be from
// memcache or could be fresh from pm, don't know for sure
// going into the method
public <T extends SomeKindOfEntity> void update(CustomQueryClass q, T valueWithChangesToUpdate) {
// If valueWithChangesToUpdate is not from memcache/not transient then
// any changes made are overridden when the following statement executes
T freshObject = q.runQuery();
// What I would like to do to avoid problem I'm having...
// T freshObject = null;
// if(valueWithChangesToUpdate.isTransient()) {
// freshObject = q.runQuery();
// }
// End goal...
freshObject.applyUpdates(valueWithChangesToUpdate);
PMF.getCurrentPM().makepersistent(freshObject);
}
。