Project Wonder 2.0

er.extensions
Class ERXDatabaseContextDelegate

java.lang.Object
  extended byer.extensions.ERXDatabaseContextDelegate

public class ERXDatabaseContextDelegate
extends Object

This delegate implements several methods from the formal interface EODatabaseContext.Delegate. Of special note this class adds the ability for enterpriseobjects 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.


Field Summary
static ERXLogger dbLog
          Faulting logging support, logging category: er.transaction.adaptor.FaultFiring
static ERXLogger exLog
          Faulting logging support, logging category: er.transaction.adaptor.Exceptions
static ERXLogger log
          Basic logging support
 
Constructor Summary
ERXDatabaseContextDelegate()
           
 
Method Summary
 void _configureReadOnly(Connection aConnection)
           
 void _configureReadWrite(Connection aConnection)
           
 Connection _getConnection(EODatabaseContext dbc)
           
 String _readOnlySessionProperties()
           
 String _readWriteSessionProperties()
           
 void databaseContextDidSelectObjects(EODatabaseContext dc, EOFetchSpecification fs, EODatabaseChannel channel)
          This delegate method is called every time a fault is fired that needs to go to the database.
 boolean databaseContextFailedToFetchObject(EODatabaseContext context, Object object, EOGlobalID gid)
          This is Kelly Hawks' fix for the missing to one relationship.
 NSDictionary databaseContextNewPrimaryKey(EODatabaseContext databaseContext, Object object, EOEntity entity)
          Provides the ability for new enterprise objects that implement the interface ERXGeneratesPrimaryKeyInterface to provide their own primary key dictionary.
 boolean databaseContextShouldFetchArrayFault(EODatabaseContext eodatabasecontext, Object obj)
          Delegate method.
 boolean databaseContextShouldFetchObjectFault(EODatabaseContext dbCtxt, Object obj)
          Delegate method.
 NSArray databaseContextShouldFetchObjects(EODatabaseContext dbc, EOFetchSpecification fs, EOEditingContext ec)
          Delegate method.
 boolean databaseContextShouldHandleDatabaseException(EODatabaseContext dbc, Exception e)
          Allows custom handling of dropped connection exceptions.
 boolean databaseContextShouldHandleDatabaseException(EODatabaseContext databaseContext, 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.
 NSArray databaseContextWillPerformAdaptorOperations(EODatabaseContext dbCtxt, NSArray adaptorOps, EOAdaptorChannel adChannel)
          Delegate method.
static ERXDatabaseContextDelegate defaultDelegate()
          Returns the singleton of the database context delegate
 void setReadWriteForConnectionInDatabaseContext(boolean isReadWrite, EODatabaseContext dbc)
          Switch the connection to read/write mode.
 
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
Basic logging support


dbLog

public static final ERXLogger dbLog
Faulting logging support, logging category: er.transaction.adaptor.FaultFiring


exLog

public static final ERXLogger exLog
Faulting logging support, logging category: er.transaction.adaptor.Exceptions

Constructor Detail

ERXDatabaseContextDelegate

public ERXDatabaseContextDelegate()
Method Detail

defaultDelegate

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


databaseContextShouldHandleDatabaseException

public boolean databaseContextShouldHandleDatabaseException(EODatabaseContext databaseContext,
                                                            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, set the logger er.transaction.adaptor.Exceptions to debug.

Parameters:
databaseContext -
throwable -
Returns:

databaseContextNewPrimaryKey

public NSDictionary databaseContextNewPrimaryKey(EODatabaseContext databaseContext,
                                                 Object object,
                                                 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(EODatabaseContext dbc,
                                                            Exception e)
                                                     throws 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:
Throwable

databaseContextFailedToFetchObject

public boolean databaseContextFailedToFetchObject(EODatabaseContext context,
                                                  Object object,
                                                  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.

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(EODatabaseContext dc,
                                            EOFetchSpecification fs,
                                            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

databaseContextWillPerformAdaptorOperations

public NSArray databaseContextWillPerformAdaptorOperations(EODatabaseContext dbCtxt,
                                                           NSArray adaptorOps,
                                                           EOAdaptorChannel adChannel)
Delegate method. Will switch the connection to read write.


databaseContextShouldFetchObjectFault

public boolean databaseContextShouldFetchObjectFault(EODatabaseContext dbCtxt,
                                                     Object obj)
Delegate method. Will switch the connection to read only.


databaseContextShouldFetchArrayFault

public boolean databaseContextShouldFetchArrayFault(EODatabaseContext eodatabasecontext,
                                                    Object obj)
Delegate method. Will switch the connection to read only.


databaseContextShouldFetchObjects

public NSArray databaseContextShouldFetchObjects(EODatabaseContext dbc,
                                                 EOFetchSpecification fs,
                                                 EOEditingContext ec)
Delegate method. Will switch the connection to read only.


setReadWriteForConnectionInDatabaseContext

public void setReadWriteForConnectionInDatabaseContext(boolean isReadWrite,
                                                       EODatabaseContext dbc)
Switch the connection to read/write mode.

Parameters:
isReadWrite - true if the connection should be set to read/write, false if it should be set to read only
dbc - the EODatabaseContext to use to get the java.sql.Connection object FIXME: should support per-model sql statements in order to support different databases

_getConnection

public Connection _getConnection(EODatabaseContext dbc)

_configureReadWrite

public void _configureReadWrite(Connection aConnection)
                         throws SQLException
Throws:
SQLException

_configureReadOnly

public void _configureReadOnly(Connection aConnection)
                        throws SQLException
Throws:
SQLException

_readOnlySessionProperties

public String _readOnlySessionProperties()

_readWriteSessionProperties

public String _readWriteSessionProperties()

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

Copyright © 2002 – 2004 Project Wonder.