ERXCustomObject Class Reference

Inherits com::webobjects::eocontrol::EOCustomObject, er::extensions::eof::ERXGuardedObjectInterface, er::extensions::eof::ERXGeneratesPrimaryKeyInterface, and er::extensions::eof::ERXEnterpriseObject.

Collaboration diagram for ERXCustomObject:

Collaboration graph
[legend]

List of all members.

Classes

class  ERXCustomObjectClazz< T extends EOEnterpriseObject >

Public Member Functions

boolean _setUpdateInverseRelationships (boolean newValue)
void addObjectsToBothSidesOfRelationshipWithKey (NSArray objects, String key)
void addObjectToBothSidesOfRelationshipWithKey (EORelationshipManipulation eo, String key)
void awakeFromClientUpdate (EOEditingContext editingContext)
void awakeFromFetch (EOEditingContext editingContext)
void awakeFromInsertion (EOEditingContext editingContext)
void batchCheckConsistency () throws NSValidation.ValidationException
boolean canDelete ()
boolean canUpdate ()
NSDictionary changesFromCommittedSnapshot ()
void checkConsistency () throws NSValidation.ValidationException
Object committedSnapshotValueForKey (String key)
void delete ()
String description ()
void didDelete (EOEditingContext ec)
void didInsert ()
void didRevert (EOEditingContext ec)
void didUpdate ()
String encryptedPrimaryKey ()
void flushCaches ()
Object foreignKeyForRelationshipWithKey (String rel)
Logger getClassLog ()
boolean isDeletedEO ()
boolean isNewEO ()
boolean isNewObject ()
EOEnterpriseObject localInstanceIn (EOEditingContext ec)
EOEnterpriseObject localInstanceOf (EOEnterpriseObject eo)
NSArray localInstancesOf (NSArray eos)
void mightDelete ()
boolean parentObjectStoreIsObjectStoreCoordinator ()
String primaryKey ()
NSArray primaryKeyAttributeNames ()
NSDictionary primaryKeyDictionary (boolean inTransaction)
String primaryKeyInTransaction ()
Object rawPrimaryKey ()
Object rawPrimaryKeyInTransaction ()
ERXEnterpriseObject refetchObjectFromDBinEditingContext (EOEditingContext ec)
void removeObjectsFromBothSidesOfRelationshipWithKey (NSArray objects, String key)
void removeObjectsFromPropertyWithKey (NSArray objects, String key)
ERXEnterpriseObject self ()
void takeStoredValueForKey (Object value, String key)
void takeValueForKey (Object value, String key)
String toLongString ()
String toString ()
void trimSpaces ()
void validateForDelete () throws NSValidation.ValidationException
void validateForInsert () throws NSValidation.ValidationException
void validateForSave () throws NSValidation.ValidationException
void validateForUpdate () throws NSValidation.ValidationException
Object validateValueForKey (Object value, String key) throws NSValidation.ValidationException
void willDelete () throws NSValidation.ValidationException
void willInsert ()
void willRevert ()
void willUpdate ()

Static Public Member Functions

static boolean shouldTrimSpaces ()
static boolean usesDeferredFaultCreation ()

Public Attributes

String insertionStackTrace = null

Protected Member Functions

void excludeObjectFromPropertyWithKey (Object o, String key)
void includeObjectIntoPropertyWithKey (Object o, String key)
void init (EOEditingContext ec)

Protected Attributes

String _primaryKey = null
boolean wasInitialized

Private Member Functions

boolean _checkEditingContextDelegate (EOEditingContext editingContext)

Private Attributes

NSDictionary _primaryKeyDictionary
boolean _updateInverseRelationships = ERXGenericRecord.InverseRelationshipUpdater.updateInverseRelationships()

Static Private Attributes

static final
NSMutableDictionary< Class,
Logger > 
classLogs = new NSMutableDictionary<Class, Logger>()


Detailed Description

This class contains a bunch of extensions to the regular com.webobjects.eocontrol.EOCustomObject class. Of notable interest it contains built in support for generating primary keys via the ERXGeneratesPrimaryKeyInterface, support for an augmented transaction methods like willUpdate and didDelete and a bunch of handy utility methods like committedSnapshotValueForKey . At the moment it is required that those wishing to take advantage of templatized and localized validation exceptions need to subclass this class. Hopefully in the future we can get rid of this requirement. Also, this class supports auto-updating of inverse relationships. You can simply call eo.setFoo(other), eo.takeValueForKey(other), eo.addObjectToBothSidesOfRelationshipWithKey(other, "foo") or eo.addToFoos(other) and the inverse relationship will get updated for you automagically, so that you don't need to call other.addToBars(eo) or other.setBar(eo). Doing so doesn't hurt, though. Giving a null value of removing the object from a to-many will result in the inverse relationship getting cleared.
This feature should greatly help readability and reduce the number errors you make when you forget to update an inverse relationship. To turn this feature on, you must set the system default er.extensions.ERXEnterpriseObject.updateInverseRelationships=true.

Member Function Documentation

boolean _checkEditingContextDelegate ( EOEditingContext  editingContext  )  [private]

By default, and this should change in the future, all editing contexts that are created and use ERXEnterpriseObjects or subclasses need to have a delegate set of instance ERXEditingContextDelegate. These delegates provide the augmentation to the regular transaction mechanism, all of the will* methods plus the flushCaching method. To change the default behaviour set the property: er.extensions.ERXRaiseOnMissingEditingContextDelegate to false in your WebObjects.properties file. This method is called when an object is fetched, updated or inserted.

Parameters:
editingContext to check for the correct delegate.
Returns:
if the editing context has the correct delegate set.

boolean _setUpdateInverseRelationships ( boolean  newValue  )  [virtual]

Toggles whether or not inverse relationships should be updates. This is called by ERXGenericRecord.InverseRelationshipUpdater to prevent infinite loops and should not be called by anything else unless you know exactly what you are doing.

Parameters:
newValue whether or not inverse relationships should be updated
Returns:
the previous setting of the updateInverseRelationships setting

Implements ERXEnterpriseObject.

void addObjectsToBothSidesOfRelationshipWithKey ( NSArray  objects,
String  key 
) [virtual]

Adds a collection of objects to a given relationship by calling addObjectToBothSidesOfRelationshipWithKey for all objects in the collection.

Parameters:
objects objects to add to both sides of the given relationship
key relationship key

Implements ERXEnterpriseObject.

void addObjectToBothSidesOfRelationshipWithKey ( EORelationshipManipulation  eo,
String  key 
)

Adds a check to make sure that both the object being added and this object are in the same editing context. If not then a runtime exception is thrown instead of getting the somewhat cryptic NSInternalInconsistency excpetion that is thrown when you attempt to save changes to the database.

Parameters:
eo enterprise object to be added to the relationship
key relationship to add the object to.

void awakeFromClientUpdate ( EOEditingContext  editingContext  ) 

Checks the editing context delegate before calling super's implementation. See the method _checkEditingContextDelegate for an explanation as to what this check does.

Parameters:
editingContext to be checked to make sure it has the correct type of delegate set.

void awakeFromFetch ( EOEditingContext  editingContext  ) 

Checks the editing context delegate before calling super's implementation. See the method _checkEditingContextDelegate for an explanation as to what this check does.

Parameters:
editingContext to be checked to make sure it has the correct type of delegate set.

void awakeFromInsertion ( EOEditingContext  editingContext  ) 

Checks the editing context delegate before calling super's implementation. See the method _checkEditingContextDelegate for an explanation as to what this check does.

Parameters:
editingContext to be checked to make sure it has the correct type of delegate set.

void batchCheckConsistency (  )  throws NSValidation.ValidationException [virtual]

This method is very similar to the checkConsistency method except that this method is only called from an outside process, usually a batch process, to verify that the data this object holds is consistent. JUnit tests are great for testing that all of the methods of a single object function correctly, batch checking of consistency is a good way of checking that all of the data in a given database is consistent. Hopefully in the future we will add a batch check consistency application to demonstrate the use of this method.

Exceptions:
NSValidation.ValidationException if the object fails consistency

Implements ERXEnterpriseObject.

boolean canDelete (  ) 

Implementation of ERXGuardedObjectInterface. This is checked before the object is deleted in the willDelete method which is in turn called by ERXEditingContextDelegate. The default implementation returns true.

Returns:
true

Implements ERXGuardedObjectInterface.

boolean canUpdate (  ) 

Implementation of ERXGuardedObjectInterface. This is checked before the object is deleted in the willUpdate method which is in turn called by ERXEditingContextDelegate. The default implementation returns true.

Returns:
true

Implements ERXGuardedObjectInterface.

NSDictionary changesFromCommittedSnapshot (  )  [virtual]

Computes the current set of changes that this object has from the currently committed snapshot.

Returns:
a dictionary holding the changed values from the currently committed snapshot.

Implements ERXEnterpriseObject.

void checkConsistency (  )  throws NSValidation.ValidationException [virtual]

Debugging method that will be called on an object before it is saved to the database if the property key: ERDebuggingEnabled is enabled. This allows for adding in a bunch of expensive validation checks that should only be enabled in development and testing environments.

Exceptions:
NSValidation.ValidationException if the object is not consistent

Implements ERXEnterpriseObject.

Object committedSnapshotValueForKey ( String  key  )  [virtual]

Determines what the value of the given key is in the committed snapshot

Parameters:
key to be checked in committed snapshot
Returns:
the committed snapshot value for the given key

Implements ERXEnterpriseObject.

void delete (  ) 

Implementation of ERXGuardedObjectInterface. This is used to work around a bug in EOF that doesn't refresh the relationship in the parent editingContext for the object.

Implements ERXGuardedObjectInterface.

String description (  )  [virtual]

Cover method to return toString.

Returns:
the results of calling toString.

Implements ERXEnterpriseObject.

void didDelete ( EOEditingContext  ec  )  [virtual]

Called on the object after is has been deleted. The editing context is passed to the object since by this point the editingContext of the object is null. You should check if the ec is a child context when doing something here that can't be undone.

Parameters:
ec editing context that used to be associated with the object.

Implements ERXEnterpriseObject.

void didInsert (  )  [virtual]

Called on the object after is has successfully been inserted into the database.

Implements ERXEnterpriseObject.

void didRevert ( EOEditingContext  ec  )  [virtual]

Called on the object after it has been reverted. The editing context is passed to the object because if the object was in the insertedObjects list before the revert, the object has had its editingContext nulled.

Default implementation calls flushCaches.

Parameters:
ec editing context that is either currently associated with the object if the object was marked as changed or deleted before the revert, otherwise the editing context that was associated with the object before the revert.

Implements ERXEnterpriseObject.

void didUpdate (  )  [virtual]

Called on the object after is has successfully been updated in the database.

Implements ERXEnterpriseObject.

String encryptedPrimaryKey (  )  [virtual]

Takes the primary key of the object and encrypts it with the blowfish cipher using ERXCrypto.

Returns:
blowfish encrypted primary key

Implements ERXEnterpriseObject.

void excludeObjectFromPropertyWithKey ( Object  o,
String  key 
) [protected]

Overridden to support two-way relationship setting.

void flushCaches (  )  [virtual]

This is called when an object has had changes merged into it by the editing context. This is called by ERXDefaultEditingContextDelegate after it merges changes. Any caches that an object keeps based on any of it's values it should flush. The default implementation of this method does nothing.

Implements ERXEnterpriseObject.

Object foreignKeyForRelationshipWithKey ( String  rel  )  [virtual]

Returns the foreign key for a given relationship.

Parameters:
rel relationship key
Returns:
foreign key for a given relationship.

Implements ERXEnterpriseObject.

Logger getClassLog (  )  [virtual]

This methods checks if we already have created an Logger for this class If not, one will be created, stored and returned on next request. This method eliminates individual static variables for Logger's in all subclasses. We use an NSDictionary here because static fields are class specific and thus something like lazy initialization would not work in this case.

Returns:
an Logger for this objects class

Implements ERXEnterpriseObject.

void includeObjectIntoPropertyWithKey ( Object  o,
String  key 
) [protected]

Overridden to support two-way relationship setting.

void init ( EOEditingContext  ec  )  [protected]

used for initialization stuff instead of awakeFromInsertion. awakeFromInsertions is buggy because if an EO is deleted and then its EOEditingContext is reverted using 'revert' for example then EOF will -insert- this EO again in its EOEditingContext which in turn calls awakeFromInsertion again.

Parameters:
ec the EOEditingContext in which this new EO is inserted

boolean isDeletedEO (  )  [virtual]

Determines if this object is a deleted object by checking to see if it is included in the deletedObjects array of the editing context or - if it's editing context is null - it already has a global id.

Returns:
if the object is a deleted object

Implements ERXEnterpriseObject.

boolean isNewEO (  ) 

boolean isNewObject (  )  [virtual]

Determines if this object is a new object and hasn't been saved to the database yet. This method just calls the method ERExtensions.isNewObject passing in this object as the current parameter. Note that an object that has been successfully deleted will also look as if it is a new object because it will have a null editing context.

Returns:
if the object is a new enterprise object.

Implements ERXEnterpriseObject.

EOEnterpriseObject localInstanceIn ( EOEditingContext  ec  )  [virtual]

Returns this EO in the supplied editing context.

Returns:
this EO in the supplied editing context.

Implements ERXEnterpriseObject.

EOEnterpriseObject localInstanceOf ( EOEnterpriseObject  eo  )  [virtual]

Returns an EO in the same editing context as the caller.

Returns:
an EO in the same editing context as the caller.

Implements ERXEnterpriseObject.

NSArray localInstancesOf ( NSArray  eos  )  [virtual]

Returns an array of EOs in the same editing context as the caller.

Returns:
array of EOs in the same editing context as the caller.

Implements ERXEnterpriseObject.

void mightDelete (  )  [virtual]

Called as part of the augmented transaction process. This method is called when deleteObject() is called on the editing context. The benefit over willDelete() is that in this method, the relationships are still intact. Mostly, at least, as it's also called when the deletes cascade.

Implements ERXEnterpriseObject.

boolean parentObjectStoreIsObjectStoreCoordinator (  )  [virtual]

Simple method that will return if the parent object store of this object's editing context is an instance of EOObjectStoreCoordinator. The reason this is important is because if this condition evaluates to true then when changes are saved in this editing context they will be propagated to the database.

Returns:
if the parent object store of this object's editing context is an EOObjectStoreCoordinator.

Implements ERXEnterpriseObject.

String primaryKey (  )  [virtual]

Primary key of the object as a String.

Returns:
primary key for the given object as a String

Implements ERXEnterpriseObject.

NSArray primaryKeyAttributeNames (  )  [virtual]

Returns the names of all primary key attributes.

Implements ERXEnterpriseObject.

NSDictionary primaryKeyDictionary ( boolean  inTransaction  ) 

Implementation of the interface ERXGeneratesPrimaryKeyInterface. This implementation operates in the following fashion. If it is called passing in 'false' and it has not yet been saved to the database, meaning this object does not yet have a primary key assigned, then it will have the adaptor channel generate a primary key for it. Then when the object is saved to the database it will use the previously generated primary key instead of having the adaptor channel generate another primary key. If 'true' is passed in then this method will either return the previously generated primaryKey dictionary or null if it does not have one. Typically you should only call this method with the 'false' parameter seeing as unless you are doing something really funky you won't be dealing with this object when it is in the middle of a transaction. The delegate ERXDatabaseContextDelegate is the only class that should be calling this method and passing in 'true'.

Parameters:
inTransaction boolean flag to tell the object if it is currently in the middle of a transaction.
Returns:
primary key dictionary for the current object, if the object does not have a primary key assigned yet and is not in the middle of a transaction then a new primary key dictionary is created, cached and returned.

Implements ERXGeneratesPrimaryKeyInterface.

String primaryKeyInTransaction (  )  [virtual]

Calling this method will return the primary key of the given enterprise object or if one has not been assigned to it yet, then it will have the adaptor channel generate one for it, cache it and then use that primary key when it is saved to the database. This method returns the string representation of the primary key. If you just want the primary key of the object or null if it doesn't have one yet, use the method primaryKey.

Returns:
string representation of the primary key of this object.

Implements ERXEnterpriseObject.

Object rawPrimaryKey (  )  [virtual]

Gives the raw primary key of the object. This could be anything from an NSData to a BigDecimal.

Returns:
the raw primary key of this object.

Implements ERXEnterpriseObject.

Object rawPrimaryKeyInTransaction (  )  [virtual]

Calling this method will return the primary key of the given enterprise object or if one has not been assigned to it yet, then it will have the adaptor channel generate one for it, cache it and then use that primary key when it is saved to the database. If you just want the primary key of the object or null if it doesn't have one yet, use the method rawPrimaryKey.

Returns:
the primary key of this object.

Implements ERXEnterpriseObject.

ERXEnterpriseObject refetchObjectFromDBinEditingContext ( EOEditingContext  ec  )  [virtual]

Method that will make sure to fetch an eo from the Database and place it in the editingContext provided as an argument

Parameters:
ec the editing context in which the result will be placed
Returns:
fresh instance of an EO fetched from the DB and placed in the editing context argument

Implements ERXEnterpriseObject.

void removeObjectsFromBothSidesOfRelationshipWithKey ( NSArray  objects,
String  key 
) [virtual]

Removes a collection of objects to a given relationship by calling removeObjectFromBothSidesOfRelationshipWithKey for all objects in the collection.

Parameters:
objects objects to be removed from both sides of the given relationship
key relationship key

Implements ERXEnterpriseObject.

void removeObjectsFromPropertyWithKey ( NSArray  objects,
String  key 
) [virtual]

Removes a collection of objects to a given relationship by calling removeObjectFromPropertyWithKey for all objects in the collection.

Parameters:
objects objects to be removed from both sides of the given relationship
key relationship key

Implements ERXEnterpriseObject.

ERXEnterpriseObject self (  )  [virtual]

self is usefull for directtoweb purposes

Implements ERXEnterpriseObject.

static boolean shouldTrimSpaces (  )  [static]

void takeStoredValueForKey ( Object  value,
String  key 
)

void takeValueForKey ( Object  value,
String  key 
)

String toLongString (  )  [virtual]

Returns the super classes implementation of toString which prints out the current key-value pairs for all of the attributes and relationships for the current object. Very verbose.

Returns:
super's implementation of toString.

Implements ERXEnterpriseObject.

String toString (  ) 

Overrides the EOGenericRecord's implementation to provide a slightly less verbose output. A typical output for an object mapped to the class com.foo.User with a primary key of 50 would look like: <com.foo.User pk:"50"> EOGenericRecord's implementation is preserved in the method toLongString. To restore the original verbose logging in your subclasses override this method and return toLongString.

Returns:
much less verbose description of an enterprise object.

void trimSpaces (  )  [virtual]

This method will trim the leading and trailing white space from any attributes that are mapped to a String object. This method is called before the object is saved to the database. Override this method to do nothing if you wish to preserve your leading and trailing white space.

Implements ERXEnterpriseObject.

static boolean usesDeferredFaultCreation (  )  [static]

void validateForDelete (  )  throws NSValidation.ValidationException

Calls up validateForUpdate() on the class description if it supports it.

Exceptions:
NSValidation.ValidationException if the object does not pass validation for saving to the database.

void validateForInsert (  )  throws NSValidation.ValidationException

Calls up validateForInsert() on the class description if it supports it.

Exceptions:
NSValidation.ValidationException if the object does not pass validation for saving to the database.

void validateForSave (  )  throws NSValidation.ValidationException

This method performs a few checks before invoking super's implementation. If the property key: ERDebuggingEnabled is set to true then the method checkConsistency will be called on this object.

Exceptions:
NSValidation.ValidationException if the object does not pass validation for saving to the database.

void validateForUpdate (  )  throws NSValidation.ValidationException

Calls up validateForUpdate() on the class description if it supports it.

Exceptions:
NSValidation.ValidationException if the object does not pass validation for saving to the database.

Object validateValueForKey ( Object  value,
String  key 
) throws NSValidation.ValidationException

Overrides the default validation mechanisms to provide a few checks before invoking super's implementation, which incidently just invokes validateValueForKey on the object's class description. The class description for this object should be an ERXEntityClassDescription or subclass. It is that class that provides the hooks to convert model throw validation exceptions into ERXValidationException objects.

Parameters:
value to be validated for a given attribute or relationship
key corresponding to an attribute or relationship
Exceptions:
NSValidation.ValidationException if the value fails validation
Returns:
the validated value

void willDelete (  )  throws NSValidation.ValidationException [virtual]

Called as part of the augmented transaction process. This method is called after saveChanges is called on the editing context, but before the object is actually deleted from the database. This method is also called before validateForDelete is called on this object. This method is called by the editing context delegate ERXDefaultEditingContextDelegate.

Exceptions:
NSValidation.ValidationException to stop the object from being deleted.

Implements ERXEnterpriseObject.

void willInsert (  )  [virtual]

Called as part of the augmented transaction process. This method is called after saveChanges is called on the editing context, but before the object is actually inserted into the database. This method is also called before validateForInsert is called on this object. This method is called by the editing context delegate ERXDefaultEditingContextDelegate.

Implements ERXEnterpriseObject.

void willRevert (  )  [virtual]

Called on the object before it will be reverted.

Default implementation does nothing other than log.

Implements ERXEnterpriseObject.

void willUpdate (  )  [virtual]

Called as part of the augmented transaction process. This method is called after saveChanges is called on the editing context, but before the object is actually updated in the database. This method is also called before validateForSave is called on this object. This method is called by the editing context delegate ERXDefaultEditingContextDelegate.

Implements ERXEnterpriseObject.


Member Data Documentation

String _primaryKey = null [protected]

NSDictionary _primaryKeyDictionary [private]

caches the primary key dictionary for the given object

final NSMutableDictionary<Class, Logger> classLogs = new NSMutableDictionary<Class, Logger>() [static, private]

holds all subclass related Logger's

boolean wasInitialized [protected]


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:07 2012 for Project Wonder by  doxygen 1.5.8