caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)
caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)
- Subject: caching global IDs does not work as expected (followup: ordered and filtered fault efficiency)
- From: OC <email@hidden>
- Date: Sat, 14 Feb 2015 10:59:51 +0100
P.S.
On 14. 2. 2015, at 8:34, OC <email@hidden> wrote:
> I tried to cache the object's permanentGlobalID when found or added new valid one ... it still does not work well
Actually it seems I must be misunderstanding somehow the behaviour of global IDs, worth to ask for an advice what I am doing wrong.
I cache permanent GID of the found object in my relationship; the cache key is the owner's GID -- the code looks essentially like this:
===
private static Map _lastValidPOCacheGID=[:]
public DBPriceOffer lastValidPriceOffer { // this might happen in any EC, default or temporary
if (_lastValidPOCacheGID[this.permanentGlobalID()]) {
def gid=_lastValidPOCacheGID[this.permanentGlobalID()]
def lvpo=this.editingContext().objectForGlobalID(gid) //1 finds it if exists in EC, or...
if (!lvpo) {
lvpo=ERXEOGlobalIDUtilities.fetchObjectWithGlobalID(this.editingContext(),gid) //2 ... fetches if does not
println "???? fetched valid PO of ${this.permanentGlobalID()}: ${gid} -> ${lvpo} IN ${this.editingContext.hashCode()}"
} else println "???? found valid PO of ${this.permanentGlobalID()}: ${gid} -> ${lvpo} IN ${this.editingContext.hashCode()}"
if (lvpo) return lvpo
}
NSArray a=orderedPriceOffers
for (int n=a.count-1;n>=0;n--) {
DBPriceOffer po=(DBPriceOffer)a.objectAtIndex(n)
if (po.validOffer) {
println "???? setting found last valid PO of ${this.permanentGlobalID()}: $po -> ${po.permanentGlobalID()} IN ${po.editingContext.hashCode()}"
_lastValidPOCacheGID[this.permanentGlobalID()]=po.permanentGlobalID()
return po
}
}
return nil
}
public int addPriceOffer(BigDecimal offerValue) { // this happens in a temp EC
DBPriceOffer npo=new DBPriceOffer()
this.editingContext.insertObject(npo)
this.addObjectToBothSidesOfRelationshipWithKey(npo,'priceOffers')
npo.offerValue=offerValue
if ((npo.validOffer=_validateOffer(npo))) {
println "???? setting new valid PO of ${this.permanentGlobalID()}: $npo -> ${npo.permanentGlobalID()} IN.this ${this.editingContext.hashCode()} IN.po ${npo.editingContext.hashCode()}"
_lastValidPOCacheGID[this.permanentGlobalID()]=npo.permanentGlobalID() // the newly added offer is valid
... ... ...
}
===
Now, at beginning, it works exactly as presumed -- the valid PO is found and cached, and then found in EC; when a temp EC is created, it is fetched for the first time, then found:
=== (printout of GIDs cleaned up manually for better reading) ===
???? setting found last valid PO of [DBAuction.1000015]: <DBPriceOffer@344474980 PK:1000205 /EC:704069077> -> [DBPriceOffer.1000205] IN 704069077
???? found valid PO of [DBAuction.1000015]: [DBPriceOffer.1000205] -> <DBPriceOffer@344474980 PK:1000205 /EC:704069077> IN 704069077
???? fetched valid PO of [DBAuction.1000015]: [DBPriceOffer.1000205] -> <DBPriceOffer@890877103 PK:1000205 /EC:73728309> IN 73728309
???? found valid PO of [DBAuction.1000015]: [DBPriceOffer.1000205] -> <DBPriceOffer@890877103 PK:1000205 /EC:73728309> IN 73728309
===
When a new PO is added through addPriceOffer though, weird (to my flawed understanding) things happen: the PO is cached, is neither found in EC nor fetched, but IS found in the relationship -- what the darn?!? I would suppose it to be "found" at the line //1?!?
===
???? setting new valid PO of [DBAuction.1000015]: <DBPriceOffer@34841915 PK:null N /EC:73728309> -> [DBPriceOffer.1000206] IN.this 73728309 IN.po 73728309
???? fetched valid PO of [DBAuction.1000015]: [DBPriceOffer.1000206] -> null IN 73728309
???? setting found last valid PO of [DBAuction.1000015]: <DBPriceOffer@34841915 PK:null N /EC:73728309> -> [DBPriceOffer.1000206] IN 73728309
===
At this moment, the new object is saved into the database.
The very same behaviour repeats later in the default EC -- again, the new PO is neither found in EC nor fetched, but IS found in the relationship -- this time, I would suppose it to be "fetched" at the line //2?!?
===
???? fetched valid PO of [DBAuction.1000015]: [DBPriceOffer.1000206] -> null IN 704069077
???? setting found last valid PO of [DBAuction.1000015]: <DBPriceOffer@1582817960 PK:1000207 /EC:704069077> -> [DBPriceOffer.1000207] IN 704069077
===
Can anyone explain the behaviour, so that I can see which of my presumptions is wrong and why?
Thanks a lot,
OC
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden