org.apache.cayenne.access

## Class DbLoader

- java.lang.Object
- - org.apache.cayenne.access.DbLoader

-     public class DbLoader
      extends Object

  Utility class that does reverse engineering of the database. It can create DataMaps using database meta data obtained via JDBC driver.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected DbAdapter` | `adapter`
    `protected Connection` | `connection`
    `protected boolean` | `creatingMeaningfulPK`
    `protected DbLoaderDelegate` | `delegate`
    `protected String` | `genericClassName`
    `protected DatabaseMetaData` | `metaData`
    `protected NamingStrategy` | `namingStrategy` Strategy for choosing names for entities, attributes and relationships
    `static String` | `WILDCARD`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DbLoader(Connection connection, DbAdapter adapter, DbLoaderDelegate delegate)` Creates new DbLoader.
    `DbLoader(Connection connection, DbAdapter adapter, DbLoaderDelegate delegate, NamingStrategy strategy)` Creates new DbLoader with specified naming strategy.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `DbAdapter` | `getAdapter()` Returns DbAdapter associated with this DbLoader.
    `List<String>` | `getCatalogs()` Retrieves catalogues for the database associated with this DbLoader.
    `Connection` | `getConnection()` Returns database connection used by this DbLoader.
    `String` | `getGenericClassName()` Returns a name of a generic class that should be used for all ObjEntities.
    `DatabaseMetaData` | `getMetaData()` Returns DatabaseMetaData object associated with this DbLoader.
    `NamingStrategy` | `getNamingStrategy()`
    `List<String>` | `getSchemas()` Retrieves the schemas for the database.
    `List<DbEntity>` | `getTables(String catalogPattern, String schemaPattern, String tableNamePattern, String[] types)` Returns all tables for given combination of the criteria.
    `List<String>` | `getTableTypes()` Returns all the table types for the given database.
    `boolean` | `includeTableName(String tableName)` A method that return true if the given table name should be included.
    `boolean` | `isCreatingMeaningfulPK()` Returns true if the generator should map all primary key columns as ObjAttributes.
    `DataMap` | `loadDataMapFromDB(String schemaName, String tablePattern, DataMap dataMap)` Performs database reverse engineering and generates DataMap that contains default mapping of the tables and views.
    `DataMap` | `loadDataMapFromDB(String schemaName, String tablePattern, String[] tableTypes, DataMap dataMap)` Performs database reverse engineering and generates DataMap object that contains default mapping of the tables and views.
    `boolean` | `loadDbEntities(DataMap map, List<? extends DbEntity> tables)` Loads dbEntities for the specified tables.
    `void` | `loadDbRelationships(DataMap map)` Loads database relationships into a DataMap.
    `void` | `loadObjEntities(DataMap map)` Creates an ObjEntity for each DbEntity in the map.
    `void` | `loadProceduresFromDB(String schemaPattern, String namePattern, DataMap dataMap)` Loads database stored procedures into the DataMap.
    `protected void` | `postprocessMasterDbRelationship(DbRelationship relationship, ExportedKey key)` Detects correct relationship multiplicity and "to dep pk" flag.
    `void` | `setCreatingMeaningfulPK(boolean check)`
    `void` | `setGenericClassName(String genericClassName)` Sets a name of a generic class that should be used for all ObjEntities.
    `void` | `setNamingStrategy(NamingStrategy strategy)` Sets new naming strategy for reverse engineering

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### WILDCARD

          public static final String WILDCARD

      See Also:
        Constant Field Values

    - #### connection

          protected Connection connection

    - #### adapter

          protected DbAdapter adapter

    - #### metaData

          protected DatabaseMetaData metaData

    - #### delegate

          protected DbLoaderDelegate delegate

    - #### genericClassName

          protected String genericClassName

    - #### creatingMeaningfulPK

          protected boolean creatingMeaningfulPK

    - #### namingStrategy

          protected NamingStrategy namingStrategy

      Strategy for choosing names for entities, attributes and relationships

  - ### Constructor Detail

    - #### DbLoader

          public DbLoader(Connection connection,
                          DbAdapter adapter,
                          DbLoaderDelegate delegate)

      Creates new DbLoader.

    - #### DbLoader

          public DbLoader(Connection connection,
                          DbAdapter adapter,
                          DbLoaderDelegate delegate,
                          NamingStrategy strategy)

      Creates new DbLoader with specified naming strategy.
      Since:
        3.0

  - ### Method Detail

    - #### getMetaData

          public DatabaseMetaData getMetaData()
                                       throws SQLException

      Returns DatabaseMetaData object associated with this DbLoader.
      Throws:
        `SQLException`

    - #### setCreatingMeaningfulPK

          public void setCreatingMeaningfulPK(boolean check)

    - #### isCreatingMeaningfulPK

          public boolean isCreatingMeaningfulPK()

      Returns true if the generator should map all primary key columns as ObjAttributes.
      Since:
        3.0

    - #### getConnection

          public Connection getConnection()

      Returns database connection used by this DbLoader.
      Since:
        3.0

    - #### getGenericClassName

          public String getGenericClassName()

      Returns a name of a generic class that should be used for all ObjEntities. The most common generic class is `CayenneDataObject`. If generic class name is null (which is the default), DbLoader will assign each entity a unique class name derived from the table name.
      Since:
        1.2

    - #### setGenericClassName

          public void setGenericClassName(String genericClassName)

      Sets a name of a generic class that should be used for all ObjEntities. The most common generic class is `CayenneDataObject`. If generic class name is set to null (which is the default), DbLoader will assign each entity a unique class name derived from the table name.
      Since:
        1.2

    - #### getAdapter

          public DbAdapter getAdapter()

      Returns DbAdapter associated with this DbLoader.
      Since:
        1.1

    - #### includeTableName

          public boolean includeTableName(String tableName)

      A method that return true if the given table name should be included. The default implementation include all tables.

    - #### getCatalogs

          public List<String> getCatalogs()
                                   throws SQLException

      Retrieves catalogues for the database associated with this DbLoader.
      Returns:
        List with the catalog names, empty Array if none found.
      Throws:
        `SQLException`

    - #### getSchemas

          public List<String> getSchemas()
                                  throws SQLException

      Retrieves the schemas for the database.
      Returns:
        List with the schema names, empty Array if none found.
      Throws:
        `SQLException`

    - #### getTableTypes

          public List<String> getTableTypes()
                                     throws SQLException

      Returns all the table types for the given database. Types may be such as "TABLE", "VIEW", "SYSTEM TABLE", etc.
      Returns:
        List of Strings, empty array if nothing found.
      Throws:
        `SQLException`

    - #### getTables

          public List<DbEntity> getTables(String catalogPattern,
                                          String schemaPattern,
                                          String tableNamePattern,
                                          String[] types)
                                   throws SQLException

      Returns all tables for given combination of the criteria. Tables returned as DbEntities without any attributes or relationships.
      Parameters:
        `catalogPattern` - The name of the catalog, may be null.
        `schemaPattern` - The pattern for schema name, use "%" for wildcard.
        `tableNamePattern` - The pattern for table names, % for wildcard, if null or "" defaults to "%".
        `types` - The types of table names to retrieve, null returns all types.
      Returns:
        List of TableInfo objects, empty array if nothing found.
      Throws:
        `SQLException`

    - #### loadDbEntities

          public boolean loadDbEntities(DataMap map,
                                        List<? extends DbEntity> tables)
                                 throws SQLException

      Loads dbEntities for the specified tables.
      Parameters:
        `map` - DataMap to be populated with DbEntities.
        `tables` - The list of org.apache.cayenne.ashwood.dbutil.Table objects for which DbEntities must be created.
      Returns:
        false if loading must be immediately aborted.
      Throws:
        `SQLException`

    - #### loadObjEntities

          public void loadObjEntities(DataMap map)

      Creates an ObjEntity for each DbEntity in the map. ObjEntities are created empty without

    - #### loadDbRelationships

          public void loadDbRelationships(DataMap map)
                                   throws SQLException

      Loads database relationships into a DataMap.
      Throws:
        `SQLException`

    - #### postprocessMasterDbRelationship

          protected void postprocessMasterDbRelationship(DbRelationship relationship,
                                                         ExportedKey key)

      Detects correct relationship multiplicity and "to dep pk" flag. Only called on relationships from PK to FK, not the reverse ones.

    - #### loadDataMapFromDB

          public DataMap loadDataMapFromDB(String schemaName,
                                           String tablePattern,
                                           DataMap dataMap)
                                    throws SQLException

      Performs database reverse engineering and generates DataMap that contains default mapping of the tables and views. By default will include regular tables and views.
      Throws:
        `SQLException`
      Since:
        1.0.7

    - #### loadDataMapFromDB

          public DataMap loadDataMapFromDB(String schemaName,
                                           String tablePattern,
                                           String[] tableTypes,
                                           DataMap dataMap)
                                    throws SQLException

      Performs database reverse engineering and generates DataMap object that contains default mapping of the tables and views. Allows to limit types of tables to read.
      Throws:
        `SQLException`

    - #### loadProceduresFromDB

          public void loadProceduresFromDB(String schemaPattern,
                                           String namePattern,
                                           DataMap dataMap)
                                    throws SQLException

      Loads database stored procedures into the DataMap.

      As of 1.1 there is no boolean property or delegate method to make procedure loading optional or to implement custom merging logic, so currently this method is NOT CALLED from "loadDataMapFromDB" and should be invoked explicitly by the user.

      Throws:
        `SQLException`
      Since:
        1.1

    - #### setNamingStrategy

          public void setNamingStrategy(NamingStrategy strategy)

      Sets new naming strategy for reverse engineering
      Since:
        3.0

    - #### getNamingStrategy

          public NamingStrategy getNamingStrategy()

      Returns:
        naming strategy for reverse engineering
      Since:
        3.0

Copyright © 2001–2018 Apache Cayenne. All rights reserved.