Package Modeling :: Module SchemaGeneration :: Class SchemaGeneration
[show private | hide private]
[frames | no frames]

Class SchemaGeneration

Known Subclasses:
AbstractDBAPI2SchemaGeneration, MySQLSchemaGeneration, OracleSchemaGeneration, PostgresqlSchemaGeneration, SQLiteSchemaGeneration

... __TBD

Additionnally the class defines the following static methods, none of which should be overriden by subclasses:


Method Summary
  __init__(self, anAdaptor)
See interfaces.SchemaGeneration for details
  appendExpressionToScript(self, expression, script)
Appends the expression to the StringIO script, prepended with a semi-colon (';') and a newline if the StringIO is not empty.
  createDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary)
Default implementation returns an empty list.
  createTableStatementsForEntityGroup(self, entityGroup)
Returns a list of SQLExpressions needed to create the tables defined by the supplied 'entityGroup', or an empty list if 'entityGroup' is empty.
  createTableStatementsForEntityGroups(self, entityGroups)
Invokes createTableStatementsForEntityGroup() for each entityGroup in 'entityGroups', and returns the list of SQLExpressions needed to create the necessary table.
  defaultOrderingsForSchemaCreation()
Used in method SchemaGeneration.schemaCreationScriptForEntities() to order the schema creation statements produced (Static method)
  dropDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary)
Default implementation returns an empty list.
  dropForeignKeyConstraintStatementsForRelationship(self, relationship)
Default implementation returns an empty list.
  dropPrimaryKeyConstraintStatementsForEntityGroup(self, entityGroup)
Default implementation returns an empty list.
  dropPrimaryKeyConstraintStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'dropPrimaryKeyConstraintStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence.
  dropPrimaryKeySupportStatementsForEntityGroup(self, entityGroup)
Default implementation returns an empty list.
  dropPrimaryKeySupportStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'dropPrimaryKeySupportStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence.
  dropTableStatementsForEntityGroup(self, entityGroup)
Parameter:
  dropTableStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'dropPrimaryKeySupportStatementsForEntityGroup()' to each of them, collects the results and returns them in a sequence.
  foreignKeyConstraintStatementsForRelationship(self, relationship)
Returns a list of SQLExpressions needed to add a constraint statement for the given relationship.
  primaryKeyConstraintStatementsForEntityGroup(self, entityGroup)
Default implementation returns an empty list.
  primaryKeyConstraintStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'primaryKeyConstraintStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence.
  primaryKeySupportStatementsForEntityGroup(self, entityGroup)
Default implementation returns an empty list.
  primaryKeySupportStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'primaryKeySupportStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence.
  schemaCreationScriptForEntities(self, allEntities, options, keyOrderings)
__TBD
  schemaCreationStatementsForEntities(self, allEntities, options, keyOrderings)
__TBD doc.
  schemaCreationStatementsForEntitiesByOptions(self, allEntities, options)
__TBD doc.
  setDefaultOrderingsForSchemaCreation(keyOrderings)
Sets the default ordering. (Static method)
  tableEntityGroupsForEntities(self, entities)
Returns a list of entityGroups ; each entityGroup consists of the entities in parameter 'entities' which share the same externalName(), and wich answered positively to the definesTableColumns() message.

Class Variable Summary
tuple __implements__ = (<class Modeling.interfaces.SchemaGener...

Instance Method Details

__init__(self, anAdaptor)
(Constructor)

See interfaces.SchemaGeneration for details

appendExpressionToScript(self, expression, script)

Appends the expression to the StringIO script, prepended with a semi-colon (';') and a newline if the StringIO is not empty.

Subclasses overrides this method if the underlying database uses a different syntax.

createDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary)

Default implementation returns an empty list. Subclasses override this method ... __TBD

createTableStatementsForEntityGroup(self, entityGroup)

Returns a list of SQLExpressions needed to create the tables defined by the supplied 'entityGroup', or an empty list if 'entityGroup' is empty.

Default implementation returns a list consisting of one sole SQLExpression whose statement is of the following form:

CREATE TABLE <TABLE_NAME> ( <COLUMN_CREATE_CLAUSES> )

where <TABLE_NAME> is the externalName of the first entity in 'entityGroup', and <COLUMN_CREATE_CLAUSES> is the list of all create clauses needed to build the underlying columns --see SQLExpression.addCreateClauseForAttribute(). That list can be accessed in the returned SQLExpression object through sending it the message 'listString()'

Parameter 'entityGroup' is a sequence of entities which share the same external name.

See also: dropTableStatementsForEntityGroup, Entity.externalName(),
SQLExpression.addCreateClauseForAttribute(), SQLExpression.listString()

createTableStatementsForEntityGroups(self, entityGroups)

Invokes createTableStatementsForEntityGroup() for each entityGroup in 'entityGroups', and returns the list of SQLExpressions needed to create the necessary table. It is guaranteed that all SQLExpressions in the returned sequence have a different statement (SQLExpression.statement()).

Subclasses should not need to override this method. If they do, they should comply with the guaranteed nature of the returned sequence, as stated above.

Parameter:

entityGroups -- a sequence of entityGroups ; an 'entityGroup' is a list
of entities whose externalNames are identical.

dropDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary)

Default implementation returns an empty list.

dropForeignKeyConstraintStatementsForRelationship(self, relationship)

Default implementation returns an empty list. Subclasses override this method to return a sequence of SQLExpressions designed to remove the foreign key constraints built by foreignKeyConstraintStatementsForRelationship(). Returned value should be an empty list if 'entityGroup' is empty.

Parameter 'entityGroup' is a list of entities whose externalNames are identical.

See also:
foreignKeyConstraintStatementsForRelationship()

dropPrimaryKeyConstraintStatementsForEntityGroup(self, entityGroup)

Default implementation returns an empty list. Subclasses override this method to return a sequence of SQLExpressions designed to remove the constraint Primary Key constraints built by primaryKeyConstraintStatementsForEntityGroup(). Returned value should be an empty list if 'entityGroup' is empty.

Parameter 'entityGroup' is a list of entities whose externalNames are identical.

See also:
primaryKeyConstraintStatementsForEntityGroup()

dropPrimaryKeyConstraintStatementsForEntityGroups(self, entityGroups)

Iterates on each entityGroup in 'entityGroups', sends the message 'dropPrimaryKeyConstraintStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence. It is guaranteed that all SQLExpressions in the returned sequence have a different statement (SQLExpression.statement()).

Subclasses should not need to override this method. If they do, they should comply with the guaranteed nature of the returned sequence, as stated above.

Parameter:

entityGroups -- a sequence of entityGroups ; an 'entityGroup' is a list
of entities whose externalNames are identical.

See also: primaryKeyConstraintStatementsForEntityGroups()

dropPrimaryKeySupportStatementsForEntityGroup(self, entityGroup)

Default implementation returns an empty list. Subclasses override this method to return a sequence of SQLExpressions designed to remove the elements supporting the mechanism used to generate primary keys, as they were created by primaryKeySupportStatementsForEntityGroup(). Returned value should be an empty list if 'entityGroup' is empty.

Parameter 'entityGroup' is a list of entities whose externalNames are identical.

See also:
primaryKeySupportStatementsForEntityGroup() AdaptorContext.primaryKeysForNewRowsWithEntity()

dropPrimaryKeySupportStatementsForEntityGroups(self, entityGroups)

Iterates on each entityGroup in 'entityGroups', sends the message 'dropPrimaryKeySupportStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence. It is guaranteed that all SQLExpressions in the returned sequence have a different statement (SQLExpression.statement()).

Subclasses should not need to override this method. If they do, they should comply with the guaranteed nature of the returned sequence, as stated above.

Parameter:

entityGroups -- a sequence of entityGroups ; an 'entityGroup' is a list
of entities whose externalNames are identical.

dropTableStatementsForEntityGroup(self, entityGroup)

Parameter:

entityGroup -- a list of entities whose externalNames are identical.

dropTableStatementsForEntityGroups(self, entityGroups)

Iterates on each entityGroup in 'entityGroups', sends the message 'dropPrimaryKeySupportStatementsForEntityGroup()' to each of them, collects the results and returns them in a sequence.

Subclasses should not need to override this method. If they do, they should comply with the guaranteed nature of the returned sequence, as stated above.

foreignKeyConstraintStatementsForRelationship(self, relationship)

Returns a list of SQLExpressions needed to add a constraint statement
for the given relationship. Under specific conditions on 'relationship',
expressed below, that lists consists of a single SQLExpression
statement of the following form::

   ALTER TABLE <TABLE> ADD CONSTRAINT <REL_NAME> FOREIGN KEY
   (<FKS>) REFERENCES <DESTINATION_TABLE>(<DESTINATION_PK>)
   INITIALLY DEFERRED

where TABLE is the relationship's entity externalName(),
      REL_NAME is the relationship's source attribute columnName(),
      FKS is a comma-separated list of the relationship's source
        attributes.columnName(),
      DESTINATION_PKS is a comma-separated list of the rel.'s
        destinationAttributes().columnName(),
      DESTINATION_TABLE is the relationship.destinationEntity() 's
        externalName()

The conditions under which the statement above is returned are:

  - the relationship is a toOne rel. and it is not flattened,

  - its inverseRelationship, if any, is a toMany relationship,

  - its source and destinationEntity share the same model

  - the destinationEntity has no sub-entity.

If any of these conditions is not fulfilled the method returns an empty
sequence.

Why 'INITIALLY DEFERRED'? Suppose we need to cascade delete 3 objects in
relations ; we do not guarantee that they will be deleted in the correct
order (moreover, determining the order in which objects should be deleted,
or updated, etc. is a difficult problem and solving it is beyond my
knowledge). So, we need to defer the constraint until the transaction
commits. Last, I put it there, not in any specific adaptor, since I do not
want to hide that fact from the eyes of anyone willing to create a custom
AdaptorLayer. If this is what you want to do, and your database does not
allow constraints to be deferred, you'll probably won't add any
referential constraints at all --or you'll solve the general scheduling
problem!

primaryKeyConstraintStatementsForEntityGroup(self, entityGroup)

Default implementation returns an empty list. __TBD

Parameter 'entityGroup' is a list of entities whose externalNames are identical.

See also: dropPrimaryKeyConstraintStatementsForEntityGroup
primaryKeyConstraintStatementsForEntityGroups dropPrimaryKeySupportStatementsForEntityGroup

primaryKeyConstraintStatementsForEntityGroups(self, entityGroups)

Iterates on each entityGroup in 'entityGroups', sends the message 'primaryKeyConstraintStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence. It is guaranteed that all SQLExpressions in the returned sequence have a different statement (SQLExpression.statement()).

Subclasses should not need to override this method. If they do, they should comply with the guaranteed nature of the returned sequence, as stated above.

Parameter:

entityGroups -- a sequence of entityGroups ; an 'entityGroup' is a list
of entities whose externalNames are identical.

See also: dropPrimaryKeySupportStatementsForEntityGroups()

primaryKeySupportStatementsForEntityGroup(self, entityGroup)

Default implementation returns an empty list. Subclasses override this method to return a sequence of SQLExpressions in adequation to the mechanism used to generate primary keys, or an empty list if 'entityGroup' is empty.

Subclasses overriding this method have no need to call the super implementation.

Parameter:

entityGroup -- a list of entities whose externalNames are identical.
See also:
dropPrimaryKeySupportStatementsForEntityGroup() AdaptorContext.primaryKeysForNewRowsWithEntity() Entity.primaryKeyRootName()

primaryKeySupportStatementsForEntityGroups(self, entityGroups)

Iterates on each entityGroup in 'entityGroups', sends the message 'primaryKeySupportStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence. It is guaranteed that all SQLExpressions in the returned sequence have a different statement (SQLExpression.statement()).

Subclasses should not need to override this method. If they do, they should comply with the guaranteed nature of the returned sequence, as stated above.

Parameter:

entityGroups -- a sequence of entityGroups ; an 'entityGroup' is a list
of entities whose externalNames are identical.

schemaCreationScriptForEntities(self, allEntities, options, keyOrderings=())

__TBD

If parameter 'keyOrdering' is omitted, None or empty it defaults to 'defaultOrderingsForSchemaCreation()'.

See also: schemaCreationStatementsForEntities(), appendExpressionToScript()
defaultOrderingsForSchemaCreation()

schemaCreationStatementsForEntities(self, allEntities, options, keyOrderings=())

__TBD doc.

schemaCreationStatementsForEntitiesByOptions(self, allEntities, options)

__TBD doc.

tableEntityGroupsForEntities(self, entities)

Returns a list of entityGroups ; each entityGroup consists of the entities in parameter 'entities' which share the same externalName(), and wich answered positively to the definesTableColumns() message. Hence, the set of entities returned in the entityGroups is a (possibly smaller) subset of the entities supplied in parameter 'entities'

See also: Entity.definesTableColumns()


Static Method Details

defaultOrderingsForSchemaCreation()

Used in method SchemaGeneration.schemaCreationScriptForEntities() to order the schema creation statements produced

This method is also available as a static method in class SchemaGeneration.

setDefaultOrderingsForSchemaCreation(keyOrderings)

Sets the default ordering. See defaultOrderingsForSchemaCreation() for details.

This method is also available as a static method in class SchemaGeneration.


Class Variable Details

__implements__

Type:
tuple
Value:
(<class Modeling.interfaces.SchemaGeneration.ISchemaGeneration at 0xb7\
62a5fc>,)                                                              

Generated by Epydoc 2.1 on Sat Mar 4 13:36:22 2006 http://epydoc.sf.net