Re: ERAttachment Framework Broken by Anjo Krank's ERXDatabaseContect "HACK"
Re: ERAttachment Framework Broken by Anjo Krank's ERXDatabaseContect "HACK"
- Subject: Re: ERAttachment Framework Broken by Anjo Krank's ERXDatabaseContect "HACK"
- From: Kwasi O-Ahoofe via Webobjects-dev <email@hidden>
- Date: Mon, 9 Aug 2021 11:16:50 -0400
Hi Paul:
Anjo’s “HACK” should test for EMPY and/or NONE-EXISTENT Snapshots for
RELATIONSHIPS that have not-been-fetched/accessed yet, meaning dbSnapshot
isNULL and dbSnapshot.objectForKey(key) throws exceptions and aborts the save
operations!!
Thanks.
This update is required to FIX the error, I hope:
// HACK: ak these methods are protected, so we call them via KVC
if (dbOp.databaseOperator() == 2 && ((Boolean)
NSKeyValueCoding.Utility.valueForKey(entity,
"_hasNonUpdateableAttributes")).booleanValue()) {
NSArray keys = (NSArray)
NSKeyValueCoding.Utility.valueForKey(entity, "dbSnapshotKeys");
NSDictionary dbSnapshotX = dbOp.dbSnapshot();
NSDictionary newRow = dbOp.newRow();
NSDictionary dbSnapshot =
ERXDictionaryUtilities.removeNullValues(dbSnapshotX);
if (dbSnapshot.isEmpty())
{
// do nothing
}
else
{
for (int i = keys.count() - 1; i >= 0; i--) {
String key = (String)
keys.objectAtIndex(i);
EOAttribute att =
entity.attributeNamed(key);
// FIX: ak when you have single-table
inheritance and in the
// child there are foreign keys that are not in
the parent
// THEN, if the entity
_hasNonUpdateableAttributes (public PK or
// read only props) the DB op is checked
// against the attributes. BUT this dictionary
has all entries,
// even from the child (most likely NULL values)
// and the current implementation doesn't check
against the case
// when the attribute isn't present in the
first place.
// SO we add this check and live happily ever
after
if (att != null &&
att._isNonUpdateable() &&
!dbSnapshot.objectForKey(key).equals(newRow.objectForKey(key))) {
if (att.isReadOnly()) {
throw new
IllegalStateException("cannot update read-only key '" + key + "' on object:" +
dbOp.object() + " of entity: " + entity.name() + " in databaseContext " + this);
}
throw new IllegalStateException("cannot
update primary-key '" + key + "' from '" + dbSnapshot.objectForKey(key) + "' to
'" + newRow.objectForKey(key) + "' on object:" + dbOp.object() + " of entity: "
+ entity.name() + " in databaseContext " + this);
}
}
}
}
/* */
_______________________________________________
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