Please note: this project is inactive since early 2006

 
7. Accessing a model and its properties

Every model required at runtime is loaded into a single ModelSet, the so-called ``default model set''. It is accessed this way:

  >>> from Modeling.ModelSet import defaultModelSet
  >>> ms=defaultModelSet()

Suppose we already imported the two test packages AuthorBooks and StoreEmployees, then we have:

  >>> ms.modelsNames()
  ['AuthorBooks', 'StoreEmployees']

The two corresponding models have been correctly imported, as expected.

Accessing a model in particular, or one of its entities is straightforward:

  >>> model_AuthorBooks=ms.modelNamed('AuthorBooks')
  >>> model_AuthorBooks.entitiesNames()
  ['Writer', 'Book']
  >>> model_AuthorBooks.entities()
  (<Entity instance at 8396b50>, <Entity instance at 8337cd0>)
  >>> entity_Book=model_AuthorBooks.entityNamed('Book')

Note: you do not need to access a model to get one of its entities; since entities share a common namespace inside a ModelSet, this can be asked to the model set as well:

  >>> ms.entitiesNames()
  ('Writer', 'Book', 'Store', 'Employee', 'Address', 'SalesClerk',
   'Executive', 'Mark')
  >>> ms.entityNamed('Book')
  <Entity instance at 8337cd0>

Last, given an entity, you can access its attributes and relationships quite the same way, for example:

  >>> # All attributes' names
  ... entity_Book.attributesNames()
  ('title', 'id', 'price', 'FK_Writer_Id')
  >>> # All relationships' names
  ... entity_Book.relationshipsNames()
  ('author',)
  >>> # Class properties only
  ... entity_Book.classProperties()
  (<Attribute instance at 839bc38>, <Attribute instance at 83c5720>,
   <Attribute instance at 83eaca8>, <SimpleRelationship instance at 840b280>)
  >>> # and their names
  ... entity_Book.classPropertiesNames()
  ['title', 'id', 'price', 'author']
  >>> # dealing with an attribute
  ... book_title=entity_Book.attributeNamed('title')
  >>> book_title.type(), book_title.externalType(), book_title.width()
  ('string', 'VARCHAR', 40)

Each of the classes Model, Entity, Attribute and Relationship have more functionalities then that. We invite you to look at their respective API for further details.

Comments are welcome: Sebastien Bigaret / Modeling Home Page
Hosted by:SourceForge.net Logo