PATH Documentation > WebObjects

Table of Contents

EOSchemaGeneration


Implemented by:
EOSynchronizationFactory
Package:
com.webobjects.eoaccess

Interface Description


This interface has been introduced to define API for generating database schemas from model files. None of the API is new. Rather, it was moved to EOSchemaGeneration from EOSQLExpression. The API is essentially the same except that in 4.5, the methods were static methods. In 5.0 the methods on EOSchemaGeneration are instance methods.

An implementation of the EOSchemaGeneration API is provided by the class, EOSynchronizationFactory, which is new in 5.0. For more information, see the sections for EOSQLExpression and EOSynchronizationFactory.



Constants


EOSchemeGeneration defines the following String constants.


Constant Description
CreateTablesKey Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create tables.
DropTablesKey Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to drop tables.
CreatePrimaryKeySupportKey Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create primary key support.
DropPrimaryKeySupportKey Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to drop primary key support.
PrimaryKeyConstraintsKey Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create primary key constraints.
ForeignKeyConstraintsKey Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create foreign key constraints.
CreateDatabaseKey Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create a database.
DropDatabaseKey Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to drop a database.



Method Types


Creating a schema generation script
schemaCreationScriptForEntities
schemaCreationStatementsForEntities
appendExpression
createTableStatementsForEntityGroup
createTableStatementsForEntityGroups
dropTableStatementsForEntityGroup
dropTableStatementsForEntityGroups
primaryKeyConstraintStatementsForEntityGroup
primaryKeyConstraintStatementsForEntityGroups
primaryKeySupportStatementsForEntityGroup
primaryKeySupportStatementsForEntityGroups
dropPrimaryKeySupportStatementsForEntityGroup
dropPrimaryKeySupportStatementsForEntityGroups
foreignKeyConstraintStatementsForRelationship
createDatabaseStatementsForConnectionDictionary
dropDatabaseStatementsForConnectionDictionary


Instance Methods



appendExpression

public abstract void appendExpressionToScript( EOSQLExpression anSQLExpression, StringBuffer script)

Append's anSQLExpression's statement to script along with any necessary delimiter. EOSQLExpression's implementation appends the SQL statement for anSQLExpression to script followed by a semicolon and a newline. A subclass of EOSQLExpression only needs to override this method if the delimiter for its database server is different. For example, the Oracle and Informix use the default implementation, whereas the Sybase adaptor appends the word "go" instead of a semicolon.

See Also: createTableStatementsForEntityGroup



createDatabaseStatementsForConnectionDictionary

public abstract NSArray createDatabaseStatementsForConnectionDictionary( NSDictionary connectionDictionary, NSDictionary adminDictionary)

Generates the SQL statements that will create a database (or user, for Oracle) that can be accessed by the provided connection dictionary and administrative connection dictionary.

See Also: dropDatabaseStatementsForConnectionDictionary



createTableStatementsForEntityGroup

public abstract NSArray createTableStatementsForEntityGroup(NSArray entityGroup)

Returns an array of EOSQLExpression objects that define the SQL necessary to create a table for entityGroup, an array of EOEntity objects that have the same externalName. Returns an empty array if entityGroup is null or empty.

EOSQLExpression's implementation does the following:

  1. Creates an EOSQLExpression object.
  2. Sets the expression's entity to the first entity in entityGroup.
  3. Adds a create clause for each Attribute in entityGroup's Entities.
  4. Sets the expression's statement to CREATE TABLE TABLE_NAME (LIST_STRING), where TABLE_NAME is the externalName of the Entity objects in entityGroup and LIST_STRING is the expression's listString.
  5. Adds the expression to an array.
  6. Returns the array.

The following is an example of a CREATE TABLE statement produced by the default implementation:


create table EMPLOYEE (
    EMP_ID      int not null,
    DEPT_ID     int null,
    LAST_NAME   varchar(40) not null,
    PHONE       char(12) null,
    HIRE_DATE   date null,
    SALARY      number(7, 2) null
)

If a subclass's database server's table creation semantics are different, the subclass should override this method or one or more of the following methods as appropriate:

See Also: createTableStatementsForEntityGroup, dropTableStatementsForEntityGroup



createTableStatementsForEntityGroups

public abstract NSArray createTableStatementsForEntityGroups(NSArray entityGroups)

Returns an array of EOSQLExpression objects that define the SQL necessary to create the tables specified in entityGroups. An entity group is an array of Entity objects that have the same externalName, and entityGroups is an array of entity groups. Returns an empty array if entityGroups is null or empty. EOSQLExpression's implementation invokes createTableStatementsForEntityGroup for each entity group in entityGroups and returns an array of all the resulting EOSQLExpressions.

See Also: schemaCreationStatementsForEntities



dropDatabaseStatementsForConnectionDictionary

public abstract NSArray dropDatabaseStatementsForConnectionDictionary( NSDictionary connectionDictionary, NSDictionary adminDictionary)

Generates the SQL statements to drop a database (or user, for Oracle).

See Also: createDatabaseStatementsForConnectionDictionary



dropPrimaryKeySupportStatementsForEntityGroup

public abstract NSArray dropPrimaryKeySupportStatementsForEntityGroup(NSArray entityGroup)

Returns an array of EOSQLExpression objects that define the SQL necessary to drop the primary key generation support for entityGroup, an array of Entity objects that have the same externalName. The drop statement generated by this method should be sufficient to remove the primary key support created by primaryKeySupportStatementsForEntityGroup's statements.

EOSQLExpression's implementation creates a statement of the following form:


drop sequence SEQUENCE_NAME

Where SEQUENCE_NAME is the primaryKeyRootName for the first entity in entityGroup concatenated with "_SEQ" (EMP_ID_SEQ, for example).

If a subclass uses a different primary key generation mechanism or if the subclass's database server's drop semantics are different, the subclass should override this method.



dropPrimaryKeySupportStatementsForEntityGroups

public abstract NSArray dropPrimaryKeySupportStatementsForEntityGroups(NSArray entityGroups)

Returns an array of EOSQLExpression objects that define the SQL necessary to drop the primary key generation support for the entities specified in entityGroups. An entity group is an array of EOEntity objects that have the same externalName, and entityGroups is an array of entity groups. EOSQLExpression's implementation invokes dropPrimaryKeySupportStatementsForEntityGroup for each entity group in entityGroups and returns an array of all the resulting EOSQLExpressions.

See Also: schemaCreationStatementsForEntities



dropTableStatementsForEntityGroup

public abstract NSArray dropTableStatementsForEntityGroup(NSArray entityGroup)

Returns an array of EOSQLExpression objects that define the SQL necessary to drop the table identified by entityGroup, an array of Entity objects that have the same externalName. The drop statement generated by this method should be sufficient to remove the table created by createTableStatementsForEntityGroup's statements.

EOSQLExpression's implementation creates a statement of the following form:


DROP TABLE TABLE_NAME

Where TABLE_NAME is the externalName of the first entity in entityGroup.

If a subclass's database server's drop semantics are different, the subclass should override this method.



dropTableStatementsForEntityGroups

public abstract NSArray dropTableStatementsForEntityGroups(NSArray entityGroups)

Returns an array of EOSQLExpression objects that define the SQL necessary to drop the tables for entityGroups. An entity group is an array of Entity objects that have the same externalName, and entityGroups is an array of entity groups. EOSQLExpression's implementation invokes dropTableStatementsForEntityGroup for each entity group in entityGroups and returns an array of all the resulting EOSQLExpressions.

See Also: schemaCreationStatementsForEntities



foreignKeyConstraintStatementsForRelationship

public abstract NSArray foreignKeyConstraintStatementsForRelationship(EORelationship aRelationship)

Returns an array of EOSQLExpression objects that define the SQL necessary to create foreign key constraints for aRelationship. EOSQLExpression's implementation generates statements such as the following:

ALTER TABLE EMPLOYEE ADD CONSTRAINT TO_DEPARTMENT FOREIGN KEY (DEPT_ID)
        REFERENCES DEPARTMENT(DEPT_ID)

It returns an empty array if either of the following are true:

If a subclass's database server's foreign key constraint semantics are different, the subclass should override this method or override the method prepareConstraintStatementForRelationship:sourceColumns:destinationColumns:.

See Also: schemaCreationStatementsForEntities



primaryKeyConstraintStatementsForEntityGroup

public abstract NSArray primaryKeyConstraintStatementsForEntityGroup(NSArray entityGroup)

Returns an array of EOSQLExpression objects that define the SQL necessary to create the primary key constraints for entityGroup, an array of EOEntity objects that have the same externalName. Returns an empty array if any of the primary key attributes in entityGroup don't have a columnName.

EOSQLExpression's implementation creates a statement of the following form:


ALTER TABLE TABLE_NAME ADD PRIMARY KEY (PRIMARY_KEY_COLUMN_NAMES)

Where TABLE_NAME is the externalName for the first entity in entityGroup and PRIMARY_KEY_COLUMN_NAMES is a comma-separated list of the columnNames of the first entity's primaryKeyAttributes.

If the subclass's database server's primary key constraint semantics are different, the subclass should override this method.



primaryKeyConstraintStatementsForEntityGroups

public abstract NSArray primaryKeyConstraintStatementsForEntityGroups(NSArray entityGroups)

Returns an array of EOSQLExpression objects that define the SQL necessary to create the primary key constraints for the Entities specified in entityGroups. An entity group is an array of Entity objects that have the same externalName, and entityGroups is an array of entity groups. EOSQLExpression's implementation invokes primaryKeySupportStatementsForEntityGroup for each entity group in entityGroups and returns an array of all the resulting EOSQLExpressions.

primaryKeySupportStatementsForEntityGroup

public abstract NSArray primaryKeySupportStatementsForEntityGroup(NSArray entityGroup)

Returns an array of EOSQLExpression objects that define the SQL necessary to create the primary key generation support for entityGroup, an array of EOEntity objects that have the same externalName. EOSQLExpression's implementation creates a statement of the following form:

create sequence SEQUENCE_NAME

Where SEQUENCE_NAME is the primaryKeyRootName for the first entity in entityGroup concatenated with "_SEQ" (EMP_ID_SEQ, for example).

If a subclass uses a different primary key generation mechanism or if the subclass's database server's drop semantics are different, the subclass should override this method.

See Also: dropPrimaryKeySupportStatementsForEntityGroup, primaryKeyForNewRowWithEntity (EOAdaptorChannel)



primaryKeySupportStatementsForEntityGroups

public abstract NSArray primaryKeySupportStatementsForEntityGroups(NSArray entityGroups)

Returns an array of EOSQLExpression objects that define the SQL necessary to create the primary key generation support for the Entities specified in entityGroups. An entity group is an array of Entity objects that have the same externalName, and entityGroups is an array of entity groups. EOSQLExpression's implementation invokes primaryKeySupportStatementsForEntityGroup for each entity group in entityGroups and returns an array of all the resulting EOSQLExpressions.

schemaCreationScriptForEntities

public abstract String schemaCreationScriptForEntities( NSArray entities, NSDictionary options)

Returns a script of SQL statements suitable to create the schema for the EOEntity objects in entities. The options dictionary describes the aspects of the schema for which to create SQL statements; for more information, see "The Options Dictionary" (page 306). EOSQLExpression's implementation invokes schemaCreationStatementsForEntities with entities and options and then uses appendExpression to generate the script from the EOSQLExpressions generated by schemaCreationStatementsForEntities.

schemaCreationStatementsForEntities

public abstract NSArray schemaCreationStatementsForEntities( NSArray entities, NSDictionary options)

Returns an array of EOSQLExpressions suitable to create the schema for the Entity objects in entities. The options dictionary describes the aspects of the schema for which to create SQL statements; for more information, see "The Options Dictionary" (page 306).

EOSQLExpression's implementation uses the following methods:

to generate EOSQLExpressions for the support identified in options.

See Also: schemaCreationScriptForEntities



© 2001 Apple Computer, Inc. (Last Published April 13, 2001)


Table of Contents