Re: [Modeling-users] How the transactions are done in the saveChanges?
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2004-08-12 22:26:02
|
Marco Bizzarri wrote: > Hi all. > > I'm experimenting with ModelingFramework, and I've some questions. > > I've tried the sample model in from the website, and I've analyzed the > database logs. I've noticed that the ec.saveChanges() in the model is > composed of 5 transactions: the first 4 transactions get the key > numbers from the sequence, the last one is the transaction actually > doing the work. > > Is this a correct behaviour? What are the reasons behind it? The first 4 transactions get the PK value from the sequence; in fact, you'll notice that there are as many transactions for obtaining PK values as there are newly inserted objects that will be saved. Is this correct? It is, even if it's inefficient --this is a TODO item, PKs values could be obtained in a single roundtrip to the database! By the way, the PK values are obtained before any change is saved, just because saving changes requires that those PKs values are known (because of relationships). Now if ec.saveChanges() fails, those PKs values won't be used, ever. So, in theory, there are two transactions, one for obtaining the new primary keys values (in practice you get N transactions there), the other one for actually saving the changes. BTW: if you set the env. variable 'MDL_ENABLE_DATABASE_LOGGING' then you'll get a copy of the framework db-related actions on stderr (or anywhere else if you modify Modeling.logging) --see the appropriate annex in the User's Guide. > Also, I've noticed that the ec.fetch() is a transaction which > terminates with an abort. Is this correct? This is intentional, anyhow ;) Such a transaction should be terminated, and I cannot see any reason why it should be COMMITed, hence it is ABORTed! But if you think differently, please let us know! > I've not yet experimented with Zope. I see I can connect the > ec.saveChanges() to the transactions machinery in Zope. Some > questions: > > 1) how many db transaction are done for each saveChanges (i.e. same as > above?) Yes. > 2) how are the db transaction executed/completed inside a Zope > transaction? In a non-zope application, I can see each fetch() > produces a transaction, as well as the ec.saveChanges(). Is this true > also in Zope applications? Yes it is. The zope support basically consists in providing a default EditingContext per session, possibly also connecting this EC's saveChanges() to the transaction machinery (i.e. to each request/response loop). That's all, and everything else will be handled in your ZProducts' code, just the same way you would make it in pure python. Hope this helps, -- Sébastien. |