Class SchemaManager
- java.lang.Object
-
- org.eclipse.persistence.tools.schemaframework.SchemaManager
-
- Direct Known Subclasses:
DynamicSchemaManager
public class SchemaManager extends Object
Purpose: Define all user level protocol for development time database manipulation.
Responsibilities:
- Define protocol for schema creation.
- Define any useful testing specific protocol.
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
FAST_TABLE_CREATOR
Allow table creator to occur "fast" by just deleting all the rows.static boolean
FORCE_DROP
Allow replacing of table to force the drop, this may require several passes.
-
Constructor Summary
Constructors Constructor Description SchemaManager(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl session)
SchemaManager(DatabaseSession session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
alterSequence(SequenceDefinition sequenceDefinition)
Use the definition to alter sequence.void
appendToDDLWriter(Writer schemaWriter, String stringToWrite)
void
appendToDDLWriter(String stringToWrite)
PUBLIC: If the schema manager is writing to a writer, append this string to that writer.void
buildFieldTypes(TableDefinition tableDef)
INTERNAL: builds the field names based on the type read in from the builderboolean
checkTableExists(TableDefinition table)
Check if the table exists by issuing a select.void
closeDDLWriter()
PUBLIC: Close the schema writer.void
closeDDLWriter(Writer schemaWriter)
void
createConstraints(TableDefinition tableDefinition)
Use the table definition to add the constraints to the database, this is normally done in two steps to avoid dependencies.void
createDefaultTables(boolean generateFKConstraints)
Create the default table schema for the project this session associated with.void
createObject(DatabaseObjectDefinition databaseObjectDefinition)
Use the definition object to create the schema entity on the database.void
createSequences()
Create all the receiver's sequences on the database for all of the loaded descriptors.void
dropConstraints(TableDefinition tableDefinition)
Use the table definition to drop the constraints from the table, this is normally done in two steps to avoid dependencies.void
dropDatabaseSchemas()
INTERNAL: Iterate over the schemas that need to be dropped.void
dropDefaultTables()
Create the default table schema for the project this session associated with.void
dropObject(DatabaseObjectDefinition databaseObjectDefinition)
Use the definition object to drop the schema entity from the database.void
dropTable(String tableName)
Drop (delete) the table named tableName from the database.void
extendDefaultTables(boolean generateFKConstraints)
Create or extend the default table schema for the project this session associated with.void
finalize()
INTERNAL: Close the schema writer when the schema manger is garbage collectedvoid
generateStoredProcedures()
PUBLIC: Use this method to generate stored procedures based on the dynamic SQL generated for your mappings and descriptors.void
generateStoredProcedures(Writer writer)
PUBLIC: Use this method to generate stored procedures based on the dynamic SQL generated for your mappings and descriptors.void
generateStoredProceduresAndAmendmentClass(Writer writer, String fullyQualifiedClassName)
PUBLIC: Use this method to generate stored procedures based on the dynamic SQL generated for your mappings and descriptors.void
generateStoredProceduresAndAmendmentClass(String path, String fullyQualifiedClassName)
PUBLIC: Use this method to generate stored procedures based on the dynamic SQL generated for your mappings and descriptors.Vector
getAllColumnNames(String tableName)
Get a description of table columns available in a catalog.Vector
getAllColumnNames(String creatorName, String tableName)
Get a description of table columns available in a catalog.Vector
getAllTableNames()
Get a description of tables available in a catalog.Vector
getAllTableNames(String creatorName)
Get a description of table columns available in a catalog.Vector
getColumnInfo(String catalog, String schema, String tableName, String columnName)
Get a description of table columns available in a catalog.org.eclipse.persistence.internal.sessions.AbstractSession
getSession()
Vector
getTableInfo(String catalog, String schema, String tableName, String[] types)
Get a description of tables available in a catalog.void
outputCreateDDLToFile(String fileName)
void
outputCreateDDLToWriter(Writer createWriter)
void
outputDDLToDatabase()
PUBLIC: Output all DDL statements directly to the database.void
outputDDLToFile(String fileName)
PUBLIC: Output all DDL statements to a file writer specified by the name in the parameter.void
outputDDLToWriter(Writer schemaWriter)
PUBLIC: Output all DDL statements to a writer specified in the parameter.void
outputDropDDLToFile(String fileName)
void
outputDropDDLToWriter(Writer dropWriter)
void
replaceDefaultTables()
Drop and recreate the default table schema for the project this session associated with.void
replaceDefaultTables(boolean createSequenceTables, boolean generateFKConstraints)
Drop and recreate the default table schema for the project this session associated with.void
replaceDefaultTables(boolean createSequenceTables, boolean createSequences, boolean generateFKConstraints)
Drop and recreate the default table schema for the project this session associated with.void
replaceObject(DatabaseObjectDefinition databaseDefinition)
Use the definition object to drop and recreate the schema entity on the database.void
replaceSequences()
Drop and recreate all the receiver's sequences on the database for all of the loaded descriptors.void
setCreateDatabaseSchemas(boolean createDatabaseSchemas)
INTERNAL: Set to true if database schemas should be built during the DDL generation.void
setCreateSQLFiles(boolean genFlag)
void
setSession(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl session)
boolean
shouldWriteToDatabase()
PUBLIC: Return true if this SchemaManager should write to the database directly
-
-
-
Constructor Detail
-
SchemaManager
public SchemaManager(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl session)
-
SchemaManager
public SchemaManager(DatabaseSession session)
-
-
Method Detail
-
appendToDDLWriter
public void appendToDDLWriter(String stringToWrite)
PUBLIC: If the schema manager is writing to a writer, append this string to that writer.
-
buildFieldTypes
public void buildFieldTypes(TableDefinition tableDef)
INTERNAL: builds the field names based on the type read in from the builder
-
closeDDLWriter
public void closeDDLWriter()
PUBLIC: Close the schema writer.
-
closeDDLWriter
public void closeDDLWriter(Writer schemaWriter)
-
createConstraints
public void createConstraints(TableDefinition tableDefinition) throws EclipseLinkException
Use the table definition to add the constraints to the database, this is normally done in two steps to avoid dependencies.- Throws:
EclipseLinkException
-
createObject
public void createObject(DatabaseObjectDefinition databaseObjectDefinition) throws EclipseLinkException
Use the definition object to create the schema entity on the database. This is used for creating tables, views, procedures ... etc ...- Throws:
EclipseLinkException
-
createSequences
public void createSequences() throws EclipseLinkException
Create all the receiver's sequences on the database for all of the loaded descriptors.- Throws:
EclipseLinkException
-
setCreateDatabaseSchemas
public void setCreateDatabaseSchemas(boolean createDatabaseSchemas)
INTERNAL: Set to true if database schemas should be built during the DDL generation.
-
setCreateSQLFiles
public void setCreateSQLFiles(boolean genFlag)
-
replaceSequences
public void replaceSequences() throws EclipseLinkException
Drop and recreate all the receiver's sequences on the database for all of the loaded descriptors.- Throws:
EclipseLinkException
-
checkTableExists
public boolean checkTableExists(TableDefinition table)
Check if the table exists by issuing a select.
-
dropConstraints
public void dropConstraints(TableDefinition tableDefinition) throws EclipseLinkException
Use the table definition to drop the constraints from the table, this is normally done in two steps to avoid dependencies.- Throws:
EclipseLinkException
-
dropObject
public void dropObject(DatabaseObjectDefinition databaseObjectDefinition) throws EclipseLinkException
Use the definition object to drop the schema entity from the database. This is used for dropping tables, views, procedures ... etc ...- Throws:
EclipseLinkException
-
dropTable
public void dropTable(String tableName) throws EclipseLinkException
Drop (delete) the table named tableName from the database.- Throws:
EclipseLinkException
-
finalize
public void finalize()
INTERNAL: Close the schema writer when the schema manger is garbage collected
-
generateStoredProcedures
public void generateStoredProcedures() throws EclipseLinkException
PUBLIC: Use this method to generate stored procedures based on the dynamic SQL generated for your mappings and descriptors. This should be used with caution as it maintenance will be high. Stored procedures may be generated either directly on the database or to a file.- Throws:
EclipseLinkException
-
generateStoredProcedures
public void generateStoredProcedures(Writer writer) throws EclipseLinkException
PUBLIC: Use this method to generate stored procedures based on the dynamic SQL generated for your mappings and descriptors. This should be used with caution as it maintenance will be high. Stored procedures may be generated either directly on the database or to a file.- Throws:
EclipseLinkException
-
generateStoredProceduresAndAmendmentClass
public void generateStoredProceduresAndAmendmentClass(Writer writer, String fullyQualifiedClassName) throws EclipseLinkException
PUBLIC: Use this method to generate stored procedures based on the dynamic SQL generated for your mappings and descriptors. This should be used with caution as it maintenance will be high. Stored procedures may be generated either directly on the database or to a file.- Throws:
EclipseLinkException
-
generateStoredProceduresAndAmendmentClass
public void generateStoredProceduresAndAmendmentClass(String path, String fullyQualifiedClassName) throws EclipseLinkException
PUBLIC: Use this method to generate stored procedures based on the dynamic SQL generated for your mappings and descriptors. This should be used with caution as it maintenance will be high. Stored procedures may be generated either directly on the database or to a file.- Throws:
EclipseLinkException
-
getAllColumnNames
public Vector getAllColumnNames(String tableName) throws DatabaseException
Get a description of table columns available in a catalog.Each column description has the following columns:
- TABLE_CAT String => table catalog (may be null)
- TABLE_SCHEM String => table schema (may be null)
- TABLE_NAME String => table name
- COLUMN_NAME String => column name
- DATA_TYPE short => SQL type from java.sql.Types
- TYPE_NAME String => Data source dependent type name
- COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
- BUFFER_LENGTH is not used.
- DECIMAL_DIGITS int => the number of fractional digits
- NUM_PREC_RADIX int => Radix (typically either 10 or 2)
- NULLABLE int => is NULL allowed?
- columnNoNulls - might not allow NULL values
- columnNullable - definitely allows NULL values
- columnNullableUnknown - nullability unknown
- REMARKS String => comment describing column (may be null)
- COLUMN_DEF String => default value (may be null)
- SQL_DATA_TYPE int => unused
- SQL_DATETIME_SUB int => unused
- CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
- ORDINAL_POSITION int => index of column in table (starting at 1)
- IS_NULLABLE String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.
- Parameters:
tableName
- a table name pattern- Returns:
- a Vector of Records.
- Throws:
DatabaseException
-
getAllColumnNames
public Vector getAllColumnNames(String creatorName, String tableName) throws DatabaseException
Get a description of table columns available in a catalog.Each column description has the following columns:
- TABLE_CAT String => table catalog (may be null)
- TABLE_SCHEM String => table schema (may be null)
- TABLE_NAME String => table name
- COLUMN_NAME String => column name
- DATA_TYPE short => SQL type from java.sql.Types
- TYPE_NAME String => Data source dependent type name
- COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
- BUFFER_LENGTH is not used.
- DECIMAL_DIGITS int => the number of fractional digits
- NUM_PREC_RADIX int => Radix (typically either 10 or 2)
- NULLABLE int => is NULL allowed?
- columnNoNulls - might not allow NULL values
- columnNullable - definitely allows NULL values
- columnNullableUnknown - nullability unknown
- REMARKS String => comment describing column (may be null)
- COLUMN_DEF String => default value (may be null)
- SQL_DATA_TYPE int => unused
- SQL_DATETIME_SUB int => unused
- CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
- ORDINAL_POSITION int => index of column in table (starting at 1)
- IS_NULLABLE String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.
- Parameters:
creatorName
- a schema name pattern; "" retrieves those without a schematableName
- a table name pattern- Returns:
- a Vector of Records.
- Throws:
DatabaseException
-
getAllTableNames
public Vector getAllTableNames() throws DatabaseException
Get a description of tables available in a catalog.Each table description has the following columns:
- TABLE_CAT String => table catalog (may be null)
- TABLE_SCHEM String => table schema (may be null)
- TABLE_NAME String => table name
- TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
- REMARKS String => explanatory comment on the table
Note: Some databases may not return information for all tables.
- Returns:
- a Vector of Records.
- Throws:
DatabaseException
-
getAllTableNames
public Vector getAllTableNames(String creatorName) throws DatabaseException
Get a description of table columns available in a catalog.Each column description has the following columns:
- TABLE_CAT String => table catalog (may be null)
- TABLE_SCHEM String => table schema (may be null)
- TABLE_NAME String => table name
- COLUMN_NAME String => column name
- DATA_TYPE short => SQL type from java.sql.Types
- TYPE_NAME String => Data source dependent type name
- COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
- BUFFER_LENGTH is not used.
- DECIMAL_DIGITS int => the number of fractional digits
- NUM_PREC_RADIX int => Radix (typically either 10 or 2)
- NULLABLE int => is NULL allowed?
- columnNoNulls - might not allow NULL values
- columnNullable - definitely allows NULL values
- columnNullableUnknown - nullability unknown
- REMARKS String => comment describing column (may be null)
- COLUMN_DEF String => default value (may be null)
- SQL_DATA_TYPE int => unused
- SQL_DATETIME_SUB int => unused
- CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
- ORDINAL_POSITION int => index of column in table (starting at 1)
- IS_NULLABLE String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.
- Parameters:
creatorName
- a schema name pattern; "" retrieves those without a schema- Returns:
- a Vector of Records.
- Throws:
DatabaseException
-
getColumnInfo
public Vector getColumnInfo(String catalog, String schema, String tableName, String columnName) throws DatabaseException
Get a description of table columns available in a catalog.Only column descriptions matching the catalog, schema, table and column name criteria are returned. They are ordered by TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
Each column description has the following columns:
- TABLE_CAT String => table catalog (may be null)
- TABLE_SCHEM String => table schema (may be null)
- TABLE_NAME String => table name
- COLUMN_NAME String => column name
- DATA_TYPE short => SQL type from java.sql.Types
- TYPE_NAME String => Data source dependent type name
- COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
- BUFFER_LENGTH is not used.
- DECIMAL_DIGITS int => the number of fractional digits
- NUM_PREC_RADIX int => Radix (typically either 10 or 2)
- NULLABLE int => is NULL allowed?
- columnNoNulls - might not allow NULL values
- columnNullable - definitely allows NULL values
- columnNullableUnknown - nullability unknown
- REMARKS String => comment describing column (may be null)
- COLUMN_DEF String => default value (may be null)
- SQL_DATA_TYPE int => unused
- SQL_DATETIME_SUB int => unused
- CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
- ORDINAL_POSITION int => index of column in table (starting at 1)
- IS_NULLABLE String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.
- Parameters:
catalog
- a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteriaschema
- a schema name pattern; "" retrieves those without a schematableName
- a table name patterncolumnName
- a column name pattern- Returns:
- a Vector of Records.
- Throws:
DatabaseException
-
getSession
public org.eclipse.persistence.internal.sessions.AbstractSession getSession()
-
getTableInfo
public Vector getTableInfo(String catalog, String schema, String tableName, String[] types) throws DatabaseException
Get a description of tables available in a catalog.Only table descriptions matching the catalog, schema, table name and type criteria are returned. They are ordered by TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
Each table description has the following columns:
- TABLE_CAT String => table catalog (may be null)
- TABLE_SCHEM String => table schema (may be null)
- TABLE_NAME String => table name
- TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
- REMARKS String => explanatory comment on the table
Note: Some databases may not return information for all tables.
- Parameters:
catalog
- a catalog name; "" retrieves those without a catalog; null means drop catalog name from the selection criteriaschema
- a schema name pattern; "" retrieves those without a schematableName
- a table name patterntypes
- a list of table types to include; null returns all types- Returns:
- a Vector of Records.
- Throws:
DatabaseException
-
outputDDLToDatabase
public void outputDDLToDatabase()
PUBLIC: Output all DDL statements directly to the database.
-
outputDDLToFile
public void outputDDLToFile(String fileName)
PUBLIC: Output all DDL statements to a file writer specified by the name in the parameter.
-
outputCreateDDLToFile
public void outputCreateDDLToFile(String fileName)
-
outputDropDDLToFile
public void outputDropDDLToFile(String fileName)
-
outputDDLToWriter
public void outputDDLToWriter(Writer schemaWriter)
PUBLIC: Output all DDL statements to a writer specified in the parameter.
-
outputCreateDDLToWriter
public void outputCreateDDLToWriter(Writer createWriter)
-
outputDropDDLToWriter
public void outputDropDDLToWriter(Writer dropWriter)
-
replaceObject
public void replaceObject(DatabaseObjectDefinition databaseDefinition) throws EclipseLinkException
Use the definition object to drop and recreate the schema entity on the database. This is used for dropping tables, views, procedures ... etc ... This handles and ignore any database error while dropping in case the object did not previously exist.- Throws:
EclipseLinkException
-
createDefaultTables
public void createDefaultTables(boolean generateFKConstraints)
Create the default table schema for the project this session associated with.
-
dropDatabaseSchemas
public void dropDatabaseSchemas()
INTERNAL: Iterate over the schemas that need to be dropped.
-
dropDefaultTables
public void dropDefaultTables()
Create the default table schema for the project this session associated with.
-
replaceDefaultTables
public void replaceDefaultTables() throws EclipseLinkException
Drop and recreate the default table schema for the project this session associated with.- Throws:
EclipseLinkException
-
replaceDefaultTables
public void replaceDefaultTables(boolean createSequenceTables, boolean generateFKConstraints) throws EclipseLinkException
Drop and recreate the default table schema for the project this session associated with.- Throws:
EclipseLinkException
-
replaceDefaultTables
public void replaceDefaultTables(boolean createSequenceTables, boolean createSequences, boolean generateFKConstraints) throws EclipseLinkException
Drop and recreate the default table schema for the project this session associated with.- Throws:
EclipseLinkException
-
setSession
public void setSession(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl session)
-
shouldWriteToDatabase
public boolean shouldWriteToDatabase()
PUBLIC: Return true if this SchemaManager should write to the database directly
-
alterSequence
public void alterSequence(SequenceDefinition sequenceDefinition) throws EclipseLinkException
Use the definition to alter sequence.- Throws:
EclipseLinkException
-
extendDefaultTables
public void extendDefaultTables(boolean generateFKConstraints) throws EclipseLinkException
Create or extend the default table schema for the project this session associated with.- Throws:
EclipseLinkException
-
-