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      (Webobjects-dev@lists.apple.com)
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