Package org.apache.cayenne.access
Class DbGenerator
java.lang.Object
org.apache.cayenne.access.DbGenerator
Utility class that generates database schema based on Cayenne mapping. It is
 a logical counterpart of DbLoader class.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected DbAdapterContains all DbEntities ordered considering their interdependencies.protected DataDomainprotected Map<String,Collection<String>> protected ValidationResultprotected JdbcEventLoggerprotected DataMapprotected booleanprotected booleanprotected booleanprotected booleanprotected boolean
- 
Constructor SummaryConstructorsConstructorDescriptionDbGenerator(DbAdapter adapter, DataMap map, 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, Collection<DbEntity> excludedEntities) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidCreates and stores internally a set of statements for database schema creation, ignoring configured schema creation preferences.Returns a list of all schema statements that should be executed with the current configuration.createConstraintsQueries(DbEntity table) Creates FK and UNIQUE constraint statements for a given table.Returns DbAdapter associated with this DbGenerator.Returns a DataDomain used by the DbGenerator to detect cross-database relationships.Returns an object representing a collection of failures that occurred on the last "runGenerator" invocation, or null if there were no failures.booleanisEmpty(boolean respectConfiguredSettings) Returnstrueif there is nothing to be done by this generator.protected voidvoidExecutes a set of commands to drop/create database objects.protected booleansafeExecute(Connection connection, String sql) Builds and executes a SQL statement, catching and storing SQL exceptions resulting from invalid SQL.voidsetShouldCreateFKConstraints(boolean shouldCreateFKConstraints) voidsetShouldCreatePKSupport(boolean shouldCreatePKSupport) voidsetShouldCreateTables(boolean shouldCreateTables) voidsetShouldDropPKSupport(boolean shouldDropPKSupport) voidsetShouldDropTables(boolean shouldDropTables) booleanbooleanReturns whether DbGenerator is configured to create primary key support for DataMap entities.booleanReturns whether DbGenerator is configured to create tables for DataMap entities.booleanboolean
- 
Field Details- 
adapter
- 
map
- 
domain
- 
jdbcEventLogger
- 
dropTables
- 
createTables
- 
createConstraints
- 
createPK
- 
dropPK
- 
dbEntitiesInInsertOrderContains all DbEntities ordered considering their interdependencies. DerivedDbEntities are filtered out of this list.
- 
dbEntitiesRequiringAutoPK
- 
shouldDropTablesprotected boolean shouldDropTables
- 
shouldCreateTablesprotected boolean shouldCreateTables
- 
shouldDropPKSupportprotected boolean shouldDropPKSupport
- 
shouldCreatePKSupportprotected boolean shouldCreatePKSupport
- 
shouldCreateFKConstraintsprotected boolean shouldCreateFKConstraints
- 
failures
 
- 
- 
Constructor Details- 
DbGenerator- Since:
- 3.1
 
- 
DbGeneratorpublic DbGenerator(DbAdapter adapter, DataMap map, JdbcEventLogger logger, Collection<DbEntity> excludedEntities) - Since:
- 3.1
 
- 
DbGeneratorpublic DbGenerator(DbAdapter adapter, DataMap map, 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 Details- 
resetToDefaultsprotected void resetToDefaults()
- 
buildStatementsprotected 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.
- 
isEmptypublic boolean isEmpty(boolean respectConfiguredSettings) Returnstrueif there is nothing to be done by this generator. IfrespectConfiguredSettingsistrue, checks are done applying currently configured settings, otherwise check is done, assuming that all possible generated objects.
- 
getAdapterReturns DbAdapter associated with this DbGenerator.
- 
configuredStatementsReturns a list of all schema statements that should be executed with the current configuration.
- 
runGeneratorExecutes 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:
- Exception
 
- 
safeExecuteBuilds and executes a SQL statement, catching and storing SQL exceptions resulting from invalid SQL. Only non-recoverable exceptions are rethrown.- Since:
- 1.1
 
- 
createConstraintsQueriesCreates FK and UNIQUE constraint statements for a given table.- Since:
- 3.0
 
- 
getFailuresReturns 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
 
- 
shouldCreatePKSupportpublic boolean shouldCreatePKSupport()Returns whether DbGenerator is configured to create primary key support for DataMap entities.
- 
shouldCreateTablespublic boolean shouldCreateTables()Returns whether DbGenerator is configured to create tables for DataMap entities.
- 
shouldDropPKSupportpublic boolean shouldDropPKSupport()
- 
shouldDropTablespublic boolean shouldDropTables()
- 
shouldCreateFKConstraintspublic boolean shouldCreateFKConstraints()
- 
setShouldCreatePKSupportpublic void setShouldCreatePKSupport(boolean shouldCreatePKSupport) 
- 
setShouldCreateTablespublic void setShouldCreateTables(boolean shouldCreateTables) 
- 
setShouldDropPKSupportpublic void setShouldDropPKSupport(boolean shouldDropPKSupport) 
- 
setShouldDropTablespublic void setShouldDropTables(boolean shouldDropTables) 
- 
setShouldCreateFKConstraintspublic void setShouldCreateFKConstraints(boolean shouldCreateFKConstraints) 
- 
getDomainReturns a DataDomain used by the DbGenerator to detect cross-database relationships. By default DataDomain is null.- Since:
- 1.2
 
 
-