[ANN] Adaptor Operation Ordering (MSSQL!), SQL Generation Ordering, and Multi-cast Delegates
[ANN] Adaptor Operation Ordering (MSSQL!), SQL Generation Ordering, and Multi-cast Delegates
- Subject: [ANN] Adaptor Operation Ordering (MSSQL!), SQL Generation Ordering, and Multi-cast Delegates
- From: Chuck Hill <email@hidden>
- Date: Thu, 28 Jun 2007 10:29:39 -0700
This is just a summary of changes. Details and usage examples are in
the JavaDocs. The code is part of Project Wonder. I am cross
posting to the WO Dev list as it may be of interest to those who have
still not seen the light.
A word on Wonder. You don't have to marry it. You don't even have
to date it. The new Wonder believes in Free Love. It's downright
promiscuous. You can safely use classes in Wonder without fearing any
interaction with your own code. Unless you set specific
properties**, it is inert. You won't get all the bug fixes and all
the magic, but you will get access to some very handy code. The code
that I am writing about here is part of that code.
1. Adaptor Operation Ordering
OK, so first off database (adaptor / database context) operation
ordering. If you are using a database that supports deferrable
constraints then this is not a issue you need to be concerned with.
Skip down to the multi-cast delegate stuff below. For the rest of
you, I think this may solve the problem once and for all with the
exception of self-referential relationships. I have no idea how to
handle those.
The first class of interest is
er.extensions.eoaccess.entityordering.ERXEntityOrder. This is an
abstract class that builds a dependancy list of entities and provides
NSComparators to sort entities based on this ordering.
This is extended byer.extensions.eoaccess.entityordering.
ERXEntityFKConstraintOrder, which creates an ordering based on
foreign key dependencies. It walks through all the models and looks
at all the relationships to determine this order.
This class is then used by
com.webobjects.eoaccess.ERXEntityDependencyOrderingDelegate to
actually order the operations before they are performed. This is an
EODatabaseContext.Delegate. More on an easy way to use this a bit
later.
2. DROP TABLE Ordering
The second problem that databases without deferrable constraints
have is dropping tables when you want to re-create the database. I
do this several times a day when I am making schema changes. By
default, the DROP TABLE statements are ordered in alphabetical
order. Predictably, this leads to foreign key constraint violations
when the tables are dropped. This needs to be fixed on a database by
database basis by extending the plugin used. I have only fixed it
for MSSQL. Support can easily be added for other databases.
The class that fixes this DROP TABLE ordering problem is
com.webobjects.jdbcadaptor. ERXMicrosoftPlugIn To use this, set the
plugin in Database Config in Entity Modeler to
er.extensions.jdbcadaptor.ERXMicrosoftPlugIn
3. Multiple Delegation
Finally, a problem I have often run into is that WebObject's only
allows a single delegate per delegating class. As this is a common
way to tweak behavior, I often run into the situation where I have
two delegates that I want to use at the same time. But that can't be
done. Until now. To fix this, I created the abstract
er.foundation.ERXDelegateMulticast. ERXDelegateMulticast allows
multiple delegate objects to be aggregated and presented as a single
delegate object. The first, and so far only, concrete class is
er.extensions.eoaccess.ERXMultiDatabaseContextDelegate which wraps
EODatabaseContext.Delegates.
As an example of use and also of use of
ERXEntityDependencyOrderingDelegate:
ERXMultiDatabaseContextDelegate.addDefaultDelegate(new
ERXEntityDependencyOrderingDelegate());
If you also want the ERXDatabaseContextDelegate, just add this :
ERXMultiDatabaseContextDelegate.addDefaultDelegate(new
ERXDatabaseContextDelegate());
There is more to the API, but that should get you started.
Chuck
** If you do want all that Wonder magic and love:
1) extend ERXApplication
2) extend ERXSession
3) use ERXEC.newEditingContext() instead of new EOEditingContext()
4) Add to Properties:
er.extensions.ERXApplication.useEditingContextUnlocker=true
er.extensions.ERXEC.defaultAutomaticLockUnlock=true
er.extensions.ERXEC.useSharedEditingContext=false
er.extensions.ERXEC.defaultCoalesceAutoLocks=true"
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden