Project Wonder 2.0

er.extensions
Class ERXTolerantSaver

java.lang.Object
  extended byer.extensions.ERXTolerantSaver

public class ERXTolerantSaver
extends Object

This class is pulled directly out of David Neumann's ChangeNotification framework. The only changes made are to use log4j instead of System.out.println.

The tolerant saver provides a way to save an editing context in a tolerant fashion. By tolerant we mean that you can have the option to save an editing context and have the exception ignored, hvae the changes merged from the database or stomp all the changes the database regardless of locking. The entry point for using this class is the save method.


Field Summary
static ERXLogger log
          logging support
 
Constructor Summary
ERXTolerantSaver()
           
 
Method Summary
static String _save(EOEditingContext ec, boolean writeAnyWay, boolean merge)
          Entry point for saving an editing context in a tolerant manner.
static void applyChangesToEO(NSDictionary changedValues, EOEnterpriseObject failedEO, EOEntity ent)
          Method used to apply a set of changes to a re-fetched eo.
static void applyEOChangesForValue(Object val, NSArray rels, EOEnterpriseObject eo)
          Method used to push an object identified by it's primary key into one or many relationships off of a given enterprise object.
static String errorFromException(Exception e)
           
static NSDictionary primaryKeyFor(Object val, EOEntity destEnt)
          Constructs a primary key dictionary given a value and an entity.
static EOQualifier qualifierWithSnapshotAndPks(NSArray pkAttribs, NSDictionary snapshot)
          Constructs a qualifier for a given array of primary key attributes and a given snapshot.
static NSArray relationshipsForAttribute(EOAttribute attrib, NSArray rels)
          Filters a list of relationships for only the ones that have a given EOAttribute as a source attribute.
static String save(EOEditingContext ec, boolean writeAnyWay)
          Cover method for calling the method save with the third parameter (merge) set to true.
static String save(EOEditingContext ec, boolean writeAnyWay, boolean merge)
           
static String saveMerge(EOEditingContext ec, boolean writeAnyWay, boolean merge)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final ERXLogger log
logging support

Constructor Detail

ERXTolerantSaver

public ERXTolerantSaver()
Method Detail

relationshipsForAttribute

public static NSArray relationshipsForAttribute(EOAttribute attrib,
                                                NSArray rels)
Filters a list of relationships for only the ones that have a given EOAttribute as a source attribute. This implementation igonores relationships that have compound keys.

Parameters:
attrib - EOAttribute to filter source attributes of relationships.
rels - array of EORelationship objects.
Returns:
filtered array of EORelationship objects that have the given attribute as the source attribute.

primaryKeyFor

public static NSDictionary primaryKeyFor(Object val,
                                         EOEntity destEnt)
Constructs a primary key dictionary given a value and an entity. This implementation ignores entities that have multiple primary keys.

Parameters:
val - primary key to be the value in the dictionary.
destEnt - entity to construct the primary key dictionary for.
Returns:
primary key dictionary for the given value and entity

applyEOChangesForValue

public static void applyEOChangesForValue(Object val,
                                          NSArray rels,
                                          EOEnterpriseObject eo)
Method used to push an object identified by it's primary key into one or many relationships off of a given enterprise object.

Parameters:
val - primary key of a given object
rels - array of relationships that the object should be added to.
eo - enterprise object to have the object added to.

applyChangesToEO

public static void applyChangesToEO(NSDictionary changedValues,
                                    EOEnterpriseObject failedEO,
                                    EOEntity ent)
Method used to apply a set of changes to a re-fetched eo. This method is used to re-apply changes to a given eo after it has been refetched.

Parameters:
changedValues - dictionary of the changed values to be applied to the object.
failedEO - enterprise object to have the changes re-applied to.
ent - EOEntity of the failedEO

qualifierWithSnapshotAndPks

public static EOQualifier qualifierWithSnapshotAndPks(NSArray pkAttribs,
                                                      NSDictionary snapshot)
Constructs a qualifier for a given array of primary key attributes and a given snapshot.

Parameters:
pkAttribs - array of EOAttributes that define the primary keys of a given entity
snapshot - to form the qualifier for
Returns:
qualifier that can be used to re-fetch the given snapshot.

save

public static String save(EOEditingContext ec,
                          boolean writeAnyWay)
Cover method for calling the method save with the third parameter (merge) set to true. See the description of the three parameter version for a detailed explanation.

Parameters:
ec - editing context to be saved.
writeAnyWay - boolean flag to determine if the editing context should be resaved after a general adaptor exception
Returns:
string representation of the exception that happened. This will be changed in the future.

saveMerge

public static String saveMerge(EOEditingContext ec,
                               boolean writeAnyWay,
                               boolean merge)

_save

public static String _save(EOEditingContext ec,
                           boolean writeAnyWay,
                           boolean merge)
Entry point for saving an editing context in a tolerant manner. The two flags for this methad are writeAnyWay and merge. The writeAnyWay flag controls if a second save should be performed if the first operation fails due to a general adaptor operation. Note that even if this option is specified as false the object will be refetched and optionally have the new changes merged into. This means that the objects that failed saving to the database will be ready to be saved if writeAnyWay is false. The second option is to merge the previous changes if a failure occurs. If this is set to true then when a locking failure occurs the object is refetched and then the previous changes are re-applied to the object.

Parameters:
ec - editing context to be saved
writeAnyWay - boolean flag to determine if an editing context should be saved again after a failure.
merge - boolean flag that determines if changes should be re-applied if a locking failure occurs when the first save happens
Returns:
string indicating the exception that happened, null if everything went smooth. This should be changed in the future.

save

public static String save(EOEditingContext ec,
                          boolean writeAnyWay,
                          boolean merge)

errorFromException

public static String errorFromException(Exception e)

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.