From 71c64c23b31165a766ba2dd79711ab057c3c5352 Mon Sep 17 00:00:00 2001 From: Johann Werner Date: Thu, 16 Jan 2014 09:18:39 +0100 Subject: [PATCH] some optimizations for #495 --- .../extensions/eof/ERXEOControlUtilities.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXEOControlUtilities.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXEOControlUtilities.java index f97e831347b..a394f817119 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXEOControlUtilities.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXEOControlUtilities.java @@ -2052,24 +2052,27 @@ public static synchronized NSArray stringAttributeListForEntityNamed(EOEditingCo } /** - * Trims all values from string attributes from the given EO. - * @param object + * Trims all values from string attributes from the given EO unless the EO itself + * or the string attribute is flagged as read-only. + * + * @param object the EO whose string attributes should be trimmed */ public static void trimSpaces(EOEnterpriseObject object) { + EOEntity entity = EOUtilities.entityForObject(object.editingContext(), object); + if (entity.isReadOnly()) { + return; + } for (Enumeration e=ERXEOControlUtilities.stringAttributeListForEntityNamed(object.editingContext(), object.entityName()).objectEnumerator(); e.hasMoreElements();) { String key=(String)e.nextElement(); String value=(String)object.storedValueForKey(key); - if (value!=null) { - if (!EOUtilities.entityForObject(object.editingContext(), object).isReadOnly() && - !EOUtilities.entityForObject(object.editingContext(), object).attributeNamed(key).isReadOnly()) { - String trimmedValue=value.trim(); - if (trimmedValue.length()!=value.length()) - object.takeStoredValueForKey(trimmedValue,key); - } + if (value != null && !entity.attributeNamed(key).isReadOnly()) { + String trimmedValue=value.trim(); + if (trimmedValue.length()!=value.length()) + object.takeStoredValueForKey(trimmedValue,key); } } } - + /** * Convenience to get the destination entity name from a key path of an object. * Returns null if no destination found.