• 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: Force Refresh Relation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Force Refresh Relation


  • Subject: Re: Force Refresh Relation
  • From: Lachlan Deck <email@hidden>
  • Date: Thu, 20 Sep 2007 16:19:38 +1000

Hi Alan,

(hope you have a minute...)

On 20/09/2007, at 2:24 PM, Alan Ward wrote:

"don't use the shared EC" is very much like "use ec.invalidateAllObjecs()"

Both are not good advice.

Well put. Would you have any ideas, however, why unless I use invalidateAllObjects on the shared ec periodically it doesn't pick up newly inserted objects added by another app into the db, or indeed forgetting objects that have been marked with isDeleted=true (which is part of the restricting qualifier)?


I'm using a timer to periodically refetch the various entities in the app into the shared ec. This is not modelled in the eomodel seeing as there's more than one app using the models. The timestamp lag is set to around 5 minutes on the shared ec.

protected void reloadSharedEntities()
{
<...>
for ( Enumeration en = sharedEntitiesNames().objectEnumerator(); en.hasMoreElements(); )
{
if ( NSPropertyListSerialization.booleanForString ( NSProperties.getProperty ( "MyApplication.sharedEntitiesInvalidation", "false" ) )
{
sharedEc.lock();
try {
sharedEditingContext().invalidateAllObjects();
} finally {
sharedEditingContext().unlock();
}
}
refetchSharedRecordsForEntity( entityName );
}
}


protected NSArray refetchSharedRecordsForEntity( String entityName )
{
EOFetchSpecification fetchSpec;
NSArray sortOrderings;

try
{
EOEntity theEntity = EOModelGroup.defaultGroup().entityNamed ( entityName );
Class entityClass = Class.forName( theEntity.className() );
Method fetchSpecMethod = entityClass.getMethod ( "sharedFetchSpecification", null );
fetchSpec = ( EOFetchSpecification )fetchSpecMethod.invoke ( entityClass, null );
}
catch ( Exception e )
{
fetchSpec = new EOFetchSpecification( entityName, null, null );
}


EOQualifier auxiliaryQualifier = ( EOQualifier ) sharedEntitiesAuxiliaryQualifiers().valueForKey( entityName );
if ( auxiliaryQualifier != null )
{
if ( fetchSpec.qualifier() != null )
{
auxiliaryQualifier = new EOAndQualifier( new NSArray( new Object[] {
auxiliaryQualifier, fetchSpec.qualifier()
} );
}
fetchSpec.setQualifier( auxiliaryQualifier );
}

sortOrderings = ( NSArray )sharedEntitiesSortOrderings().valueForKey ( entityName );
if ( sortOrderings != null )
{
if ( fetchSpec.sortOrderings() != null )
fetchSpec.setSortOrderings( fetchSpec.sortOrderings ().arrayByAddingObjectsFromArray( sortOrderings ) );
else fetchSpec.setSortOrderings( sortOrderings );
}

return refetchSharedRecordsWithFetchSpecification( fetchSpec );
}


protected NSArray refetchSharedRecordsWithFetchSpecification ( EOFetchSpecification fetchSpec )
{
NSArray records;
try
{
EOFetchSpecification fetchSpecCopy = ( EOFetchSpecification ) fetchSpec.clone();
fetchSpecCopy.setRefreshesRefetchedObjects( true );
records = sharedEditingContext().objectsWithFetchSpecification ( fetchSpecCopy, sharedEditingContext() );
}
catch ( RuntimeException rte )
{
LOG.error( "Refetch error for entity: " + fetchSpec.entityName(), rte );
records = NSArray.EmptyArray;
}
return records;
}


with regards,
--

Lachlan Deck



_______________________________________________
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: Force Refresh Relation
      • From: Alexander Spohr <email@hidden>
References: 
 >Force Refresh Relation (From: "Daniele Corti" <email@hidden>)
 >Re: Force Refresh Relation (From: Amedeo Mantica <email@hidden>)
 >Re: Force Refresh Relation (From: Kieran Kelleher <email@hidden>)
 >Re: Force Refresh Relation (From: Alan Ward <email@hidden>)
 >Re: Force Refresh Relation (From: Lachlan Deck <email@hidden>)
 >Re: Force Refresh Relation (From: Kieran Kelleher <email@hidden>)
 >Re: Force Refresh Relation (From: Lachlan Deck <email@hidden>)
 >Re: Force Refresh Relation (From: Alan Ward <email@hidden>)

  • Prev by Date: Re: Force Refresh Relation
  • Next by Date: Wonder How to get it running?
  • Previous by thread: Re: Force Refresh Relation
  • Next by thread: Re: Force Refresh Relation
  • Index(es):
    • Date
    • Thread