• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Fetching record counts.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fetching record counts.


  • Subject: Re: Fetching record counts.
  • From: Arturo PĂ©rez <email@hidden>
  • Date: Mon, 31 Jan 2005 22:57:56 -0500


On Jan 31, 2005, at 9:33 PM, Marek Wawrzyczny wrote:

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).

Can anyone point me in the right direction on this?

EOF may not provide a locking mechanism but perhaps the Java one will suffice? Have you tried synchronizing on the entity, something like:

    public static Number objectCountWithFetchSpecification(
			EOEditingContext editingContext,
			EOFetchSpecification fetchSpecification) {

        if (fetchSpecification != null) {
            EOFetchSpecification rawFetchspecification;

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


            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      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Fetching record counts.
      • From: Marek Wawrzyczny <email@hidden>
References: 
 >Fetching record counts. (From: Marek Wawrzyczny <email@hidden>)

  • Prev by Date: Fetching record counts.
  • Next by Date: Re: Fetching record counts.
  • Previous by thread: Fetching record counts.
  • Next by thread: Re: Fetching record counts.
  • Index(es):
    • Date
    • Thread