Re: Dynamically altering external names for Entities (solution)
Mark Morris <[email protected]> Mon, 12 May 2003 13:22:54 -0500
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <[email protected]> |
Thanks for the help. After looking into it some more, I don't think in my case I'll need the flexibility offered by Eric's suggestion, as my requirements are a bit more bounded. Here's my (mostly tested) plan, which basically alters the SQL just before it gets executed:
In the Application constructor, I'll go through each EOModel in the default EOModelGroup. If an entity has a specific userInfo key set, I'll replace the variable portion of the external name with a placeholder string I'm certain won't be in a real table name.
In the Session constructor, I'll instantiate a delegate for EOAdaptorChannel, implementing adaptorChannelShouldEvaluateExpression. I'll register for the EODatabaseContext.DatabaseChannelNeededNotification, so I can set the delegate for any channels that might get created.
My delegate method will just be:
public boolean adaptorChannelShouldEvaluateExpression(
EOAdaptorChannel channel, EOSQLExpression expression ) {
String statement = expression.statement().replaceAll( placeHolderString, tableNameSuffix );
expression.setStatement( statement );
return true;
}
I'll have a Session method that will update the "tableNameSuffix" (and invalidate all objects).
In limited testing, this seems to do what I want, which is to just model one "set" of all the repeating entities, and allow me to deal with them one "set" at a time. Please let me know if anyone see's any potential gotchas in this approach. ;-)
Thanks for the input!
-- Mark