• 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: Setting setRefreshesRefetchedObjects using EOGenerator classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting setRefreshesRefetchedObjects using EOGenerator classes


  • Subject: Re: Setting setRefreshesRefetchedObjects using EOGenerator classes
  • From: Jeff Schmitz <email@hidden>
  • Date: Sun, 26 Oct 2008 22:02:20 -0500

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

_______________________________________________ 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
References: 
 >Setting setRefreshesRefetchedObjects using EOGenerator classes (From: Jeff Schmitz <email@hidden>)

  • Prev by Date: Setting setRefreshesRefetchedObjects using EOGenerator classes
  • Next by Date: generics and KVC.NullValue
  • Previous by thread: Setting setRefreshesRefetchedObjects using EOGenerator classes
  • Next by thread: Re: Setting setRefreshesRefetchedObjects using EOGenerator classes
  • Index(es):
    • Date
    • Thread