[Modeling-cvs] ProjectModeling/Modeling/tests/testPackages/StoreEmployees pymodel_StoreEmployees.py,
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2003-05-18 15:29:30
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/tests/testPackages/StoreEmployees In directory sc8-pr-cvs1:/tmp/cvs-serv4394/tests/testPackages/StoreEmployees Added Files: Tag: brch-0_9pre7-1-PyModel pymodel_StoreEmployees.py Log Message: Added tests/testPackages/StoreEmployees/pymodel_StoreEmployees.py and updated StoreEmployees/__init__.py: now loads the model from the PyModel --- NEW FILE: pymodel_StoreEmployees.py --- #! /usr/bin/env python ''' A sample Pythonic OO-RDB Model (re-expressing testPackages/StoreEmployees/model_StoreEmployees.xml) -- A PyModel must define a global variable called 'model', that is of type Model ''' from Modeling.PyModel import * ## # Set preferred defaults for this model (when different from # standard defaults, or if we want to make things explicit) AFloat.defaults['precision'] = 10 AFloat.defaults['scale'] = 10 AString.defaults['width'] = 30 RToOne.defaults['delete'] = 'nullify' RToOne.defaults['multiplicity'] = [0,1] #RToOne.defaults['sourceAttribute'] = RToOne.attNameFromRel # 'fk'+destEnt+destAtt+count #RToOne.defaults['destinationAttribute'] = 'id' RToMany.defaults['delete'] = 'cascade' RToMany.defaults['multiplicity'] = [0,None] #RToMany.defaults['sourceAttribute'] = 'id' #RToMany.defaults['destinationAttribute'] = RToMany.attNameFromRel # fk+destEnt+sourceAtt+count # Note that Relation.attNameFromRel is a callable, that calculates the att # name from the indicated pieces (where count to distinguish between multiple # relations between same source and target Entity.defaults['properties'] = [ APrimaryKey('id', isClassProperty=0, isRequired=1, doc='Primary key!') ] ## _connDict = {'database': 'STORE_EMPLOYEES'} model = Model('StoreEmployees',adaptorName='Postgresql', connDict=_connDict) model.doc = ' ... ' model.version='0.1' model.entities = [ # Entity('Store', properties=[ AString('corporateName', isRequired=1), ], ), Entity('Employee', properties=[ AString('lastName',isRequired=1,usedForLocking=1, width=20), AString('firstName', isRequired=1, width=50, usedForLocking=1), ] ), Entity('SalesClerk', parent='Employee', properties=[ AString('storeArea', width=20) ] ), Entity('Executive', parent='Employee', properties=[ AString('officeLocation', width=5) ] ), Entity('Address', properties=[ AString('street', width=80), AString('zipCode', width=10), AString('town'), ] ), Entity('Mark', properties=[ AInteger('month', isRequired=1), AInteger('mark', isRequired=1), ] ) ] model.associations=[ Association('Mark', 'Executive', relations=['executive', 'marks'], keys=['FK_Executive_id', 'id']), Association('Address', 'Employee', relations=['toEmployee', 'toAddresses'], keys=['fkEmployeeId', 'id']), Association('Store', 'Employee', relations=['employees', 'toStore'], keys=['fkStoreId', 'id']), ] if __name__ == '__main__': model.build() #print model.validate() #print model.toXML() # plus whatever ... ## |