Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There is a performance hit on your Application when EOSharedEditingContexts are enabled. If your application does not use them, you should call:

Panelcode

  EOSharedEditingContext.setDefaultSharedEditingContext(null);

in your Application constructor. This will disable shared editing contexts completely, and you will no longer see any performance loss.

...

Then, in Application I have two methods:

Panel
Wiki Markup
Code Block

public static void refreshSharedEntity(String entityName) throws MarvinGeneralException {
   Application.refreshSharedEntityForFetchSpecificationName(entityName,   "FetchAll");    
}
  
public static void refreshSharedEntityForFetchSpecificationName(String entityName, String fetchSpecName) 
        throws MarvinGeneralException {
  
EOModelGroup modelGroup = EOModelGroup.defaultGroup();
  
EOSharedEditingContext sharedEC =
  EOSharedEditingContext.defaultSharedEditingContext();
  
EOFetchSpecification fs = modelGroup.fetchSpecificationNamed(fetchSpecName, entityName);
        
  
if (fs == null) {            
    throw new MarvinGeneralException(Application.class.getName() + ".refreshSharedEntityForFetchSpecificationName", 
            entityName + "." + fetchSpecName + " doesn't exist");        
  
} else {
    
sharedEC.bindObjectsWithFetchSpecification(fs, fetchSpecName);        
  
}
}

I use these methods for updating the shared editing context for a specific entity.

As an example for an entity, I have the methods:

Panel
Wiki Markup
Code Block

public static NSArray enclosureMasters() {
  
NSDictionary objectsByEntityName = (NSDictionary)EOSharedEditingContext.defaultSharedEditingContext()
          .objectsByEntityNameAndFetchSpecificationName();
  
NSDictionary objectsForEnclosureMaster = (NSDictionary) objectsByEntityName.objectForKey("EnclosureMaster");
  
NSArray enclosureMasters = (NSArray) objectsForEnclosureMaster.objectForKey("FetchAll");
  return enclosureMasters;
}
  
public static NSArray enclosureMasters(String fetchSpecName, NSDictionary bindings) {
  
// filter in memory against all enclosure masters 
  
// EOQualifier.filteredArrayWithQualifier( NSArray objects, EOQualifier aQualifier)
  
  if (bindings == null) bindings = new NSDictionary();
  
EOFetchSpecification fetchSpec = EOFetchSpecification.fetchSpecificationNamed(fetchSpecName, "EnclosureMaster");
  
EOQualifier boundQualifier = fetchSpec.qualifier().qualifierWithBindings(bindings, 
          fetchSpec.requiresAllQualifierBindingVariables());
  
if (boundQualifier == null) return
  
EnclosureMaster.enclosureMasters(); // return all - 
             
// otherwise the next call will give us an empty array
  
NSArray results = EOQualifier.filteredArrayWithQualifier(EnclosureMaster.enclosureMasters(), boundQualifier);
  
// we should now use the fetchSpec's sort orderings to sort the results
  NSArray sortedResults = results;
  
NSArray sortOrderings = fetchSpec.sortOrderings();
  
if (sortOrderings != null)
    
sortedResults = EOSortOrdering.sortedArrayUsingKeyOrderArray(results, sortOrderings);
  
return sortedResults;
}

These two methods let me fetch all objects of a certain type and, even better, let me use my other fetch specs on these objects.

...

When you addd a new object you have to reload by calling, for example,

Panelcode

  Application.refreshSharedEntity("EnclosureMaster"
(wink)
;);

When you edit or delete a shared entity the SharedEditing context will take care of updating the objects it's holding.

...