Overview | Package | Class | 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 DbLoader

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

    public class DbLoader

extends java.lang.Object

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

Author:
  Michael Shengaout, Andrei Adamchik

Field Summary
`protected DbAdapter` | `adapter`
`protected java.sql.Connection` | `con`
`protected DbLoaderDelegate` | `delegate`
`protected java.lang.String` | `genericClassName`
`protected java.sql.DatabaseMetaData` | `metaData`
`static java.lang.String` | `WILDCARD`

Constructor Summary
`DbLoader(java.sql.Connection con, DbAdapter adapter, DbLoaderDelegate delegate)` Creates new DbLoader.

Method Summary
`DbAdapter` | `getAdapter()` Returns DbAdapter associated with this DbLoader.
`java.util.List` | `getCatalogs()` Retrieves catalogues for the database associated with this DbLoader.
`java.sql.Connection` | `getCon()` Returns database connection used by this DbLoader.
`java.lang.String` | `getGenericClassName()` Returns a name of a generic class that should be used for all ObjEntities.
`java.sql.DatabaseMetaData` | `getMetaData()` Returns DatabaseMetaData object associated with this DbLoader.
`java.util.List` | `getSchemas()` Retrieves the schemas for the database.
`java.util.List` | `getTables(java.lang.String catalog, java.lang.String schemaPattern, java.lang.String tableNamePattern, java.lang.String[] types)` Returns all table names for given combination of the criteria.
`java.util.List` | `getTableTypes()` Returns all the table types for the given database.
`DataMap` | `loadDataMapFromDB(java.lang.String schemaName, java.lang.String tablePattern, DataMap dataMap)` Performs database reverse engineering and generates DataMap that contains default mapping of the tables and views.
`DataMap` | `loadDataMapFromDB(java.lang.String schemaName, java.lang.String tablePattern, java.lang.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, java.util.List 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(java.lang.String schemaPattern, java.lang.String namePattern, DataMap dataMap)` Loads database stored procedures into the DataMap.
`protected void` | `postprocessMasterDbRelationship(DbRelationship relationship)` Detects correct relationship multiplicity and "to dep pk" flag.
`void` | `setGenericClassName(java.lang.String genericClassName)` Sets a name of a generic class that should be used for all ObjEntities.

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

Field Detail

### WILDCARD

    public static final java.lang.String WILDCARD

See Also:
  Constant Field Values

### con

    protected java.sql.Connection con

### adapter

    protected DbAdapter adapter

### metaData

    protected java.sql.DatabaseMetaData metaData

### delegate

    protected DbLoaderDelegate delegate

### genericClassName

    protected java.lang.String genericClassName

Constructor Detail

### DbLoader

    public DbLoader(java.sql.Connection con,
                    DbAdapter adapter,
                    DbLoaderDelegate delegate)

  Creates new DbLoader.

Method Detail

### getMetaData

    public java.sql.DatabaseMetaData getMetaData()
                                          throws java.sql.SQLException

  Returns DatabaseMetaData object associated with this DbLoader.

  Throws:
    `java.sql.SQLException`

### getCon

    public java.sql.Connection getCon()

  Returns database connection used by this DbLoader.

### getGenericClassName

    public java.lang.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(java.lang.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

### getCatalogs

    public java.util.List getCatalogs()
                               throws java.sql.SQLException

  Retrieves catalogues for the database associated with this DbLoader.

  Returns:
    List with the catalog names, empty Array if none found.
  Throws:
    `java.sql.SQLException`

### getSchemas

    public java.util.List getSchemas()
                              throws java.sql.SQLException

  Retrieves the schemas for the database.

  Returns:
    List with the schema names, empty Array if none found.
  Throws:
    `java.sql.SQLException`

### getTableTypes

    public java.util.List getTableTypes()
                                 throws java.sql.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:
    `java.sql.SQLException`

### getTables

    public java.util.List getTables(java.lang.String catalog,
                                    java.lang.String schemaPattern,
                                    java.lang.String tableNamePattern,
                                    java.lang.String[] types)
                             throws java.sql.SQLException

  Returns all table names for given combination of the criteria.

  Parameters:
    `catalog` - 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:
    `java.sql.SQLException`

### loadDbEntities

    public boolean loadDbEntities(DataMap map,
                                  java.util.List tables)
                           throws java.sql.SQLException

  Loads dbEntities for the specified tables.

  Parameters:
    `map` - DataMap to be populated with DbEntities.
    `tables` - The list of org.objectstyle.ashwood.dbutil.Table objects for which DbEntities must be created.
  Returns:
    false if loading must be immediately aborted.
  Throws:
    `java.sql.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 java.sql.SQLException

  Loads database relationships into a DataMap.

  Throws:
    `java.sql.SQLException`

### postprocessMasterDbRelationship

    protected void postprocessMasterDbRelationship(DbRelationship relationship)

  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(java.lang.String schemaName,
                                     java.lang.String tablePattern,
                                     DataMap dataMap)
                              throws java.sql.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:
    `java.sql.SQLException`
  Since:
    1.0.7

### loadDataMapFromDB

    public DataMap loadDataMapFromDB(java.lang.String schemaName,
                                     java.lang.String tablePattern,
                                     java.lang.String[] tableTypes,
                                     DataMap dataMap)
                              throws java.sql.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:
    `java.sql.SQLException`

### loadProceduresFromDB

    public void loadProceduresFromDB(java.lang.String schemaPattern,
                                     java.lang.String namePattern,
                                     DataMap dataMap)
                              throws java.sql.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:
    `java.sql.SQLException`
  Since:
    1.1

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

Copyright © 2001-2006 Apache.org All Rights Reserved.