site_archiver@lists.apple.com Delivered-To: webobjects-dev@lists.apple.com On Jan 31, 2005, at 9:33 PM, Marek Wawrzyczny wrote: Can anyone point me in the right direction on this? public static Number objectCountWithFetchSpecification( EOEditingContext editingContext, EOFetchSpecification fetchSpecification) { if (fetchSpecification != null) { EOFetchSpecification rawFetchspecification; if ((results != null) && (results.count() == 1)) { NSDictionary row = (NSDictionary) results.lastObject(); return (Number)row.objectForKey(attribute.name()); } } return null; } _______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (Webobjects-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/site_archiver%40lists.... This is actually where I am stuck. I don't understand the EOModel and EOAttribute mechanism very well. One solution I tried was to add the count attribute permanently, that crashed the application. So I tried creating the attributes on the fly and removing them once finished this worked. However, it doesn't appear I can make this thread-safe since there is no locking mechanism on the EOModel (I think this is why Eric's solution used a static var) and I cannot easily test this concept under duress (when the exceptions actually start occurring). EOF may not provide a locking mechanism but perhaps the Java one will suffice? Have you tried synchronizing on the entity, something like: try { rawFetchspecification = (EOFetchSpecification)fetchSpecification.clone(); } catch (Exception e) { System.out.println("\nException in objectCountWithFetchSpecification :\n"+e); return null; } EOEntity entity = EOModelGroup.defaultGroup().entityNamed(rawFetchspecification.entityName ()); synchronized (entity) { // ADDED SYNCHRONIZED EOQualifier schemaBasedQualifier = entity.schemaBasedQualifier(rawFetchspecification.qualifier()); EOAttribute attribute = EOFetchCounting.objectCountAttribute(); NSArray results = null; entity.addAttribute(attribute); // Fix to ensure that fetch counting does not trip the site when // the fetch fails for some reason try { rawFetchspecification.setQualifier(schemaBasedQualifier); rawFetchspecification.setRawRowKeyPaths(new NSArray(attribute.name())); results = editingContext.objectsWithFetchSpecification(rawFetchspecification); } finally { // IMPORTANT!!! // This needs to run every time, exception or not entity.removeAttribute(attribute); } } // CLOSE SYNCHRONIZED This email sent to site_archiver@lists.apple.com
participants (1)
-
Arturo Pérez