Project Wonder 5.0

er.extensions.eof
Class ERXDatabaseContextDelegate

java.lang.Object
  extended by er.extensions.eof.ERXDatabaseContextDelegate

public class ERXDatabaseContextDelegate
extends java.lang.Object

This delegate implements several methods from the formal interface EODatabaseContext.Delegate. Of special note this class adds the ability for enterprise objects to generate their own primary keys, correctly throws an exception when a toOne relationship object is not found in the database and adds debugging abilities to tracking down when faults are fired. It also supports a cache for array fault that is checked before they are fetched from the database.


Nested Class Summary
static interface ERXDatabaseContextDelegate.AutoBatchFaultingEnterpriseObject
          Interface to provide auto-magic batch fetching.
static interface ERXDatabaseContextDelegate.BatchHandler
           
static class ERXDatabaseContextDelegate.ObjectNotAvailableException
           
 
Field Summary
static int autoBatchFetchSize
          Holds the auto batch fetch size.
static org.apache.log4j.Logger batchLog
          Faulting logging support, logging category: er.transaction.adaptor.Batching
static java.lang.String DatabaseContextFailedToFetchObject
           
static org.apache.log4j.Logger dbLog
          Faulting logging support, logging category: er.transaction.adaptor.FaultFiring
static org.apache.log4j.Logger exLog
          Faulting logging support, logging category: er.transaction.adaptor.Exceptions
static org.apache.log4j.Logger log
          Basic logging support
static java.lang.String THREAD_KEY
          Batching thread key
 
Constructor Summary
ERXDatabaseContextDelegate()
           
 
Method Summary
 ERXArrayFaultCache arrayFaultCache()
           
static int autoBatchFetchSize()
          Returns the batch size for automatic batch faulting from the System property er.extensions.ERXDatabaseContextDelegate.autoBatchFetchSize.
 void databaseContextDidFetchObjects(com.webobjects.eoaccess.EODatabaseContext dbc, com.webobjects.foundation.NSArray eos, com.webobjects.eocontrol.EOFetchSpecification fs, com.webobjects.eocontrol.EOEditingContext ec)
          Sets the cache entry for the fetched objects and refreshes the timestamps for fetched objects if batch faulting is enabled.
 void databaseContextDidSelectObjects(com.webobjects.eoaccess.EODatabaseContext dc, com.webobjects.eocontrol.EOFetchSpecification fs, com.webobjects.eoaccess.EODatabaseChannel channel)
          This delegate method is called every time a fault is fired that needs to go to the database.
 boolean databaseContextFailedToFetchObject(com.webobjects.eoaccess.EODatabaseContext context, java.lang.Object object, com.webobjects.eocontrol.EOGlobalID gid)
          This is Kelly Hawks' fix for the missing to one relationship.
 com.webobjects.foundation.NSDictionary databaseContextNewPrimaryKey(com.webobjects.eoaccess.EODatabaseContext databaseContext, java.lang.Object object, com.webobjects.eoaccess.EOEntity entity)
          Provides the ability for new enterprise objects that implement the interface ERXGeneratesPrimaryKeyInterface to provide their own primary key dictionary.
 boolean databaseContextShouldFetchArrayFault(com.webobjects.eoaccess.EODatabaseContext dbc, java.lang.Object obj)
          This delegate method first checks the arrayFaultCache if it is set before trying to resolve the fault from the DB.
 boolean databaseContextShouldFetchObjectFault(com.webobjects.eoaccess.EODatabaseContext dbc, java.lang.Object obj)
          Batch fetches to one relationships if enabled.
 com.webobjects.foundation.NSArray databaseContextShouldFetchObjects(com.webobjects.eoaccess.EODatabaseContext dbc, com.webobjects.eocontrol.EOFetchSpecification fs, com.webobjects.eocontrol.EOEditingContext ec)
          Returns an array of already fetched objects or null if they were not already fetched.
 boolean databaseContextShouldHandleDatabaseException(com.webobjects.eoaccess.EODatabaseContext dbc, java.lang.Exception e)
          Allows custom handling of dropped connection exceptions.
 boolean databaseContextShouldHandleDatabaseException(com.webobjects.eoaccess.EODatabaseContext databaseContext, java.lang.Throwable throwable)
          Provides for a hook to get at the original exceptions from the JDBC driver, as opposed to the cooked EOGeneralAdaptorException you get from EOF.
 com.webobjects.foundation.NSArray databaseContextWillPerformAdaptorOperations(com.webobjects.eoaccess.EODatabaseContext dbCtxt, com.webobjects.foundation.NSArray adaptorOps, com.webobjects.eoaccess.EOAdaptorChannel adChannel)
          Overridden to remove inserts and deletes of the "same" row.
static ERXDatabaseContextDelegate defaultDelegate()
          Returns the singleton of the database context delegate
 ERXFetchResultCache fetchResultCache()
           
 void setArrayFaultCache(ERXArrayFaultCache value)
           
 void setBatchHandler(ERXDatabaseContextDelegate.BatchHandler handler)
          Sets the batch handler.
static void setCurrentBatchObjects(com.webobjects.foundation.NSArray arr)
           
static void setDefaultDelegate(ERXDatabaseContextDelegate delegate)
           
 void setFetchResultCache(ERXFetchResultCache value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DatabaseContextFailedToFetchObject

public static final java.lang.String DatabaseContextFailedToFetchObject
See Also:
Constant Field Values

log

public static final org.apache.log4j.Logger log
Basic logging support


dbLog

public static final org.apache.log4j.Logger dbLog
Faulting logging support, logging category: er.transaction.adaptor.FaultFiring


exLog

public static final org.apache.log4j.Logger exLog
Faulting logging support, logging category: er.transaction.adaptor.Exceptions


batchLog

public static final org.apache.log4j.Logger batchLog
Faulting logging support, logging category: er.transaction.adaptor.Batching


autoBatchFetchSize

public static int autoBatchFetchSize
Holds the auto batch fetch size.


THREAD_KEY

public static final java.lang.String THREAD_KEY
Batching thread key

See Also:
Constant Field Values
Constructor Detail

ERXDatabaseContextDelegate

public ERXDatabaseContextDelegate()
Method Detail

defaultDelegate

public static ERXDatabaseContextDelegate defaultDelegate()
Returns the singleton of the database context delegate


setDefaultDelegate

public static void setDefaultDelegate(ERXDatabaseContextDelegate delegate)
Parameters:
delegate - - the singleton database context delegate to set

arrayFaultCache

public ERXArrayFaultCache arrayFaultCache()

setArrayFaultCache

public void setArrayFaultCache(ERXArrayFaultCache value)

fetchResultCache

public ERXFetchResultCache fetchResultCache()

setFetchResultCache

public void setFetchResultCache(ERXFetchResultCache value)

databaseContextShouldFetchObjects

public com.webobjects.foundation.NSArray databaseContextShouldFetchObjects(com.webobjects.eoaccess.EODatabaseContext dbc,
                                                                           com.webobjects.eocontrol.EOFetchSpecification fs,
                                                                           com.webobjects.eocontrol.EOEditingContext ec)
Returns an array of already fetched objects or null if they were not already fetched.

Parameters:
dbc -
fs -
ec -

databaseContextDidFetchObjects

public void databaseContextDidFetchObjects(com.webobjects.eoaccess.EODatabaseContext dbc,
                                           com.webobjects.foundation.NSArray eos,
                                           com.webobjects.eocontrol.EOFetchSpecification fs,
                                           com.webobjects.eocontrol.EOEditingContext ec)
Sets the cache entry for the fetched objects and refreshes the timestamps for fetched objects if batch faulting is enabled.

Parameters:
dbc -
eos -
fs -
ec -

databaseContextShouldHandleDatabaseException

public boolean databaseContextShouldHandleDatabaseException(com.webobjects.eoaccess.EODatabaseContext databaseContext,
                                                            java.lang.Throwable throwable)
Provides for a hook to get at the original exceptions from the JDBC driver, as opposed to the cooked EOGeneralAdaptorException you get from EOF. To see the exceptions trace, set the logger er.transaction.adaptor.Exceptions to DEBUG.

Parameters:
databaseContext -
throwable -

databaseContextNewPrimaryKey

public com.webobjects.foundation.NSDictionary databaseContextNewPrimaryKey(com.webobjects.eoaccess.EODatabaseContext databaseContext,
                                                                           java.lang.Object object,
                                                                           com.webobjects.eoaccess.EOEntity entity)
Provides the ability for new enterprise objects that implement the interface ERXGeneratesPrimaryKeyInterface to provide their own primary key dictionary. If the enterprise object implements the above interface then the method primaryKeyDictionary(true) will be called on the object. If the object returns null then a primary key will be generated for the object in the usual fashion.

Parameters:
databaseContext - databasecontext
object - the new enterprise object
entity - the entity of the object
Returns:
primary key dictionary to be used or null if a primary key should be generated for the object.

databaseContextShouldHandleDatabaseException

public boolean databaseContextShouldHandleDatabaseException(com.webobjects.eoaccess.EODatabaseContext dbc,
                                                            java.lang.Exception e)
                                                     throws java.lang.Throwable
Allows custom handling of dropped connection exceptions. This was needed in WebObjects 4.5 because the OracleEOAdaptor wouldn't correctly handle all exceptions of dropped connections. This may not be needed now.

Parameters:
dbc - current database context
e - throw exception
Returns:
if the exception is one of the bad ones that isn't handled then the method handleDroppedConnection is called directly on the database object of the context and false is returned otherwise true.
Throws:
java.lang.Throwable

databaseContextFailedToFetchObject

public boolean databaseContextFailedToFetchObject(com.webobjects.eoaccess.EODatabaseContext context,
                                                  java.lang.Object object,
                                                  com.webobjects.eocontrol.EOGlobalID gid)
This is Kelly Hawks' fix for the missing to one relationship. Delegate on EODatabaseContext that gets called when a to-one fault cannot find its data in the database. The object that is returned is a cleared fault. We raise here to restore the functionality that existed prior to WebObjects 4.5. Whenever a fault fails for a globalID (i.e. the object is NOT found in the database), we raise an EOObjectNotAvailableException.
If you have entities you don't really care about, you can set the system property er.extensions.ERXDatabaseContextDelegate.tolerantEntityPattern to a regular expression that will be tested against the GID entity name. If it matches, then only an error will be logged but no exception will be thrown.

Parameters:
context - database context
object - object that is firing the fault for a given to-one relationship
gid - global id that wasn't found in the database.

databaseContextDidSelectObjects

public void databaseContextDidSelectObjects(com.webobjects.eoaccess.EODatabaseContext dc,
                                            com.webobjects.eocontrol.EOFetchSpecification fs,
                                            com.webobjects.eoaccess.EODatabaseChannel channel)
This delegate method is called every time a fault is fired that needs to go to the database. All we have added is logging statement of the debug priority. This way during runtime a developer can toggle the logger priority settting on and off to see what faults are firing. Also note that when using ERXPatternLayout one can set the option to see full backtraces to the calling method. With this option specified a developer can see exactly which methods are firing faults.

Parameters:
dc - the databasecontext
fs - the fetchspecification
channel - the databasechannel

databaseContextShouldFetchArrayFault

public boolean databaseContextShouldFetchArrayFault(com.webobjects.eoaccess.EODatabaseContext dbc,
                                                    java.lang.Object obj)
This delegate method first checks the arrayFaultCache if it is set before trying to resolve the fault from the DB. It can be a severe performance optimization depending on your setup. Also, it support batch fetching of to-many relationships of EOs that were fetched at the "same" time.

Parameters:
dbc -
obj -

databaseContextShouldFetchObjectFault

public boolean databaseContextShouldFetchObjectFault(com.webobjects.eoaccess.EODatabaseContext dbc,
                                                     java.lang.Object obj)
Batch fetches to one relationships if enabled.

Parameters:
dbc -
obj -
Returns:
true if the fault should get fetched

databaseContextWillPerformAdaptorOperations

public com.webobjects.foundation.NSArray databaseContextWillPerformAdaptorOperations(com.webobjects.eoaccess.EODatabaseContext dbCtxt,
                                                                                     com.webobjects.foundation.NSArray adaptorOps,
                                                                                     com.webobjects.eoaccess.EOAdaptorChannel adChannel)
Overridden to remove inserts and deletes of the "same" row. When you delete from a join table and then re-add the same object, then the order of operations would be insert, then delete and you will get an error because the delete would try to also delete the newly inserted row. Here we just check every insert and see if the deleted contains the same object. If they do, we just skip both operations,

Parameters:
dbCtxt -
adaptorOps -
adChannel -
Author:
chello team!

autoBatchFetchSize

public static int autoBatchFetchSize()
Returns the batch size for automatic batch faulting from the System property er.extensions.ERXDatabaseContextDelegate.autoBatchFetchSize. Default is 0, meaning it's disabled.

Returns:
batch size

setBatchHandler

public void setBatchHandler(ERXDatabaseContextDelegate.BatchHandler handler)
Sets the batch handler.

Parameters:
handler -

setCurrentBatchObjects

public static void setCurrentBatchObjects(com.webobjects.foundation.NSArray arr)

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.