Class SchemaGenerator


  • public class SchemaGenerator
    extends java.lang.Object
    The SchemaGenerator creates Schemas 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
    • Constructor Detail

      • SchemaGenerator

        public SchemaGenerator​(JDBCConfiguration conf)
        Constructor.
        Parameters:
        conf - configuration for connecting to the data store
    • Method Detail

      • 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

        public SchemaGroup getSchemaGroup()
        Return the current schema group.
      • setSchemaGroup

        public void setSchemaGroup​(SchemaGroup group)
        Set the schema group to add generated schemas to.
      • generateSchemas

        @Deprecated
        public void generateSchemas​(java.lang.String[] schemasAndTables)
                             throws java.sql.SQLException
        Deprecated.
        Throws:
        java.sql.SQLException
      • generateSchema

        @Deprecated
        public void generateSchema​(java.lang.String name,
                                   java.lang.String[] tableNames)
                            throws java.sql.SQLException
        Deprecated.
        Parameters:
        name -
        tableNames -
        Throws:
        java.sql.SQLException
      • generatePrimaryKeys

        @Deprecated
        public void generatePrimaryKeys​(java.lang.String schemaName,
                                        java.lang.String[] tableNames)
                                 throws java.sql.SQLException
        Deprecated.
        Generate primary key information for the given schema. This method must be called in addition to generateSchema(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:
        java.sql.SQLException
      • generatePrimaryKeys

        public void generatePrimaryKeys​(DBIdentifier schemaName,
                                        DBIdentifier[] tableNames)
                                 throws java.sql.SQLException
        Generate primary key information for the given schema. This method must be called in addition to generateSchema(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:
        java.sql.SQLException
      • generateIndexes

        @Deprecated
        public void generateIndexes​(java.lang.String schemaName,
                                    java.lang.String[] tableNames)
                             throws java.sql.SQLException
        Deprecated.
        Generate index information for the given schema. This method must be called in addition to generateSchema(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:
        java.sql.SQLException
      • generateIndexes

        public void generateIndexes​(DBIdentifier schemaName,
                                    DBIdentifier[] tableNames)
                             throws java.sql.SQLException
        Generate index information for the given schema. This method must be called in addition to generateSchema(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:
        java.sql.SQLException
      • generateForeignKeys

        @Deprecated
        public void generateForeignKeys​(java.lang.String schemaName,
                                        java.lang.String[] tableNames)
                                 throws java.sql.SQLException
        Deprecated.
        Generate foreign key information for the given schema. This method must be called in addition to generateSchema(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:
        java.sql.SQLException
      • generateForeignKeys

        public void generateForeignKeys​(DBIdentifier schemaName,
                                        DBIdentifier[] tableNames)
                                 throws java.sql.SQLException
        Generate foreign key information for the given schema. This method must be called in addition to generateSchema(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:
        java.sql.SQLException
      • generateTables

        @Deprecated
        public void generateTables​(java.lang.String schemaName,
                                   java.lang.String tableName,
                                   java.sql.Connection conn,
                                   java.sql.DatabaseMetaData meta)
                            throws java.sql.SQLException
        Deprecated.
        Throws:
        java.sql.SQLException
      • generateTables

        public void generateTables​(DBIdentifier schemaName,
                                   DBIdentifier tableName,
                                   java.sql.Connection conn,
                                   java.sql.DatabaseMetaData meta)
                            throws java.sql.SQLException
        Adds all tables matching the given name pattern to the schema.
        Throws:
        java.sql.SQLException
      • generatePrimaryKeys

        @Deprecated
        public void generatePrimaryKeys​(java.lang.String schemaName,
                                        java.lang.String tableName,
                                        java.sql.Connection conn,
                                        java.sql.DatabaseMetaData meta)
                                 throws java.sql.SQLException
        Deprecated.
        Generates table primary keys.
        Throws:
        java.sql.SQLException
      • generatePrimaryKeys

        public void generatePrimaryKeys​(DBIdentifier schemaName,
                                        DBIdentifier tableName,
                                        java.sql.Connection conn,
                                        java.sql.DatabaseMetaData meta)
                                 throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • generateIndexes

        @Deprecated
        public void generateIndexes​(java.lang.String schemaName,
                                    java.lang.String tableName,
                                    java.sql.Connection conn,
                                    java.sql.DatabaseMetaData meta)
                             throws java.sql.SQLException
        Deprecated.
        Generates table indexes.
        Throws:
        java.sql.SQLException
      • generateIndexes

        public void generateIndexes​(DBIdentifier schemaName,
                                    DBIdentifier tableName,
                                    java.sql.Connection conn,
                                    java.sql.DatabaseMetaData meta)
                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • generateForeignKeys

        public void generateForeignKeys​(java.lang.String schemaName,
                                        java.lang.String tableName,
                                        java.sql.Connection conn,
                                        java.sql.DatabaseMetaData meta)
                                 throws java.sql.SQLException
        Generates table foreign keys.
        Throws:
        java.sql.SQLException
      • generateForeignKeys

        public void generateForeignKeys​(DBIdentifier schemaName,
                                        DBIdentifier tableName,
                                        java.sql.Connection conn,
                                        java.sql.DatabaseMetaData meta)
                                 throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • generateSequences

        @Deprecated
        public void generateSequences​(java.lang.String schemaName,
                                      java.lang.String sequenceName,
                                      java.sql.Connection conn,
                                      java.sql.DatabaseMetaData meta)
                               throws java.sql.SQLException
        Deprecated.
        Adds all sequences matching the given name pattern to the schema.
        Throws:
        java.sql.SQLException
      • generateSequences

        public void generateSequences​(DBIdentifier schemaName,
                                      DBIdentifier sequenceName,
                                      java.sql.Connection conn,
                                      java.sql.DatabaseMetaData meta)
                               throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • addListener

        public void addListener​(SchemaGenerator.Listener l)
        Adds a listener for schema generation events.
        Parameters:
        l - the listener to add
      • removeListener

        public boolean removeListener​(SchemaGenerator.Listener l)
        Removes a schema generation listener for schema events.
        Parameters:
        l - the listener to remove
        Returns:
        true if it was successfully removed