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 Summary
Modifier and TypeFieldDescriptionprotected DbAdapter
Contains all DbEntities ordered considering their interdependencies.protected DataDomain
protected Map
<String, Collection<String>> protected ValidationResult
protected JdbcEventLogger
protected DataMap
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
-
Constructor Summary
ConstructorDescriptionDbGenerator
(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 Summary
Modifier and TypeMethodDescriptionprotected void
Creates 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.boolean
isEmpty
(boolean respectConfiguredSettings) Returnstrue
if there is nothing to be done by this generator.protected void
void
Executes a set of commands to drop/create database objects.void
Creates a temporary DataSource out of DataSourceInfo and invokespublic void runGenerator(DataSource ds)
.protected boolean
safeExecute
(Connection connection, 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
boolean
Returns whether DbGenerator is configured to create primary key support for DataMap entities.boolean
Returns whether DbGenerator is configured to create tables for DataMap entities.boolean
boolean
-
Field Details
-
adapter
-
map
-
domain
-
jdbcEventLogger
-
dropTables
-
createTables
-
createConstraints
-
createPK
-
dropPK
-
dbEntitiesInInsertOrder
Contains all DbEntities ordered considering their interdependencies. DerivedDbEntities are filtered out of this list. -
dbEntitiesRequiringAutoPK
-
shouldDropTables
protected boolean shouldDropTables -
shouldCreateTables
protected boolean shouldCreateTables -
shouldDropPKSupport
protected boolean shouldDropPKSupport -
shouldCreatePKSupport
protected boolean shouldCreatePKSupport -
shouldCreateFKConstraints
protected boolean shouldCreateFKConstraints -
failures
-
-
Constructor Details
-
DbGenerator
- Since:
- 3.1
-
DbGenerator
public DbGenerator(DbAdapter adapter, DataMap map, JdbcEventLogger logger, Collection<DbEntity> excludedEntities) - Since:
- 3.1
-
DbGenerator
public DbGenerator(DbAdapter adapter, DataMap map, Collection<DbEntity> excludedEntities, DataDomain domain, JdbcEventLogger logger) Creates and initializes new DbGenerator instance.- Parameters:
adapter
- DbAdapter corresponding to the databasemap
- DataMap whose entities will be used in schema generationexcludedEntities
- entities that should be ignored during schema generationdomain
- optional DataDomain used to detect cross-database relationships.- Since:
- 3.1
-
-
Method Details
-
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) Returnstrue
if there is nothing to be done by this generator. IfrespectConfiguredSettings
istrue
, checks are done applying currently configured settings, otherwise check is done, assuming that all possible generated objects. -
getAdapter
Returns DbAdapter associated with this DbGenerator. -
configuredStatements
Returns a list of all schema statements that should be executed with the current configuration. -
runGenerator
Creates a temporary DataSource out of DataSourceInfo and invokespublic void runGenerator(DataSource ds)
.- Throws:
Exception
-
runGenerator
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:
Exception
-
safeExecute
Builds and executes a SQL statement, catching and storing SQL exceptions resulting from invalid SQL. Only non-recoverable exceptions are rethrown.- Throws:
SQLException
- Since:
- 1.1
-
createConstraintsQueries
Creates FK and UNIQUE constraint statements for a given table.- Since:
- 3.0
-
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
Returns a DataDomain used by the DbGenerator to detect cross-database relationships. By default DataDomain is null.- Since:
- 1.2
-