Package org.apache.openjpa.jdbc.schema
Class SchemaGenerator
java.lang.Object
org.apache.openjpa.jdbc.schema.SchemaGenerator
The SchemaGenerator creates
Schema
s matching the current
database. All schemas are added to the current SchemaGroup
.
Note that tables whose name starts with "OPENJPA_" will be not be added
to the database schema. This enables the creation of special tables
that will never be dropped by the SchemaTool
.- Author:
- Abe White
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An event corresponding to the generation of a schema object.static interface
A listener for a potentially lengthy schema generation process. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a listener for schema generation events.void
generateForeignKeys
(String schemaName, String[] tableNames) Deprecated.void
generateForeignKeys
(String schemaName, String tableName, Connection conn, DatabaseMetaData meta) Generates table foreign keys.void
generateForeignKeys
(DBIdentifier schemaName, DBIdentifier[] tableNames) Generate foreign key information for the given schema.void
generateForeignKeys
(DBIdentifier schemaName, DBIdentifier tableName, Connection conn, DatabaseMetaData meta) void
generateIndexes
(String schemaName, String[] tableNames) Deprecated.void
generateIndexes
(String schemaName, String tableName, Connection conn, DatabaseMetaData meta) Deprecated.void
generateIndexes
(DBIdentifier schemaName, DBIdentifier[] tableNames) Generate index information for the given schema.void
generateIndexes
(DBIdentifier schemaName, DBIdentifier tableName, Connection conn, DatabaseMetaData meta) void
generatePrimaryKeys
(String schemaName, String[] tableNames) Deprecated.void
generatePrimaryKeys
(String schemaName, String tableName, Connection conn, DatabaseMetaData meta) Deprecated.void
generatePrimaryKeys
(DBIdentifier schemaName, DBIdentifier[] tableNames) Generate primary key information for the given schema.void
generatePrimaryKeys
(DBIdentifier schemaName, DBIdentifier tableName, Connection conn, DatabaseMetaData meta) void
generateSchema
(String name, String[] tableNames) Deprecated.void
generateSchema
(DBIdentifier name, DBIdentifier[] tableNames) Add a fully-constructedSchema
matching the given database schema to the current group.void
Generate all schemas set in the configuration.void
generateSchemas
(String[] schemasAndTables) Deprecated.void
generateSchemas
(DBIdentifier[] schemasAndTables) Generate the schemas and/or tables named in the given strings.void
generateSequences
(String schemaName, String sequenceName, Connection conn, DatabaseMetaData meta) Deprecated.void
generateSequences
(DBIdentifier schemaName, DBIdentifier sequenceName, Connection conn, DatabaseMetaData meta) void
generateTables
(String schemaName, String tableName, Connection conn, DatabaseMetaData meta) Deprecated.void
generateTables
(DBIdentifier schemaName, DBIdentifier tableName, Connection conn, DatabaseMetaData meta) Adds all tables matching the given name pattern to the schema.boolean
Return whether foreign keys should be generated.boolean
Return whether indexes should be generated.boolean
Whether to generate info on special tables used by OpenJPA components for bookkeeping.boolean
Return whether primary keys should be generated.Return the current schema group.boolean
Return whether sequences should be generated.boolean
Removes a schema generation listener for schema events.void
setForeignKeys
(boolean fks) Set whether foreign keys should be generated.void
setIndexes
(boolean indexes) Set whether indexes should be generated.void
setOpenJPATables
(boolean openjpaTables) Whether to generate info on special tables used by OpenJPA components for bookkeeping.void
setPrimaryKeys
(boolean pks) Set whether primary keys should be generated.void
setSchemaGroup
(SchemaGroup group) Set the schema group to add generated schemas to.void
setSequences
(boolean seqs) Set whether sequences should be generated.
-
Constructor Details
-
SchemaGenerator
Constructor.- Parameters:
conf
- configuration for connecting to the data store
-
-
Method Details
-
getIndexes
public boolean getIndexes()Return whether indexes should be generated. Defaults to true. -
setIndexes
public void setIndexes(boolean indexes) Set whether indexes should be generated. Defaults to true. -
getForeignKeys
public boolean getForeignKeys()Return whether foreign keys should be generated. Defaults to true. -
setForeignKeys
public void setForeignKeys(boolean fks) Set whether foreign keys should be generated. Defaults to true. -
getPrimaryKeys
public boolean getPrimaryKeys()Return whether primary keys should be generated. Defaults to true. -
setPrimaryKeys
public void setPrimaryKeys(boolean pks) Set whether primary keys should be generated. Defaults to true. -
getSequences
public boolean getSequences()Return whether sequences should be generated. Defaults to true. -
setSequences
public void setSequences(boolean seqs) Set whether sequences should be generated. Defaults to true. -
getOpenJPATables
public boolean getOpenJPATables()Whether to generate info on special tables used by OpenJPA components for bookkeeping. Defaults to true. -
setOpenJPATables
public void setOpenJPATables(boolean openjpaTables) Whether to generate info on special tables used by OpenJPA components for bookkeeping. Defaults to true. -
getSchemaGroup
Return the current schema group. -
setSchemaGroup
Set the schema group to add generated schemas to. -
generateSchemas
Generate all schemas set in the configuration. This method also callsgenerateIndexes(java.lang.String, java.lang.String[])
,generatePrimaryKeys(java.lang.String, java.lang.String[])
, andgenerateForeignKeys(java.lang.String, java.lang.String[])
automatically.- Throws:
SQLException
-
generateSchemas
Deprecated.- Throws:
SQLException
-
generateSchemas
Generate the schemas and/or tables named in the given strings. This method callsgenerateIndexes(java.lang.String, java.lang.String[])
,generatePrimaryKeys(java.lang.String, java.lang.String[])
, andgenerateForeignKeys(java.lang.String, java.lang.String[])
automatically.- Throws:
SQLException
-
generateSchema
Deprecated.- Parameters:
name
-tableNames
-- Throws:
SQLException
-
generateSchema
Add a fully-constructedSchema
matching the given database schema to the current group. No foreign keys are generated because some keys might span schemas. You must callgeneratePrimaryKeys(java.lang.String, java.lang.String[])
,generateIndexes(java.lang.String, java.lang.String[])
, andgenerateForeignKeys(java.lang.String, java.lang.String[])
separately.- Parameters:
name
- the database name of the schema, or null for all schemastableNames
- a list of tables to generate in the schema, or null to generate all tables- Throws:
SQLException
-
generatePrimaryKeys
@Deprecated public void generatePrimaryKeys(String schemaName, String[] tableNames) throws SQLException Deprecated.Generate primary key information for the given schema. This method must be called in addition togenerateSchema(java.lang.String, java.lang.String[])
. It should only be called after all schemas are generated. The schema name and tables array can be null to indicate that indexes should be generated for all schemas and/or tables.- Throws:
SQLException
-
generatePrimaryKeys
public void generatePrimaryKeys(DBIdentifier schemaName, DBIdentifier[] tableNames) throws SQLException Generate primary key information for the given schema. This method must be called in addition togenerateSchema(java.lang.String, java.lang.String[])
. It should only be called after all schemas are generated. The schema name and tables array can be null to indicate that indexes should be generated for all schemas and/or tables.- Throws:
SQLException
-
generateIndexes
Deprecated.Generate index information for the given schema. This method must be called in addition togenerateSchema(java.lang.String, java.lang.String[])
. It should only be called after all schemas are generated. The schema name and tables array can be null to indicate that indexes should be generated for all schemas and/or tables.- Throws:
SQLException
-
generateIndexes
Generate index information for the given schema. This method must be called in addition togenerateSchema(java.lang.String, java.lang.String[])
. It should only be called after all schemas are generated. The schema name and tables array can be null to indicate that indexes should be generated for all schemas and/or tables.- Throws:
SQLException
-
generateForeignKeys
@Deprecated public void generateForeignKeys(String schemaName, String[] tableNames) throws SQLException Deprecated.Generate foreign key information for the given schema. This method must be called in addition togenerateSchema(java.lang.String, java.lang.String[])
. It should only be called after all schemas are generated. The schema name and tables array can be null to indicate that indexes should be generated for all schemas and/or tables.- Throws:
SQLException
-
generateForeignKeys
public void generateForeignKeys(DBIdentifier schemaName, DBIdentifier[] tableNames) throws SQLException Generate foreign key information for the given schema. This method must be called in addition togenerateSchema(java.lang.String, java.lang.String[])
. It should only be called after all schemas are generated. The schema name and tables array can be null to indicate that indexes should be generated for all schemas and/or tables.- Throws:
SQLException
-
generateTables
@Deprecated public void generateTables(String schemaName, String tableName, Connection conn, DatabaseMetaData meta) throws SQLException Deprecated.- Throws:
SQLException
-
generateTables
public void generateTables(DBIdentifier schemaName, DBIdentifier tableName, Connection conn, DatabaseMetaData meta) throws SQLException Adds all tables matching the given name pattern to the schema.- Throws:
SQLException
-
generatePrimaryKeys
@Deprecated public void generatePrimaryKeys(String schemaName, String tableName, Connection conn, DatabaseMetaData meta) throws SQLException Deprecated.Generates table primary keys.- Throws:
SQLException
-
generatePrimaryKeys
public void generatePrimaryKeys(DBIdentifier schemaName, DBIdentifier tableName, Connection conn, DatabaseMetaData meta) throws SQLException - Throws:
SQLException
-
generateIndexes
@Deprecated public void generateIndexes(String schemaName, String tableName, Connection conn, DatabaseMetaData meta) throws SQLException Deprecated.Generates table indexes.- Throws:
SQLException
-
generateIndexes
public void generateIndexes(DBIdentifier schemaName, DBIdentifier tableName, Connection conn, DatabaseMetaData meta) throws SQLException - Throws:
SQLException
-
generateForeignKeys
public void generateForeignKeys(String schemaName, String tableName, Connection conn, DatabaseMetaData meta) throws SQLException Generates table foreign keys.- Throws:
SQLException
-
generateForeignKeys
public void generateForeignKeys(DBIdentifier schemaName, DBIdentifier tableName, Connection conn, DatabaseMetaData meta) throws SQLException - Throws:
SQLException
-
generateSequences
@Deprecated public void generateSequences(String schemaName, String sequenceName, Connection conn, DatabaseMetaData meta) throws SQLException Deprecated.Adds all sequences matching the given name pattern to the schema.- Throws:
SQLException
-
generateSequences
public void generateSequences(DBIdentifier schemaName, DBIdentifier sequenceName, Connection conn, DatabaseMetaData meta) throws SQLException - Throws:
SQLException
-
addListener
Adds a listener for schema generation events.- Parameters:
l
- the listener to add
-
removeListener
Removes a schema generation listener for schema events.- Parameters:
l
- the listener to remove- Returns:
- true if it was successfully removed
-