a trick to model a complex derived relationship?
a trick to model a complex derived relationship?
- Subject: a trick to model a complex derived relationship?
- From: "ocs.cz" <email@hidden>
- Date: Tue, 01 Mar 2016 20:25:20 +0100
Hello there,
in my code, there is a number of “derived relationships”, defined by Java code at the EO class level. It works well for years, but now (as part of the “import another application's database” task I am working on) I would need to move the behaviour to the model level, so that I can fetch the data as raw rows into another, essentially unrelated application.
For example, in my application Auction.woa, there is a DBAuction entity; in its code, there is (essentially) this derived relationship:
===
DBUser auctionOwner() {
for (DBUserAccess ua in userAccess()) // userAccess is a 1:N relationship from this to DBUserAccess
if (ua.accessAllowed()) { // accessAllowed is a boolean attribute of DBUserAccess
DBUser user=ua.user() // user is an N:1 relationship from DBUserAccess to DBUser
if (user.userType()00==USER_TYPE_OWNER) // userType is an integer attribute of DBUser; USER_TYPE_OWNER a constant
return user
}
return null
}
===
Now, the problem is that I would need to fetch data _as raw rows_ through this relationship into _another application_, say, AuctionImporter.woa, where none of the entities exist. (Even if I copied the entities there, it would not help with fetching raw rows.)
For modelled attributes and relationships I have solved the problem by creating a copy of the Auction model in my AuctionImporter.woa application, having turned all the model classes to EOGenericRecords. That allows me to fetch raw rows based on all modelled attributes (and flattened attributes through modelled :1 relationships) all right: done, tested, works like a charm.
Now, though, I bumped into a need to fetch raw rows based on these complex “derived” relationships; e.g., I would need to be able to do in AuctionImporter.woa something like
===
def fs=new EOFetchSpecification("DBAuction",null,null) // DBAuction entity from the copy of the original model
fs.fetchesRawRows=YES
fs.rawRowKeyPaths=['auctionOwner_login', ... normal modelled (potentially flattened) attribs, no problem with them ...]
def result=new ERXEC().objectsWithFetchSpecification(fs)
===
Is there a trick to define at the model level a “derived relationship“ auctionOwner, simulating somehow the behaviour described above, through which I then would be able to flatten the desired attribute (with a definition "auctionOwner.login")?
If this is not possible, it seems to me I would have to generate the complete fetch SQL myself, essentially without any help of EOF, and then fetch using EOUtilities.rawRowsForSQL. Ick. That can get pretty complex pretty quickly[*], and thus I would rather like to dodge it, if possible. Can you see any easier way to do this?
Thanks for any advice,
OC
[*] Originally, I have considered it for attributes flattened through modelled relationships, too. It quickly proved _much_ easier to add appropriate flattened attributes to the model (syncing appropriately to make sure model never gets changed by one thread and accessed by another at the same time), and let EOF to generate the SQL for me :)
_______________________________________________
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