modeling-users Mailing List for Object-Relational Bridge for python (Page 7)
Status: Abandoned
Brought to you by:
sbigaret
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(3) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(19) |
Feb
(55) |
Mar
(54) |
Apr
(48) |
May
(41) |
Jun
(40) |
Jul
(156) |
Aug
(56) |
Sep
(90) |
Oct
(14) |
Nov
(41) |
Dec
(32) |
2004 |
Jan
(6) |
Feb
(57) |
Mar
(38) |
Apr
(23) |
May
(3) |
Jun
(40) |
Jul
(39) |
Aug
(82) |
Sep
(31) |
Oct
(14) |
Nov
|
Dec
(9) |
2005 |
Jan
|
Feb
(4) |
Mar
(13) |
Apr
|
May
(5) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2006 |
Jan
(1) |
Feb
(1) |
Mar
(9) |
Apr
(1) |
May
|
Jun
(1) |
Jul
(5) |
Aug
|
Sep
(5) |
Oct
(1) |
Nov
|
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(1) |
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Marco B. <m.b...@ic...> - 2004-08-13 07:49:44
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sebastien Bigaret wrote: ... | | 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. | Ok, I will take a look |>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! | One of the basic reason for this is in the debugging/maintenance of the system. When you need to look for the DB log, it is useful to spot the problems by mean of ABORTed transactions. If the aborted transactions are the standard, this can be a problem. | |>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. Yes and no... I would prefer to be able to tell ModelingFramework when it should start/stop a transaction on the db... howevr, thanks of the answer... -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBHHJxXhfyAQQVoaIRAogVAKC4xp1v+Ttxp6wmjxWotOpYPtvq6gCdHIyC ric78zFY9j+Ifbc5eoVMilE= =hFeZ -----END PGP SIGNATURE----- |
From: Sebastien B. <sbi...@us...> - 2004-08-12 22:32:27
|
Kertis, Dennis wrote: > Is there a way I can get a field populated with an aggregate value. > i.e., I want a manager to have a field which would contain how many > employees work for him by doing a select count(*). I parsed through > the fetching section of the doc and didn't find a way to do this. For COUNT(*) there is a dedicated method: EC.fetchCount(), which has the very same syntax as EC.fetch() and returns the number of objects matching the qualifier. I recommend that you define a method returning this count, rather than have an integer field populated with such a value, or else you should be prepared to deal with every possible situations where this count can change if you do not want that this field's value get out of sync. Other aggregates are not yet supported; I believe we formerly discussed this here, probably with Ernesto, among others. I do not have access to the archives here, Erny could you maybe confirm? -- Sébastien. |
From: Sebastien B. <sbi...@us...> - 2004-08-12 22:29:59
|
Lorenzo Gil Sanchez wrote: > Hi all, > > I'm finding some problems when creating a PyModel: > > model.addEntity(my_entity) does nothing but > model.entities.append(my_entitye) works > > This is not really important and I guess it's easy to fix. Probably easy to fix, yes, I'll check that, thanks for reporting. > The next problem is more important: > > model.build > defaultModelSet().addModel(model) > > fails with this exception: [...] > defaultModelSet().addModel(model.component) > works without a warning but I'm not sure if this is the preferred way > of adding a model to the modelset. Yes, this is a known bug, ModelSet.addModel() (and other methods in ModelSet as well) only accepts Modeling.Model objects, not PyModels. In the meantime, adding the PyModel.component is the correct workaround. -- Sébastien. |
From: Sebastien B. <sbi...@us...> - 2004-08-12 22:28:03
|
Oh well, sorry, I'm sure it's not the first time it's been reported but left uncorrected, isn't it? co...@sa... wrote: > I've looked into CustomObject.py, and i could'nt find any assigment of > REAL editing, context, only initial definition 'lambda self: None' > Did i misunderstood something, or this example code in User's guide > is > just out-dated? With Erny's correction this should work. And about CustomObject.editingContext(): it's assigned whenever the object is inserted or fetched within an EC. -- Sébastien. Ernesto Revilla wrote: > > Hi, > > You have to add the instance to both sides of the relation, the > a.setPerson(p) > > is missing. > > To add an instance to both sides of a relation, you can do also: > > p.addObjectToBothSidesOfRelationshipWithKey(a, addresses) > > Erny > > > co...@sa... escribió: > > >Hello, > > > >First of all thanks to Sabastien for his efforts creating this > framework. > >Projects I'm involved now requires lots of Many-To-Many relations in > E-R > >model, so I've tried adding methods (for tranparent access to > correlation > >entity) as described in the example in UsersGuide 2.6.3. But those > methods > >doesn't work. So I've copy-pasted example from user's guide, but it > did'nt > >work as well.: > >i.e I add methods getAddresses(), addToAddresses() > >to the class "Person", Then I try to run a code, that uses those > classes: > >------------- > >#test.py > >from Modeling.EditingContext import EditingContext > >from MM1 import Person, Address > >ec=EditingContext() > >p = Person.Person() > >a = Address.Address() > >p.addToAddresses(a) > >ec.insert(p) > >ec.insert(a) > >ec.saveChanges() > >----------------- > >I get an error: > >Traceback (most recent call last): > > File "./test.py", line 8, in ? > > p.addToAddresses(a) > > File "/tmp/test2/MM1/Person.py", line 76, in addToAddresses > > self.editingContext().insert(_pa) > >AttributeError: 'NoneType' object has no attribute 'insert' > >----------------- > >I've looked into CustomObject.py, and i could'nt find any assigment > of > >REAL editing, context, only initial definition 'lambda self: None' > >Did i misunderstood something, or this example code in User's guide > is > >just out-dated? > > > >Can someone please give me some guidlines? > > > >I'm using: Python 2.3, Modeling: 0.9-pre-17.1 |
From: Sebastien B. <sbi...@us...> - 2004-08-12 22:27:19
|
Mario Ruggier wrote: [...] > Another situation in which this could apply is for migrating from one > db+model to another... a little modeling mapping code could read from > one EC and populate another that uses a modified model. This may not > be the most efficient to way to do this, but possibly the most > flexible and one that would guarantee data integrity and consistency > the most. Any opinions on whether this would be a good idea or not? I'm sure we've played with that idea some day in the past, if I remember well it was probably with Yannick Gingras (I can't check the archives right now). The problem is that, while this sounds interesting, this could probably only be done with small databases --because, unless we want to automatically analyse a model in detail, handling relationships will end up in loading a whole database in memory. Moreover, I'm convinced that it will be difficult to cover every transformations. But I can be proved wrong! -- Sébastien. |
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. |
From: Sebastien B. <sbi...@us...> - 2004-08-12 22:24:39
|
Ernesto Revilla wrote: > Dear all, > > just a question: can't I fetch objects by attribute access, without > having used ec.saveChanges first? See the last 4 lines of the > following source code. What restrictions exist using fetch, in respect > with ec.saveChanges? > > Thanx, > Erny [example snipped] To be perfectly clear: there should not exist such a restriction. I'm currently away from any development environment, with an access to my emails but that's all, so I'm not able to check and diagnose this. You have found a bug for sure --even if, for now, I cannot be completely positive about the fact that it can be easily solved. Anyhow, thanks for reporting! may I ask you to fill a bug report? I'll get back to you next week (I can't say exactly when, I'll be extremely busy for the 10 coming days). In case you're in a hurry, you may want to check this by yourself by checking EditingContext.fetch(): at the end of it, it applies the qualifier (here, 'reservations.startDay like "2004-08-09*"') to its inserted objects of the correct type/entity. I suspect that you get no objects because the 'like' operator tries to compare a string to a Date object, which obviously never selects any object. If this is the case, then the solution is probably to check the type of the destination attribute (startDay), and, if it is a date, then adjust the qualifier's value accordingly (may be changing the operator from 'like' to 'between'); or an other (more efficient?) solution could be to compare the string with the string representation of the attribute's value... but this would add the constraint that such a string representation should be the same than the database's representation for dates... Oh well, anyhow, you get the idea, don't you?-) I'm pretty confident that the bug is only triggered with attributes whose type is Date. -- Sébastien. |
From: Sebastien B. <sbi...@us...> - 2004-08-12 22:23:13
|
Delio Brignoli in...@dr... wrote: > Sebastien Bigaret <sbi...@us...> wrote: > > Without more details, I guess you intend to do some load-balancing > > between db-instances in aread-only app., right? > > not at this stage, load balancing if further down the track, now we > need to access several DBs with the same schema, it is a requirement > that each customer has is own separate database instance; fixing one > fixes the other as well. Oh oh, so this is something completely different than what I initially had in mind. If I understand you right, you have a reference model, something like a template model, that you want to use for every customer account. Each one will get its own model, say a copy of the reference model, that it should use to access its data in a separate database. But since in the framework, entities' names share a single namespace, you won't be able to load two different models with entities having the same name in the same process. What seems to be a serious problem at first sight also suggests that there exists a possible and easy solution. Say your reference model contains one entity 'Document', then for each account 'login', you can create a model named e.g. 'model_login', containing the entity 'Document_login'. This way you'll be able to dynamically create the models, create or destroy the dedicated databases from them (see the script mdl_generate_db_schema.py for details on how this can be done), and access each account's data in a dedicated database (since every 'model_login' will get its own connection dictionary, as expected). [...] > My knowledge of the framework is limited, I literaly unpacked the > source less than 24 hours ago, ported some of our biz object, logic > and have one test from the test suit succesfully complete (by the way, > being able to express the model in python made my life easier) (in > case you are interested I tried the dynamic metaclass based approach > first but I'd get an exception when populating the class as soon as I > defined an __init__ method: check_old_init method tried to len() args > but python chocked ;) ) ... I'm interested, if you could supply a simple example and fill a bug report @sf.net that would help a lot ;) > but back to the issue, > I'll look into the framework more to understand exactly what it's > involved in adding this feature and since I can already hear my boss > asking it, I'll ask you straight away how much it would cost to > contract you to add this feature (and how long it would take). Hopefully the solution exposed above can make it; if not, then do not hesitate to get back to me! Oh, but wait... sorry, I didn't realize you sent an other email with more informations: > What I want to achieve: > > When I create an EC, I'd like to pass the ID string as a parameter and > this should give me an EC that works 'like' a plain old connection to > the mapped database instance. > > How to get there: > > - change the mapping into: ID -> ( connection params, model ) > ?- subclass EC to support the ID string be passed on __init__ > ?- subclass ObjectStoreCoordinator to use the ID string information in > EC to create/select a proper DatabaseContext. > ?- at which level caches work in modeling: I obviously don't want rows > from different database instances to mixup :-P Okay, so good news, we're definitely talking about the same thing ;) So what you need to do is: use the 'ID' (login e.g.) to dynamically build (or load or...) the corresponding model 'model_ID', use the correct entity in this model e.g. 'Document_ID' when fetching objects for example, and use the correct class (that you'd probably want to dynamic.build...() from the model) to build new objects --this way they get automatically inserted into the right table in the right database (look in class ClassDescription or EntityClassDescription for a method automatically building the right object of the right class given its entity). I think this makes everything work the way you want; and obviously you won't run into any cache trouble or so, since you're just using different models, that all! What do you think? -- Sébastien. |
From: Kertis, D. <dk...@vo...> - 2004-08-12 17:29:15
|
Is there a way I can get a field populated with an aggregate value. i.e., I want a manager to have a field which would contain how many employees work for him by doing a select count(*). I parsed through the fetching section of the doc and didn't find a way to do this. |
From: Lorenzo G. S. <lg...@si...> - 2004-08-11 16:35:20
|
Hi all, I'm finding some problems when creating a PyModel: model.addEntity(my_entity) does nothing but model.entities.append(my_entitye) works This is not really important and I guess it's easy to fix. The next problem is more important: model.build defaultModelSet().addModel(model) fails with this exception: File "/home/lgs/proyectos/gruppy/middletier/DOF/m/DomainObjectFramework.py", line 40, in __init__ defaultModelSet().addModel(model) File "/opt//lib/python2.3/site-packages/Modeling/ModelSet.py", line 138, in addModel if aModel.name() in self.modelsNames(): TypeError: 'str' object is not callable defaultModelSet().addModel(model.component) works without a warning but I'm not sure if this is the preferred way of adding a model to the modelset. Cheers Lorenzo Gil Sanchez |
From: Lorenzo G. S. <lg...@si...> - 2004-08-11 16:35:20
|
Hi all, I'm finding some problems when creating a PyModel: model.addEntity(my_entity) does nothing but model.entities.append(my_entitye) works This is not really important and I guess it's easy to fix. The next problem is more important: model.build defaultModelSet().addModel(model) fails with this exception: File "/home/lgs/proyectos/gruppy/middletier/DOF/m/DomainObjectFramework.py", line 40, in __init__ defaultModelSet().addModel(model) File "/opt//lib/python2.3/site-packages/Modeling/ModelSet.py", line 138, in addModel if aModel.name() in self.modelsNames(): TypeError: 'str' object is not callable defaultModelSet().addModel(model.component) works without a warning but I'm not sure if this is the preferred way of adding a model to the modelset. Cheers Lorenzo Gil Sanchez |
From: Marco B. <m.b...@ic...> - 2004-08-10 18:24:05
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 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? Also, I've noticed that the ec.fetch() is a transaction which terminates with an abort. Is this correct? 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?) 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? Thanks for the support. Regards Marco -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBGRKfXhfyAQQVoaIRApwhAJ4gN0VvFmGwjVMGbcWPNJX8//7UuwCfWz23 ms4DuwY4buaqGurMlFB2yYg= =fnEH -----END PGP SIGNATURE----- |
From: Ernesto R. <er...@si...> - 2004-08-10 16:31:03
|
Dear all, just a question: can't I fetch objects by attribute access, without having used ec.saveChanges first? See the last 4 lines of the following source code. What restrictions exist using fetch, in respect with ec.saveChanges? Thanx, Erny """ A simple model +-------+ 1 0,* +--------+ 1 0,* +-------------+ | Hotel |<-hotel------rooms->>| Room |<-room-----reservations->>| Reservation | +-------+ nullify cascade +--------+ nullify cascade +-------------+ | name | | number | | startDay | +-------+ +--------+ | endDay | +-------------+ """ from Modeling.PyModel import * # valores por defecto para el modelo Attribute.defaults['usedForLocking']=1 AString.defaults['externalType']='TEXT' AString.defaults['width'] = 0 AString.defaults['usedForLocking']=1 Association.defaults['delete']=['nullify', 'nullify'] Entity.defaults['properties'] = [ APrimaryKey('id', isClassProperty=0, isRequired=1, doc='PK') ] _connDict = {'database': 'reservations.sqlite'} model = Model('Reservations',adaptorName='SQLite', connDict=_connDict, version='0.1') model.doc=__doc__ model.entities = [ Entity('Hotel', properties=[ AString('name', isRequired=1), ], ), Entity('Room', properties=[ AInteger('number', isRequired=1), ] ), Entity('Reservation', properties=[ ADateTime('startDay', isRequired=1), ADateTime('endDay', isRequired=1), ] ), ] # Associations will allways be defined towards the 'one' part. model.associations = [ Association('Reservation', 'Room', relations=['room','reservations'], multiplicity=[ [1, 1] , [0, None] ], delete=['nullify','cascade']), Association('Room', 'Hotel', relations=['hotel','rooms'], multiplicity=[ [1, 1] , [0, None] ], delete=['nullify','deny']), ] model.build() def test(): from Modeling.EditingContext import EditingContext from mx.DateTime import Date, Time from Reservations.Hotel import Hotel from Reservations.Room import Room from Reservations.Reservation import Reservation ec=EditingContext() h=ec.fetch('Hotel','name == "Ritz"') #!!! tiene q ser "Ritz" no 'Ritz' if not h: h=Hotel(name="Ritz"); ec.insert(h) ec.saveChanges() else: h=h[0] r=ec.fetch('Room','number == 101') if not r: r=Room(number=101); ec.insert(r) r.setHotel(h) ec.saveChanges() else: r=r[0] res=Reservation() ec.insert(res) res.setRoom(r); r.addToReservations(res) res.setStartDay(Date(2004,8,9)); res.setEndDay(Date(2004,8,14)) # ec.saveChanges() ## This does return an instance in each case res=ec.fetch("Reservation",'startDay like "2004-08-09*"') print "res normal fetch:",res ## !!! without ec.saveChanges this does return None !!! res=ec.fetch("Room",'reservations.startDay like "2004-08-09*"') print "res fetch with attribute traversal:",res --- avast! Antivirus: Saliente mensaje limpio. Base de datos de Virus (VPS): 0433-1, 09/08/2004 Comprobado en: 10/08/2004 18:30:15 avast! tiene los derechos reservados (c) 2000-2004 ALWIL Software. http://www.avast.com |
From: Ernesto R. <er...@si...> - 2004-08-10 16:10:37
|
Hi, You have to add the instance to both sides of the relation, the a.setPerson(p) is missing. To add an instance to both sides of a relation, you can do also: p.addObjectToBothSidesOfRelationshipWithKey(a, ’addresses’) Erny co...@sa... escribió: >Hello, > >First of all thanks to Sabastien for his efforts creating this framework. >Projects I'm involved now requires lots of Many-To-Many relations in E-R >model, so I've tried adding methods (for tranparent access to correlation >entity) as described in the example in UsersGuide 2.6.3. But those methods >doesn't work. So I've copy-pasted example from user's guide, but it did'nt >work as well.: >i.e I add methods getAddresses(), addToAddresses() >to the class "Person", Then I try to run a code, that uses those classes: >------------- >#test.py >from Modeling.EditingContext import EditingContext >from MM1 import Person, Address >ec=EditingContext() >p = Person.Person() >a = Address.Address() >p.addToAddresses(a) >ec.insert(p) >ec.insert(a) >ec.saveChanges() >----------------- >I get an error: >Traceback (most recent call last): > File "./test.py", line 8, in ? > p.addToAddresses(a) > File "/tmp/test2/MM1/Person.py", line 76, in addToAddresses > self.editingContext().insert(_pa) >AttributeError: 'NoneType' object has no attribute 'insert' >----------------- >I've looked into CustomObject.py, and i could'nt find any assigment of >REAL editing, context, only initial definition 'lambda self: None' >Did i misunderstood something, or this example code in User's guide is >just out-dated? > >Can someone please give me some guidlines? > >I'm using: Python 2.3, Modeling: 0.9-pre-17.1 > > > > > >------------------------------------------------------- >SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media >100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 >Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. >http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 >_______________________________________________ >Modeling-users mailing list >Mod...@li... >https://lists.sourceforge.net/lists/listinfo/modeling-users > > > --- avast! Antivirus: Saliente mensaje limpio. Base de datos de Virus (VPS): 0433-1, 09/08/2004 Comprobado en: 10/08/2004 18:09:47 avast! tiene los derechos reservados (c) 2000-2004 ALWIL Software. http://www.avast.com |
From: <co...@sa...> - 2004-08-10 12:54:35
|
Hello, First of all thanks to Sabastien for his efforts creating this framework. Projects I'm involved now requires lots of Many-To-Many relations in E-R model, so I've tried adding methods (for tranparent access to correlation entity) as described in the example in UsersGuide 2.6.3. But those methods doesn't work. So I've copy-pasted example from user's guide, but it did'nt work as well.: i.e I add methods getAddresses(), addToAddresses() to the class "Person", Then I try to run a code, that uses those classes: ------------- #test.py from Modeling.EditingContext import EditingContext from MM1 import Person, Address ec=EditingContext() p = Person.Person() a = Address.Address() p.addToAddresses(a) ec.insert(p) ec.insert(a) ec.saveChanges() ----------------- I get an error: Traceback (most recent call last): File "./test.py", line 8, in ? p.addToAddresses(a) File "/tmp/test2/MM1/Person.py", line 76, in addToAddresses self.editingContext().insert(_pa) AttributeError: 'NoneType' object has no attribute 'insert' ----------------- I've looked into CustomObject.py, and i could'nt find any assigment of REAL editing, context, only initial definition 'lambda self: None' Did i misunderstood something, or this example code in User's guide is just out-dated? Can someone please give me some guidlines? I'm using: Python 2.3, Modeling: 0.9-pre-17.1 |
From: Mario R. <ma...@ru...> - 2004-08-10 10:35:20
|
On Aug 10, 2004, at 7:47 AM, Sebastien Bigaret wrote: > Delio Brignoli <in...@dr...> wrote: >> Hello, >> >> I'm evaluating the use of modeling for our new project(s) and was >> wondering if some of you could give me pointers on how to access >> multiple database instances of the same model in the same >> application. (I understand that each database instance will be >> isolated and don't expect to insert object from an objectStore into >> another) After creating my first model definition and 30 minutes dive >> in the docs, it seems I'll have to create an EC passing a 'properly >> crafted' :-) ObjectStore instance. Am I on the right track? > > Without more details, I guess you intend to do some load-balancing > between db-instances in aread-only app., right? Another situation in which this could apply is for migrating from one db+model to another... a little modeling mapping code could read from one EC and populate another that uses a modified model. This may not be the most efficient to way to do this, but possibly the most flexible and one that would guarantee data integrity and consistency the most. Any opinions on whether this would be a good idea or not? mario |
From: Delio B. <in...@dr...> - 2004-08-10 09:17:17
|
On 10 Aug 2004 07:47:43 +0200 Sebastien Bigaret <sbi...@us...> wrote: Hi, I realized I wrote my first reply in a hurry so I'm writing this up to give you more info on what I want to achieve so you can have a better idea of what's involved. The application runs in a multithreaded application server, a client to database instance mapping is done by the application already ( in its first incarnation it was accessing the DB (almost-)directly ) let's say that we have a mapping between an ID string and a database connection string. These are my ideas and the may not play well with the way modeling is designed, but I hope will be a starting point. What I want to achieve: When I create an EC, I'd like to pass the ID string as a parameter and this should give me an EC that works 'like' a plain old connection to the mapped database instance. How to get there: - change the mapping into: ID -> ( connection params, model ) ?- subclass EC to support the ID string be passed on __init__ ?- subclass ObjectStoreCoordinator to use the ID string information in EC to create/select a proper DatabaseContext. ?- at which level caches work in modeling: I obviously don't want rows from different database instances to mixup :-P regards -- Delio |
From: Sebastien B. <sbi...@us...> - 2004-08-10 05:47:38
|
Hi, Delio Brignoli <in...@dr...> wrote: > Hello, >=20 > I'm evaluating the use of modeling for our new project(s) and was > wondering if some of you could give me pointers on how to access > multiple database instances of the same model in the same > application. (I understand that each database instance will be > isolated and don't expect to insert object from an objectStore into > another) After creating my first model definition and 30 minutes dive > in the docs, it seems I'll have to create an EC passing a 'properly > crafted' :-) ObjectStore instance. Am I on the right track? Without more details, I guess you intend to do some load-balancing between = db-instances in aread-only app., right? First, if you want to do that in different processes, simply change the model's connection dictionary before using it; each process will then use its own db instance. Regarding EC(parentObjectStore): it's usually used to make child ECs; passing it a dedicated ObjectStore is completely untested. But you're on the right track: you can either give it a dedicated DBContext, or use the default behaviour (which assigns a ObjectStoreCoordinator) and design your own ObjStoreCoord. so that e.g. it returns different DBContexts for different ECs. In both cases, you'll have to take care of the DBContext's Database (see e.g. DBContext.handleNotification): either each one gets its own, or they all share the same. If every DBContext gets its own Database object, then each EC should *always* get the same DBContext, or you'll defeat the snapshotting ref. counting. -- S=E9bastien. |
From: <so...@la...> - 2004-08-10 00:48:12
|
On Friday 06 August 2004 21:44, Sebastien Bigaret wrote: [snip] =46irst .. i'm very busy w/ computer off, right now so .. Anyways > I'm not sure this is exact --I've read your post there, and I do not=20 > agree w/ your analysis: I can be wrong of course since my experience w/ > mod_python is really thin, but to my understanding there is a global > namespace available w/ mod-python, the global namespace that exists > within the subinterpreter dedicated to an application. =46irst, i won't talk about apache1 but take care that apache2 isn't really= =20 stable. I use it in production right now but i disabled the thread support. I get to much trouble w/ it. They is 3 kind of process handling in apache2 fork / thread / mixed (i don't recall it but i hope it's true ..:)=20 I won't go deeper in explain but cut/paste the answer i got about MPServlet (which use mod_python + apache2) from Daniel Popowich: """=20 Your questions are related to each other and are frequently asked on the mod_python discussion list. The problem with maintaining global data with mod_python (and servlets doesn't solve this issue) is tightly related to how apache maintains processes and threads. If you are on linux or other unix-like OS, then apache uses the prefork MPM by default. This is a multi-process MPM where each request is handled by a separate process, so you end up with N python interpreters, where N is the number of processes apache has forked. In such an environment, the only way to have global data is through some external storage: sessions, db, shared memory, etc. =46or unix, there is the worker MPM which is a hybrid multi-process/multi-threaded server. With worker you can control apache such that you have ONE process with multiple threads. I know one person who is using servlets in such a manner. (This is the default on windows with the winnt MPM.) In such an environment you can have global data shared across requests, but of course, you'll have to wrap your data in mutexes of some sort to avoid threads stepping on each other. If the data you want shared across requests is tied to a particular user, then sessions are an excellent solution. Light-weight and pretty fast. Servlets has builtin support for sessions; see the api doc or the tutorial. """ In short, using if you're using the fork behaviour, you can't share data. So in modeling =3D> time consuming import .. and multiple (with no way to reduce without restart ).. interpreter .. not talking about the trouble you can get if you have some multiple virtual host=20 etc etc .. If you want to share data, you need to use the multi-thread, but=20 you have to play w/ python thread/mutexes. And everybody around=20 know I don't want to play w/ thread. In modeling, i don't know if=20 you can do something like this. I mean, share a 'global' editing=20 context, and garantues that it's thread safe. (without of course ending w/ a lock/unlock around each http request). I use SQObject=20 for a couple of things right now, and I get exactly this kind of=20 troubles. For example SQLite or MySQL DB Api aren't thread safe.=20 (I get weird issues about lost connection in MySQL) ..=20 So that's the dilemma (the post in my blog, is about all kind=20 of web frameworks, but here is example) If you don't want to=20 share objects, ok but you will loose time because you can use=20 some cache behaviours ..=20 I you want to share, it's ok, but you need to play w/ generator (=E0la Twisted) or to play w/ the mutexes. And i didn't find a way to do it the nice way, because most of python modules doesn't scale very well in threaded env.=20 In my point of view, quixote offer a good way to handle this.=20 Because it use the same prefork / reuse process that apache does. So you don't have to deal w/ threadObuggy modules, and=20 you can really handle multiples connections without any other artifact, and without loosing time in big lock/unlock.=20 (I know Zope can handle multiple cnx without too much pain by threading. But Zope's threads aren't really used to do=20 multiple task at the same time. It's just a way to accept http request without locking ..)=20 > > Look at http://www.larsen-b.com/Article/130.html for little deeper > > explain of the problem. > > > > I haven't do this kind of stuff for a while.. but i think Modeling need > > something like Durus do .. a server process.. :) > > Interesting indeed, I'll have a look at that. Do you have experience > with this? How do they serialize objects that are transmitted between > the server and its client? I played w/ it in a recent project, it's more simple than ZODB + ZEO ..=20 but i don't know how it works.=20 While finishing this mail, i remember that's a modeling mailing list, and=20 need to apologize to other that don't want to hear about http handling=20 Hope this helps. / I know i need to go to english course sooooonnnn :) |
From: Delio B. <in...@dr...> - 2004-08-09 23:56:53
|
Hello, I'm evaluating the use of modeling for our new project(s) and was wondering if some of you could give me pointers on how to access multiple database instances of the same model in the same application. (I understand that each database instance will be isolated and don't expect to insert object from an objectStore into another) After creating my first model definition and 30 minutes dive in the docs, it seems I'll have to create an EC passing a 'properly crafted' :-) ObjectStore instance. Am I on the right track? regards -- Delio |
From: Mario R. <ma...@ru...> - 2004-08-09 18:20:08
|
On Aug 9, 2004, at 6:12 PM, Sebastien Bigaret wrote: > Dennis Kertis <djk...@ya...> wrote: >> Hello, >> >> I am trying to get started with Modeling and have >> reviewed the users guide, but I do not see a complete >> example application. >> >> Rather than try to piece different sections of the >> users guide together, It would be easier to start with >> an application that works "out of the box" I can >> modify to suit my needs. > > > Sorry Dennis, I'm afraid I've no such example at hand. I know we need=20= > a > little demo app., probably along with a real tutorial, but it's not=20 > been > made yet. > > Maybe someone on the list already have a sample little app. just for > demonstration? > > -- S=E9bastien. Ya, a nice complete example would be... quite nice ;) As also would be=20= a tutorial... Dennis, the quick example I assume you have seen? It is the core of any=20= modeling based app, and a more evolved app will necessarily introduce=20 all sorts of other issues that are in principle independent of=20 modeling, such as web/appservers (and which one to use for such an=20 example?), gui or command line interface issues, and so on. This is in=20= principle... as clearly each of these imposes some definite=20 constraints, such as the EC and sessions ongoing discussion. mario |
From: Sebastien B. <sbi...@us...> - 2004-08-09 16:13:03
|
Dennis Kertis <djk...@ya...> wrote: > Hello, >=20 > I am trying to get started with Modeling and have > reviewed the users guide, but I do not see a complete > example application. >=20 > Rather than try to piece different sections of the > users guide together, It would be easier to start with > an application that works "out of the box" I can > modify to suit my needs. Sorry Dennis, I'm afraid I've no such example at hand. I know we need a little demo app., probably along with a real tutorial, but it's not been made yet. Maybe someone on the list already have a sample little app. just for demonstration? -- S=E9bastien. |
From: Dennis K. <djk...@ya...> - 2004-08-09 15:58:27
|
Hello, I am trying to get started with Modeling and have reviewed the users guide, but I do not see a complete example application. Rather than try to piece different sections of the users guide together, It would be easier to start with an application that works "out of the box" I can modify to suit my needs. thanks, Dennis __________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail |
From: Sebastien B. <sbi...@us...> - 2004-08-09 15:54:36
|
Duncan McGreggor <py...@ad...> wrote: > Since the basic requirements were to have minimal connects to the database > server, the default behaviour of keeping the connection open is just fine. >=20 > However, what happens when I use EditingContextSessioning? It seems to cr= eate > an EC keyed off a session id. Will that keep one complete editing context= per > user session (and thus one opened database connection per session)? or am= I > missing something? By default ECSessioning creates an EC per session id, right --but then, each EC has the same parent ObjectStore, an ObjectStoreCoordinator by default, which in turn forwards the request (e.g. a fetch) to the appropriate elements underneath it. In a word: you get as much ECs as you want, but only one DB-connection is opened (and left opened). > >>> If this is the case, then we'll need an other ObjectStoreCoordinator, > >>> assigning a dedicated DBContext to each EC... Hmmm, just thinking lou= dly > >>> here, okay, I'll wait til you confirm the need for such a feature. > >> > >> How much work is entailed in this? What would the other OSC do? > > > > It would assign specific elements of the Database (DBContext, DBChannel) > > and Adaptor (AdaptorContext, AdaprotChannel) layers per EC. At least, > > that's what I initially thought. There may be another way to ensure > > different fetchs could run concurrently --but if you can accept that any > > fecth waits for the running one to finish, it's probably not worth the > > effort, or am I still missing something? >=20 > There is no business need or user demand for this app that will require > super-speeds and concurrent queries per session, so I think it's fine wit= hout > going through this trouble... yet ;-) Fine :) but that's an idea we should keep in mind. That will probably be requested in the future. Oh and BTW, Soif hasn't made the remark yet ;) but there is a potential problem with caching, since there is no way for now to "forget" an object and its corresponding snapshot --except by deleting all ECs that reference it. Keep that in mind, I'll get back on the subject before the next release I guess. -- S=E9bastien. |
From: Ernesto R. <er...@si...> - 2004-08-09 11:31:08
|
Sebastien Bigaret escribió: > Hi Erny and all, > >On Wed, 30 Jun 2004, Ernesto Revilla <er...@si...> wrote: >[original post can be found at: > https://sf.net/mailarchive/forum.php?thread_id=5035017&forum_id=10674] > > > >>I think that Python has a design error with properties, but it is easy to >>correct this. >> >> >[demonstration that properties aint behaving very good when it comes to > inheritance] > > >>In Modeling, when inheriting from class created with properties (dynamic), it >>does NOT the inherited methods. Is this reasonable? >> >> Sometimes I just forget the VERB. I mean 'apply' behind 'NOT' in the previous sentence. Properties bind directly to methods/functions (read method, write method, delete method). This is the result of descriptors implemented in python 2.2. There is still no syntactic sugar to use 'virtualized' properties. >You're right, this needs some attention, really. Could you submit this >as a bug report or as a patch proposal @sf.net please? > > I've sent a patch proposal. >>Here I have attached a >>little patch for dynamic.py. I made a local function mkProp, so that variable >>binding is correct, otherwise it does not work the way it should. >> >> > >Can you be more explicit on this point? > > > As you can see in the mkProp I create the methods like this: getter=lambda s: getattr(s,'get'+name)() Now, as lambda is evaluated, when it is called, it depends of what is the binding of the 'name' variable at this time. If I leave this outside of a function and I have this is called several times, name changes, and at the end will have the last assigned value, so all getters created with the statement will refere effectively to the same attribute, as all getters will evaluate 'name' to the same value. Say you have 3 attributes: name, surname and age, and call the above statement, 3 times in the same order for each attribute, you'll get 3 functions, but all the three functions will call getAge, because 'name' will bind to 'age'. To force the binding, I built the mkProp function and put the statement ( getter=lambda s: getattr(s,'get'+name)() ) into the function body. This forces to copy the binding to a local variable, the function parameter. So each time I call mkProp, name will be bound to another value, and will be retained as the lambda expression refers to it. I think the same thing can be accomplished in another way, e.g. as you do by creating methods from source code. I still haven't tried using this approach. >>Just a >>remark about the setter. As in the original code, a virtual setter is created >>only if the attribute is settable in the base class. In this case, we have two >>alternatives: 1. do not create a setter, as the original code, 2. create >>always a virtual setter and the setter in the base class raises a >>ReadOnlyAttributeException. (This is was I have done in a experimental >>framework.) >> >> > >For the moment being we're not handling any 'readOnly' properties on >attributes --and the one in entity is still ignored for now, so I can't >really see whazt your point is, I suspect I'm misunderstanding something >here. > > > I used that for a mini testing framework I wrote, where i defined read-only attributes. So, please ignore it at this time. > Oh, and BTW sorry for taking such a long time to answer :/ > > No problem at all. I just wanted to make the point clear of using properties. Regards, Erny |