Thread: Fw: [Modeling-users] Questions and suggestions
Status: Abandoned
Brought to you by:
sbigaret
From: Ernesto R. <er...@si...> - 2003-06-11 15:16:44
|
Mail I wanted to send to the list instead of sending it directly to Sébastien Erny ----- Original Message ----- From: "Ernesto Revilla" <er...@si...> To: "Sebastien Bigaret" <sbi...@us...> Sent: Tuesday, June 10, 2003 8:09 PM Subject: Re: [Modeling-users] Questions and suggestions Hello again, Inheritance: I'm absolutely astonished. In your example: >>> q = qWQF('toAddresses.zipCode like "4%"') >>> fs = FS('Employee', qualifier=q) >>> fs_deep = FS('Employee', qualifier=q, deepFlag=1) # Note the deepFlag >>> ec.objectsWithFetchSpecification(fs) how this is done at SQL level? Do you execute 3 (one for each subclass of the specified class) SQL queries appending it's result objects to a list? Can you tell us a little bit about your experience, e.g. performance penalties, complications when using inheritance in real world applications? The example you specified (address<<---->employee) is good, could also be: travelling guide, novel, historic novel, etc. to match you book-author example. It would be nice if you could copy and paste it into the inheritance section (quick and dirty), perhaps it could be expanded in the next version. Erny > ----- Original Message ----- > From: "Sebastien Bigaret" <sbi...@us...> > To: "Ernesto Revilla" <er...@si...> > Cc: <mod...@li...> > Sent: Tuesday, June 10, 2003 7:30 PM > Subject: Re: [Modeling-users] Questions and suggestions > > > > Ernesto Revilla <er...@si...> wrote: > > Hi, > > > > for Sebastién: > > * I can only do a comparison matrix with the best-known Python OR-Mappers > > because I haven't done any serious work with them. The major difference is > > that the other ORMs have no query language. In Middlekit, e.g., you can > use > > SQL conditions, but the may not be db-independent. > > Ok. > > > Strange that there is no implementation of OQL. > > Well, it's not *that* known (at least to me;). If you have some good > pointers > for it I'd have a closer look --I've never played with that. > > > To all: > > after working through the docs (v.0.9-pre7) (still didn't try the package) > > here are some > > points: > > > > * Dependencies: The PyPgSQL and PyGreSQL names are interchanged. Also, > > should be pypgsql > > Yes, this has been changed with 0.9pre8 --hopefully this is now okay. If you > find more occurences of such errors, please report again. > > > * What functions are used from 4Suite? (It's 6MB to download for Windows.) > > Isn't it enough to use PyXML? > > Yes it is! 0.9pre8 removed 4Suite from its dependencies --but I forgot to > include that in the announcement. > > > * Installation is a bit complicated, because of the dependencies. What > > chances are there to create a complete install file (perhaps excluding > > db-adaptors) for some of the mile-stone versions? > > There are some chances, if only I could find a script we formerly used to > install the whole stuff. Maybe some of us here still have it at hand? (hey, > these ones know who they are ;) > > > > * Although the inheritance mapping is described, I can't see out of the > docs > > if a relations may map to different tables (say Animals and Humans). This > is > > because the class has to be stored with the foreign key. (See ids.) > > > > About ids and inheritance: > > * Would it be a good idea to specify all object pointers as type ObjectId > in > > the XML-Model file and tell how this is mapped to the DB in the adaptor? > > (integer is enough?) > > > > * May be ObjectIds should be unique throughout the database? (A seperate > > procedure would dispatch new objectids, using some high:low algorithm.) > See > > next point. Also good for replication. > > > > * Either the foreign class (id) has to be stored with each foreign key, or > > the object id contains the class id as part of it (MiddleKit does this). > > > > * How would this be treated in queries? Would a query return objects of > > several tables? (This may require extra queries. A simple INNER JOIN > > wouldn't do it.) > > > > Inheritance makes it real complicated, and in practice, may not be so > > important, depending on the object-model design. > > I'm not sure to fully understand what you mean here, pardon me if my answer > is > off-topic. > > 1. If you're looking for an 'ObjectId', globalID() is for you. A GlobalID > uniquely identifies an object. You can get it with > ec.globalIDForObject(object) > > It answers to: entityName() (mapped to a class in the model) > keyValues (dictionary with pks as keys and their > corresponding values) > > In particular, if two different objects refer to the same row in the > database, they have the same GlobalID. > > 2. Suppose you have the following model: > > Address <<-toAddresses---toEmployee-> Employee > ^ > / \ > T > | > +--------------+ > | | > Executive SalesClerk > > * An address object can be linked to either an Employee, an Executive > or > a SalesClerk instance > > * An address.toEmployee() will retrieve the right object (being an > instances of one of those three classes) > > * when fetching, you can specify whether you want to fetch a single > class or its inheritance tree as well. Compare this, based on the > test > database and model StoreEmployees: > > >>> from StoreEmployees import Address > >>> from Modeling.FetchSpecification import FetchSpecification as FS > >>> from Modeling.EditingContext import EditingContext as EC > >>> from Modeling.Qualifier import qualifierWithQualifierFormat as qWQF > >>> > >>> ec = EC() > >>> q = qWQF('toAddresses.zipCode like "4%"') > >>> fs = FS('Employee', qualifier=q) > >>> fs_deep = FS('Employee', qualifier=q, deepFlag=1) # Note the deepFlag > >>> ec.objectsWithFetchSpecification(fs) > [] > >>> [(o.getFirstName(),o.getLastName()) > ... for o in ec.objectsWithFetchSpecification(fs_deep)] > [('John Jr.', 'Cleese'), ('Jeanne', 'Cleese'), ('John', 'Cleese')] > > > So the answer to your question: > > > * How would this be treated in queries? Would a query return objects of > > several tables? (This may require extra queries. A simple INNER JOIN > > wouldn't do it.) > > is clearly yes! > > However you're right, the documentation lacks even a basic example and > explanantions for this. Does this answers your questions? Feel free to ask > for more. > > -- Sébastien. > > > |
From: Sebastien B. <sbi...@us...> - 2003-06-12 00:16:06
|
Ernesto Revilla <er...@si...> wrote: > Inheritance: >=20 > I'm absolutely astonished. In your example: >=20 > >>> q =3D qWQF('toAddresses.zipCode like "4%"') > >>> fs =3D FS('Employee', qualifier=3Dq) > >>> fs_deep =3D FS('Employee', qualifier=3Dq, deepFlag=3D1) # Note the de= epFlag > >>> ec.objectsWithFetchSpecification(fs) >=20 > how this is done at SQL level? Do you execute 3 (one for each subclass of > the specified class) SQL queries appending it's result objects to a list? That's exactly the way this is done: any deep fetch is made against the whole inheritance hierarchy below the specified entity (here, Employee) --this is DatabaseContext's responsability, you can have a look at objectsWithFetchSpecification(). This is the reason why the PK automatic generation support only uses one source per inheritance tree, either a sequence (postgresql) or a dedicated table (mysql, sqlite): this is required if we want that a relationship points to different rows in different tables. > Can you tell us a little bit about your experience, e.g. performance > penalties, complications when using inheritance in real world application= s? Performance penalty: mostly what you would expect, i.e. as many fetchs as there are classes in the inheritance tree below a given entity. Not that big since in any case you'll have to do this by hand if it was not automatically handled. However the framework does not stop after finding the first row/object. The reason for this is that if it can find more than an object for a given GlobalID that's a serious error, at least at the framework's eyes, and this error should not be hidden. So all fetchs are executed --whatever their result. But unless your inheritance tree is really big, some additional fetchs returning no row have no significant impact. Complications in real world applications: I can't think of any complications :) If you think reliability: inheritance support is used in two important projects I know, it has been extensively used and tested for months. Okay, sometimes it happens that you just want A in relation with B, not with any of B's subentities: in such a case, you'll have to deal with the extra fetchs the framework makes (there's no way to express this in a model, but this can be enforced by custom business-logic validation), but again that's no big deal unless you have a big inheritance hierarchy. BTW: you can see the exact SQL statements that the framework executes by setting the environment varibale MDL_ENABLE_DATABASE_LOGGING to any value (except non-empty string). > The example you specified (address<<---->employee) is good, could also be: > travelling guide, novel, historic novel, etc. to match you book-author > example. It would be nice if you could copy and paste it into the > inheritance section (quick and dirty), perhaps it could be expanded in the > next version. You're right here, I realize this section definitely needs to be written, and a raw copy/paste or a summary of this thread should be sufficient for a first draft; I'll do this for the next release. Deriving the book/author model with travelling guides, novels etc. is also a good idea --I might reuse it in the coming tutorial (I was looking for a better model than store/employee to demonstrate inheritance, and this one looks actually better ;) -- S=E9bastien. |