Nevermind I think,

I just found the below EO operation that should do exactly what I need. Whenever I need to make sure I have the very freshest data from the database in my EO, I'll just call:

public ERXEnterpriseObject refetchObjectFromDBinEditingContext(EOEditingContext ec) {
                EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, 
entityName());
EOQualifier qual = entity.qualifierForPrimaryKey(primaryKeyDictionary(false)); EOFetchSpecification fetchSpec = new EOFetchSpecification(entityName(), qual, null);
                fetchSpec.setRefreshesRefetchedObjects(true);
                NSArray results = ec.objectsWithFetchSpecification(fetchSpec);
                ERXEnterpriseObject freshObject = null;
                if (results.count() > 0) {
                        freshObject = (ERXEnterpriseObject) 
results.objectAtIndex(0);
                }
                return freshObject;
        }

Thanks,
Jeff

On Oct 26, 2008, at 9:25 AM, Jeff Schmitz wrote:

Hello,
I'd like to be able programatically set the setRefreshesRefetchedObjects on specific fetch specifications to true under certain, "run-time" situations to assure I have fresh data from the database when a fetch is performed.

Using the EOGenerator generated "fetch" functions, the Fetch specs are always local to the generated operations, so I'm thinking the only way to do what I need would be to copy a "set" of fetch operations from the generated EO code and change it accordingly in my edited EOCode as shown below. Is there a simpler way to do this that I'm missing? Is there a way to get EOGenerator to produce such functions?


Copied from _Entry.java, pasted into Entry.java and edited to add call to setRefreshesRefetchedObjects:

public static NSArray<Entry> fetchRefreshedEntries(EOEditingContext editingContext, EOQualifier qualifier, NSArray<EOSortOrdering> sortOrderings) { EOFetchSpecification fetchSpec = new EOFetchSpecification(_Entry.ENTITY_NAME, qualifier, sortOrderings);
  fetchSpec. setRefreshesRefetchedObjects(true);
   fetchSpec.setIsDeep(true);
NSArray<Entry> eoObjects = (NSArray <Entry>)editingContext.objectsWithFetchSpecification(fetchSpec);
   return eoObjects;
 }

public static Entry fetchRefreshedEntry(EOEditingContext editingContext, String keyName, Object value) { return _Entry.fetchRefreshedEntry(editingContext, new EOKeyValueQualifier(keyName, EOQualifier.QualifierOperatorEqual, value));
 }

public static Entry fetchRefreshedEntry(EOEditingContext editingContext, EOQualifier qualifier) { NSArray<Entry> eoObjects = _Entry.fetchRefreshedEntries(editingContext, qualifier, null);
   Entry eoObject;
   int count = eoObjects.count();
   if (count == 0) {
     eoObject = null;
   }
   else if (count == 1) {
     eoObject = (Entry)eoObjects.objectAtIndex(0);
   }
   else {
throw new IllegalStateException("There was more than one Entry that matched the qualifier '" + qualifier + "'.");
   }
   return eoObject;
 }

thanks,
Jeff
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/jeffandmonica%40mac.com

This email sent to [EMAIL PROTECTED]

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to