public class SchemaManager
extends java.lang.Object
Purpose: Define all user level protocol for development time database manipulation.
Responsibilities:
Modifier and Type | Field and Description |
---|---|
protected boolean |
createDatabaseSchemas
Flag to determine if database schemas should be created during DDL generation
|
protected java.util.HashSet<java.lang.String> |
createdDatabaseSchemas |
protected java.util.HashSet<java.lang.String> |
createdDatabaseSchemasOnDatabase |
protected java.io.Writer |
createSchemaWriter |
protected boolean |
createSQLFiles |
protected TableCreator |
defaultTableCreator |
protected java.util.HashMap<java.lang.String,DatabaseObjectDefinition> |
dropDatabaseSchemas |
protected java.io.Writer |
dropSchemaWriter |
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.
|
protected org.eclipse.persistence.internal.sessions.DatabaseSessionImpl |
session |
Constructor and Description |
---|
SchemaManager(DatabaseSession session) |
SchemaManager(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl session) |
Modifier and Type | Method and Description |
---|---|
void |
alterSequence(SequenceDefinition sequenceDefinition)
Use the definition to alter sequence.
|
void |
appendToDDLWriter(java.lang.String stringToWrite)
PUBLIC: If the schema manager is writing to a writer, append this string
to that writer.
|
void |
appendToDDLWriter(java.io.Writer schemaWriter,
java.lang.String stringToWrite) |
void |
buildFieldTypes(TableDefinition tableDef)
INTERNAL:
builds the field names based on the type read in from the builder
|
protected SequenceDefinition |
buildSequenceDefinition(Sequence sequence) |
protected java.util.HashSet<SequenceDefinition> |
buildSequenceDefinitions()
INTERNAL:
Build the sequence definitions.
|
boolean |
checkTableExists(TableDefinition table)
Check if the table exists by issuing a select.
|
void |
closeDDLWriter()
PUBLIC:
Close the schema writer.
|
void |
closeDDLWriter(java.io.Writer schemaWriter) |
protected void |
collectDatabaseSchemasForDrop(DatabaseObjectDefinition databaseObjectDefinition)
INTERNAL:
Called when dropping tables.
|
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.
|
protected void |
createOrReplaceSequences(boolean create)
Common implementor for createSequence and replaceSequence
|
protected void |
createOrReplaceSequences(boolean createSequenceTables,
boolean createSequences)
Common implementor for createSequence and replaceSequence, distinguishes between sequence tables and sequence objects
|
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.
|
protected void |
dropSequences()
This will drop the database schemas if managing the database schemas.
|
void |
dropTable(java.lang.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 collected
|
void |
generateStoredProcedures()
PUBLIC:
Use this method to generate stored procedures based on the dynamic SQL generated
for your mappings and descriptors.
|
void |
generateStoredProcedures(java.io.Writer writer)
PUBLIC:
Use this method to generate stored procedures based on the dynamic SQL generated
for your mappings and descriptors.
|
void |
generateStoredProceduresAndAmendmentClass(java.lang.String path,
java.lang.String fullyQualifiedClassName)
PUBLIC:
Use this method to generate stored procedures based on the dynamic SQL generated
for your mappings and descriptors.
|
void |
generateStoredProceduresAndAmendmentClass(java.io.Writer writer,
java.lang.String fullyQualifiedClassName)
PUBLIC:
Use this method to generate stored procedures based on the dynamic SQL generated
for your mappings and descriptors.
|
protected org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor |
getAccessor()
Return the appropriate accessor.
|
java.util.Vector |
getAllColumnNames(java.lang.String tableName)
Get a description of table columns available in a catalog.
|
java.util.Vector |
getAllColumnNames(java.lang.String creatorName,
java.lang.String tableName)
Get a description of table columns available in a catalog.
|
java.util.Vector |
getAllTableNames()
Get a description of tables available in a catalog.
|
java.util.Vector |
getAllTableNames(java.lang.String creatorName)
Get a description of table columns available in a catalog.
|
java.util.Vector |
getColumnInfo(java.lang.String catalog,
java.lang.String schema,
java.lang.String tableName,
java.lang.String columnName)
Get a description of table columns available in a catalog.
|
protected TableCreator |
getDefaultTableCreator(boolean generateFKConstraints)
Construct the default TableCreator.
|
protected java.io.Writer |
getDropSchemaWriter() |
org.eclipse.persistence.internal.sessions.AbstractSession |
getSession() |
java.util.Vector |
getTableInfo(java.lang.String catalog,
java.lang.String schema,
java.lang.String tableName,
java.lang.String[] types)
Get a description of tables available in a catalog.
|
protected java.io.Writer |
getWriter(java.lang.String fileName) |
void |
outputCreateDDLToFile(java.lang.String fileName) |
void |
outputCreateDDLToWriter(java.io.Writer createWriter) |
void |
outputDDLToDatabase()
PUBLIC:
Output all DDL statements directly to the database.
|
void |
outputDDLToFile(java.lang.String fileName)
PUBLIC:
Output all DDL statements to a file writer specified by the name in the parameter.
|
void |
outputDDLToWriter(java.io.Writer schemaWriter)
PUBLIC:
Output all DDL statements to a writer specified in the parameter.
|
void |
outputDropDDLToFile(java.lang.String fileName) |
void |
outputDropDDLToWriter(java.io.Writer dropWriter) |
protected void |
processSequenceDefinition(SequenceDefinition definition,
boolean createTables,
boolean createSequences,
boolean replace,
java.util.HashSet<java.lang.String> createdTableNames,
java.util.HashSet<java.lang.String> droppedTableNames)
Method creates database tables/objects.
|
protected void |
processSequenceDefinitions(boolean createSequenceTables,
boolean createSequences,
boolean replaceSequences)
Common implementor for createSequence and replaceSequence, distinguishes between sequence tables and sequence objects
|
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) |
protected boolean |
shouldCreateDatabaseSchema(DatabaseObjectDefinition databaseObjectDefinition,
java.util.Set<java.lang.String> createdDatabaseSchemas)
INTERNAL:
Returns true if a database schema should be created during ddl generation
for the given databaseObjectDefinition.
|
boolean |
shouldWriteToDatabase()
PUBLIC:
Return true if this SchemaManager should write to the database directly
|
protected org.eclipse.persistence.internal.sessions.DatabaseSessionImpl session
protected java.io.Writer createSchemaWriter
protected java.io.Writer dropSchemaWriter
protected boolean createSQLFiles
protected TableCreator defaultTableCreator
public static boolean FAST_TABLE_CREATOR
public static boolean FORCE_DROP
protected boolean createDatabaseSchemas
protected java.util.HashSet<java.lang.String> createdDatabaseSchemas
protected java.util.HashSet<java.lang.String> createdDatabaseSchemasOnDatabase
protected java.util.HashMap<java.lang.String,DatabaseObjectDefinition> dropDatabaseSchemas
public SchemaManager(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl session)
public SchemaManager(DatabaseSession session)
protected java.io.Writer getDropSchemaWriter()
public void appendToDDLWriter(java.lang.String stringToWrite)
public void appendToDDLWriter(java.io.Writer schemaWriter, java.lang.String stringToWrite)
public void buildFieldTypes(TableDefinition tableDef)
public void closeDDLWriter()
public void closeDDLWriter(java.io.Writer schemaWriter)
protected void collectDatabaseSchemasForDrop(DatabaseObjectDefinition databaseObjectDefinition)
public void createConstraints(TableDefinition tableDefinition) throws EclipseLinkException
EclipseLinkException
public void createObject(DatabaseObjectDefinition databaseObjectDefinition) throws EclipseLinkException
EclipseLinkException
public void createSequences() throws EclipseLinkException
EclipseLinkException
public void setCreateDatabaseSchemas(boolean createDatabaseSchemas)
public void setCreateSQLFiles(boolean genFlag)
public void replaceSequences() throws EclipseLinkException
EclipseLinkException
protected void createOrReplaceSequences(boolean create) throws EclipseLinkException
create
- - true to create the sequences, false to replace them (dropped then create)EclipseLinkException
protected void createOrReplaceSequences(boolean createSequenceTables, boolean createSequences) throws EclipseLinkException
createSequenceTables
- - true to create the sequences tables, false to replace them (dropped then create)createSequences
- - true to create the sequences objects, false to replace them (dropped then create)EclipseLinkException
protected void dropSequences()
protected void processSequenceDefinition(SequenceDefinition definition, boolean createTables, boolean createSequences, boolean replace, java.util.HashSet<java.lang.String> createdTableNames, java.util.HashSet<java.lang.String> droppedTableNames) throws EclipseLinkException
definition
- - the sequence definitioncreateTables
- - true if table sequence table definitions should be created.createSequences
- - true if the sequence definition should be created,
false if it should be dropped.replace
- - true if table definitions and sequence definitions should be replaced.EclipseLinkException
protected void processSequenceDefinitions(boolean createSequenceTables, boolean createSequences, boolean replaceSequences) throws EclipseLinkException
createSequenceTables
- - true to create the sequences tables, false to replace them (dropped then create)createSequences
- - true to create the sequences objects, false to replace them (dropped then create)replaceSequences
- - true to actually replace, false to drop only.EclipseLinkException
protected java.util.HashSet<SequenceDefinition> buildSequenceDefinitions()
public boolean checkTableExists(TableDefinition table)
protected SequenceDefinition buildSequenceDefinition(Sequence sequence)
public void dropConstraints(TableDefinition tableDefinition) throws EclipseLinkException
EclipseLinkException
public void dropObject(DatabaseObjectDefinition databaseObjectDefinition) throws EclipseLinkException
EclipseLinkException
public void dropTable(java.lang.String tableName) throws EclipseLinkException
EclipseLinkException
public void finalize()
finalize
in class java.lang.Object
public void generateStoredProcedures() throws EclipseLinkException
EclipseLinkException
public void generateStoredProcedures(java.io.Writer writer) throws EclipseLinkException
EclipseLinkException
public void generateStoredProceduresAndAmendmentClass(java.io.Writer writer, java.lang.String fullyQualifiedClassName) throws EclipseLinkException
EclipseLinkException
public void generateStoredProceduresAndAmendmentClass(java.lang.String path, java.lang.String fullyQualifiedClassName) throws EclipseLinkException
EclipseLinkException
protected org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor getAccessor()
public java.util.Vector getAllColumnNames(java.lang.String tableName) throws DatabaseException
Each column description has the following columns:
tableName
- a table name patternDatabaseException
public java.util.Vector getAllColumnNames(java.lang.String creatorName, java.lang.String tableName) throws DatabaseException
Each column description has the following columns:
creatorName
- a schema name pattern; "" retrieves those
without a schematableName
- a table name patternDatabaseException
public java.util.Vector getAllTableNames() throws DatabaseException
Each table description has the following columns:
Note: Some databases may not return information for all tables.
DatabaseException
public java.util.Vector getAllTableNames(java.lang.String creatorName) throws DatabaseException
Each column description has the following columns:
creatorName
- a schema name pattern; "" retrieves those
without a schemaDatabaseException
public java.util.Vector getColumnInfo(java.lang.String catalog, java.lang.String schema, java.lang.String tableName, java.lang.String columnName) throws DatabaseException
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:
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 patternDatabaseException
public org.eclipse.persistence.internal.sessions.AbstractSession getSession()
public java.util.Vector getTableInfo(java.lang.String catalog, java.lang.String schema, java.lang.String tableName, java.lang.String[] types) throws DatabaseException
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:
Note: Some databases may not return information for all tables.
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 typesDatabaseException
public void outputDDLToDatabase()
public void outputDDLToFile(java.lang.String fileName)
public void outputCreateDDLToFile(java.lang.String fileName)
public void outputDropDDLToFile(java.lang.String fileName)
protected java.io.Writer getWriter(java.lang.String fileName)
public void outputDDLToWriter(java.io.Writer schemaWriter)
public void outputCreateDDLToWriter(java.io.Writer createWriter)
public void outputDropDDLToWriter(java.io.Writer dropWriter)
public void replaceObject(DatabaseObjectDefinition databaseDefinition) throws EclipseLinkException
EclipseLinkException
protected TableCreator getDefaultTableCreator(boolean generateFKConstraints)
public void createDefaultTables(boolean generateFKConstraints)
public void dropDatabaseSchemas()
public void dropDefaultTables()
public void replaceDefaultTables() throws EclipseLinkException
EclipseLinkException
public void replaceDefaultTables(boolean createSequenceTables, boolean generateFKConstraints) throws EclipseLinkException
EclipseLinkException
public void replaceDefaultTables(boolean createSequenceTables, boolean createSequences, boolean generateFKConstraints) throws EclipseLinkException
EclipseLinkException
public void setSession(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl session)
protected boolean shouldCreateDatabaseSchema(DatabaseObjectDefinition databaseObjectDefinition, java.util.Set<java.lang.String> createdDatabaseSchemas)
public boolean shouldWriteToDatabase()
public void alterSequence(SequenceDefinition sequenceDefinition) throws EclipseLinkException
EclipseLinkException
public void extendDefaultTables(boolean generateFKConstraints) throws EclipseLinkException
EclipseLinkException