Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.access
Class DbGenerator

    java.lang.Object
      org.apache.cayenne.access.DbGenerator

    public class DbGenerator

extends java.lang.Object

Utility class that generates database schema based on Cayenne mapping. It is a logical counterpart of DbLoader class.

Field Summary
`protected DbAdapter` | `adapter`
`protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>` | `createConstraints`
`protected java.util.List<java.lang.String>` | `createPK`
`protected java.util.Map<java.lang.String,java.lang.String>` | `createTables`
`protected java.util.List<DbEntity>` | `dbEntitiesInInsertOrder` Contains all DbEntities ordered considering their interdependencies.
`protected java.util.List<DbEntity>` | `dbEntitiesRequiringAutoPK`
`protected DataDomain` | `domain`
`protected java.util.List<java.lang.String>` | `dropPK`
`protected java.util.Map<java.lang.String,java.util.Collection<java.lang.String>>` | `dropTables`
`protected ValidationResult` | `failures`
`protected JdbcEventLogger` | `jdbcEventLogger`
`protected DataMap` | `map`
`protected boolean` | `shouldCreateFKConstraints`
`protected boolean` | `shouldCreatePKSupport`
`protected boolean` | `shouldCreateTables`
`protected boolean` | `shouldDropPKSupport`
`protected boolean` | `shouldDropTables`

Constructor Summary
`DbGenerator(DbAdapter adapter, DataMap map)` Deprecated. since 3.1 use `DbGenerator(DbAdapter, DataMap, JdbcEventLogger)`
`DbGenerator(DbAdapter adapter, DataMap map, java.util.Collection<DbEntity> excludedEntities)` Deprecated. since 3.1 use `DbGenerator(DbAdapter, DataMap, Collection, DataDomain, JdbcEventLogger)`
`DbGenerator(DbAdapter adapter, DataMap map, java.util.Collection<DbEntity> excludedEntities, DataDomain domain, JdbcEventLogger logger)` Creates and initializes new DbGenerator instance.
`DbGenerator(DbAdapter adapter, DataMap map, JdbcEventLogger logger)`
`DbGenerator(DbAdapter adapter, DataMap map, JdbcEventLogger logger, java.util.Collection<DbEntity> excludedEntities)`

Method Summary
`protected void` | `buildStatements()` Creates and stores internally a set of statements for database schema creation, ignoring configured schema creation preferences.
`java.util.List<java.lang.String>` | `configuredStatements()` Returns a list of all schema statements that should be executed with the current configuration.
`java.util.List<java.lang.String>` | `createConstraintsQueries(DbEntity table)` Creates FK and UNIQUE constraint statements for a given table.
`DbAdapter` | `getAdapter()` Returns DbAdapter associated with this DbGenerator.
`DataDomain` | `getDomain()` Returns a DataDomain used by the DbGenerator to detect cross-database relationships.
`ValidationResult` | `getFailures()` Returns an object representing a collection of failures that occurred on the last "runGenerator" invocation, or null if there were no failures.
`boolean` | `isEmpty(boolean respectConfiguredSettings)` Returns `true` if there is nothing to be done by this generator.
`protected void` | `resetToDefaults()`
`void` | `runGenerator(javax.sql.DataSource ds)` Executes a set of commands to drop/create database objects.
`void` | `runGenerator(DataSourceInfo dsi)` Creates a temporary DataSource out of DataSourceInfo and invokes `public void runGenerator(DataSource ds)`.
`protected boolean` | `safeExecute(java.sql.Connection connection, java.lang.String sql)` Builds and executes a SQL statement, catching and storing SQL exceptions resulting from invalid SQL.
`void` | `setShouldCreateFKConstraints(boolean shouldCreateFKConstraints)`
`void` | `setShouldCreatePKSupport(boolean shouldCreatePKSupport)`
`void` | `setShouldCreateTables(boolean shouldCreateTables)`
`void` | `setShouldDropPKSupport(boolean shouldDropPKSupport)`
`void` | `setShouldDropTables(boolean shouldDropTables)`
`boolean` | `shouldCreateFKConstraints()`
`boolean` | `shouldCreatePKSupport()` Returns whether DbGenerator is configured to create primary key support for DataMap entities.
`boolean` | `shouldCreateTables()` Returns whether DbGenerator is configured to create tables for DataMap entities.
`boolean` | `shouldDropPKSupport()`
`boolean` | `shouldDropTables()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### adapter

    protected DbAdapter adapter

### map

    protected DataMap map

### domain

    protected DataDomain domain

### jdbcEventLogger

    protected JdbcEventLogger jdbcEventLogger

### dropTables

    protected java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> dropTables

### createTables

    protected java.util.Map<java.lang.String,java.lang.String> createTables

### createConstraints

    protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> createConstraints

### createPK

    protected java.util.List<java.lang.String> createPK

### dropPK

    protected java.util.List<java.lang.String> dropPK

### dbEntitiesInInsertOrder

    protected java.util.List<DbEntity> dbEntitiesInInsertOrder

  Contains all DbEntities ordered considering their interdependencies. DerivedDbEntities are filtered out of this list.

### dbEntitiesRequiringAutoPK

    protected java.util.List<DbEntity> dbEntitiesRequiringAutoPK

### shouldDropTables

    protected boolean shouldDropTables

### shouldCreateTables

    protected boolean shouldCreateTables

### shouldDropPKSupport

    protected boolean shouldDropPKSupport

### shouldCreatePKSupport

    protected boolean shouldCreatePKSupport

### shouldCreateFKConstraints

    protected boolean shouldCreateFKConstraints

### failures

    protected ValidationResult failures

Constructor Detail

### DbGenerator

    @Deprecated
    public DbGenerator(DbAdapter adapter,
                                  DataMap map)

  Deprecated. since 3.1 use `DbGenerator(DbAdapter, DataMap, JdbcEventLogger)`

  Creates and initializes new DbGenerator.

### DbGenerator

    @Deprecated
    public DbGenerator(DbAdapter adapter,
                                  DataMap map,
                                  java.util.Collection<DbEntity> excludedEntities)

  Deprecated. since 3.1 use `DbGenerator(DbAdapter, DataMap, Collection, DataDomain, JdbcEventLogger)`

  Creates and initializes new DbGenerator instance.

  Parameters:
    `adapter` - DbAdapter corresponding to the database
    `map` - DataMap whose entities will be used in schema generation
    `excludedEntities` - entities that should be ignored during schema generation

### DbGenerator

    public DbGenerator(DbAdapter adapter,
                       DataMap map,
                       JdbcEventLogger logger)

Since:
  3.1

### DbGenerator

    public DbGenerator(DbAdapter adapter,
                       DataMap map,
                       JdbcEventLogger logger,
                       java.util.Collection<DbEntity> excludedEntities)

Since:
  3.1

### DbGenerator

    public DbGenerator(DbAdapter adapter,
                       DataMap map,
                       java.util.Collection<DbEntity> excludedEntities,
                       DataDomain domain,
                       JdbcEventLogger logger)

  Creates and initializes new DbGenerator instance.

  Parameters:
    `adapter` - DbAdapter corresponding to the database
    `map` - DataMap whose entities will be used in schema generation
    `excludedEntities` - entities that should be ignored during schema generation
    `domain` - optional DataDomain used to detect cross-database relationships.
  Since:
    3.1

Method Detail

### resetToDefaults

    protected void resetToDefaults()

### buildStatements

    protected void buildStatements()

  Creates and stores internally a set of statements for database schema creation, ignoring configured schema creation preferences. Statements are NOT executed in this method.

### isEmpty

    public boolean isEmpty(boolean respectConfiguredSettings)

  Returns `true` if there is nothing to be done by this generator. If `respectConfiguredSettings` is `true`, checks are done applying currently configured settings, otherwise check is done, assuming that all possible generated objects.

### getAdapter

    public DbAdapter getAdapter()

  Returns DbAdapter associated with this DbGenerator.

### configuredStatements

    public java.util.List<java.lang.String> configuredStatements()

  Returns a list of all schema statements that should be executed with the current configuration.

### runGenerator

    public void runGenerator(DataSourceInfo dsi)
                      throws java.lang.Exception

  Creates a temporary DataSource out of DataSourceInfo and invokes `public void runGenerator(DataSource ds)`.

  Throws:
    `java.lang.Exception`

### runGenerator

    public void runGenerator(javax.sql.DataSource ds)
                      throws java.lang.Exception

  Executes a set of commands to drop/create database objects. This is the main worker method of DbGenerator. Command set is built based on pre-configured generator settings.

  Throws:
    `java.lang.Exception`

### safeExecute

    protected boolean safeExecute(java.sql.Connection connection,
                                  java.lang.String sql)
                           throws java.sql.SQLException

  Builds and executes a SQL statement, catching and storing SQL exceptions resulting from invalid SQL. Only non-recoverable exceptions are rethrown.

  Throws:
    `java.sql.SQLException`
  Since:
    1.1

### createConstraintsQueries

    public java.util.List<java.lang.String> createConstraintsQueries(DbEntity table)

  Creates FK and UNIQUE constraint statements for a given table.

  Since:
    3.0

### getFailures

    public ValidationResult getFailures()

  Returns an object representing a collection of failures that occurred on the last "runGenerator" invocation, or null if there were no failures. Failures usually indicate problems with generated DDL (such as "create...", "drop...", etc.) and usually happen due to the DataMap being out of sync with the database.

  Since:
    1.1

### shouldCreatePKSupport

    public boolean shouldCreatePKSupport()

  Returns whether DbGenerator is configured to create primary key support for DataMap entities.

### shouldCreateTables

    public boolean shouldCreateTables()

  Returns whether DbGenerator is configured to create tables for DataMap entities.

### shouldDropPKSupport

    public boolean shouldDropPKSupport()

### shouldDropTables

    public boolean shouldDropTables()

### shouldCreateFKConstraints

    public boolean shouldCreateFKConstraints()

### setShouldCreatePKSupport

    public void setShouldCreatePKSupport(boolean shouldCreatePKSupport)

### setShouldCreateTables

    public void setShouldCreateTables(boolean shouldCreateTables)

### setShouldDropPKSupport

    public void setShouldDropPKSupport(boolean shouldDropPKSupport)

### setShouldDropTables

    public void setShouldDropTables(boolean shouldDropTables)

### setShouldCreateFKConstraints

    public void setShouldCreateFKConstraints(boolean shouldCreateFKConstraints)

### getDomain

    public DataDomain getDomain()

  Returns a DataDomain used by the DbGenerator to detect cross-database relationships. By default DataDomain is null.

  Since:
    1.2

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2012 Apache Cayenne. All Rights Reserved.