| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.cayenne.access.DbGenerator
public class DbGenerator
Utility class that generates database schema based on Cayenne mapping. It is a logical counterpart of DbLoader class.
| Field Summary | |
|---|---|
| protected  DbAdapter | adapter | 
| protected  Map<String,List<String>> | createConstraints | 
| protected  List<String> | createPK | 
| protected  Map<String,String> | createTables | 
| protected  List<DbEntity> | dbEntitiesInInsertOrderContains all DbEntities ordered considering their interdependencies. | 
| protected  List<DbEntity> | dbEntitiesRequiringAutoPK | 
| protected  DataDomain | domain | 
| protected  List<String> | dropPK | 
| protected  Map<String,Collection<String>> | dropTables | 
| protected  ValidationResult | failures | 
| 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)Creates and initializes new DbGenerator. | |
| DbGenerator(DbAdapter adapter,
            DataMap map,
            Collection<DbEntity> excludedEntities)Creates and initializes new DbGenerator instance. | |
| DbGenerator(DbAdapter adapter,
            DataMap map,
            Collection<DbEntity> excludedEntities,
            DataDomain domain)Creates and initializes new DbGenerator instance. | |
| Method Summary | |
|---|---|
| protected  void | buildStatements()Creates and stores internally a set of statements for database schema creation, ignoring configured schema creation preferences. | 
|  List<String> | configuredStatements()Returns a list of all schema statements that should be executed with the current configuration. | 
|  List<String> | createConstraintsQueries(DbEntity table)Creates FK and UNIQUE constraint statements for a given table. | 
|  List<String> | createFkConstraintsQueries(DbEntity table)Deprecated. since 3.0 as this method is used to generate both FK and UNIQUE constraints, use 'createConstraintsQueries' instead. | 
|  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 trueif there is nothing to be done by this generator. | 
| protected  void | resetToDefaults() | 
|  void | runGenerator(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(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 | 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 | 
|---|
protected DbAdapter adapter
protected DataMap map
protected DataDomain domain
protected Map<String,Collection<String>> dropTables
protected Map<String,String> createTables
protected Map<String,List<String>> createConstraints
protected List<String> createPK
protected List<String> dropPK
protected List<DbEntity> dbEntitiesInInsertOrder
protected List<DbEntity> dbEntitiesRequiringAutoPK
protected boolean shouldDropTables
protected boolean shouldCreateTables
protected boolean shouldDropPKSupport
protected boolean shouldCreatePKSupport
protected boolean shouldCreateFKConstraints
protected ValidationResult failures
| Constructor Detail | 
|---|
public DbGenerator(DbAdapter adapter,
                   DataMap map)
public DbGenerator(DbAdapter adapter,
                   DataMap map,
                   Collection<DbEntity> excludedEntities)
adapter - DbAdapter corresponding to the databasemap - DataMap whose entities will be used in schema generationexcludedEntities - entities that should be ignored during schema generation
public DbGenerator(DbAdapter adapter,
                   DataMap map,
                   Collection<DbEntity> excludedEntities,
                   DataDomain domain)
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.| Method Detail | 
|---|
protected void resetToDefaults()
protected void buildStatements()
public boolean isEmpty(boolean respectConfiguredSettings)
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.
public DbAdapter getAdapter()
public List<String> configuredStatements()
public void runGenerator(DataSourceInfo dsi)
                  throws Exception
public void runGenerator(DataSource ds).
Exception
public void runGenerator(DataSource ds)
                  throws Exception
Exception
protected boolean safeExecute(Connection connection,
                              String sql)
                       throws SQLException
SQLExceptionpublic List<String> createFkConstraintsQueries(DbEntity table)
public List<String> createConstraintsQueries(DbEntity table)
public ValidationResult getFailures()
public boolean shouldCreatePKSupport()
public boolean shouldCreateTables()
public boolean shouldDropPKSupport()
public boolean shouldDropTables()
public boolean shouldCreateFKConstraints()
public void setShouldCreatePKSupport(boolean shouldCreatePKSupport)
public void setShouldCreateTables(boolean shouldCreateTables)
public void setShouldDropPKSupport(boolean shouldDropPKSupport)
public void setShouldDropTables(boolean shouldDropTables)
public void setShouldCreateFKConstraints(boolean shouldCreateFKConstraints)
public DataDomain getDomain()
| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||