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