10. Generating a Schema from DBMS Tables


The mapping tool can jump start development by generating a default mapping schema from existing tables in a database.

To utilize this option select the Generate->Schema from database tables menu option to display the dialog box shown below. You must be connected to a database in order to generate a schema from tables. If you are not connected to a database the Connect dialog box will be displayed first to allow you to connect to the database.

 

mtgenschtabdlg.jpg (43355 bytes)

 

Enter, or select from the combo box drop down list, the Java package name that the generated classes will belong to, or leave blank for no package. If necessary, enter, or select from the combo boxes, the catalog and schema where the tables are located. You may select a predefined search pattern from the Catalog, Schema, and Table pattern combo boxes, or enter your own search pattern. A table search pattern allows you filter the tables displayed based on the table names. The Table type option allows you to specify whether to display only tables, only views, both tables and views, or all table-like objects. The Available list automatically displays the names of all tables found that match the search criteria.

 

About Catalogs and Schemas
Catalogs and schemas refer to the organization of data in relational databases, where data is contained in tables, tables are grouped into schemas, and schemas are grouped into catalogs. The terms catalogs and schemas are defined in the SQL 92 standard but are not applicable to all databases. (It is important to note that term schema as used in this section does not refer to the same 'schema objects' that the mapping tool manipulates.) For example, in desktop databases such as MS Access there are no such concepts. Also, many databases use slightly different variations of these terms. For example, in SQL Server and Sybase, tables are grouped by owner, and catalogs are databases. In this case a list of database names in shown in the catalogs field, and a list of table owners in the schemas field. It is also very common that the owner of all tables is the database administrator, so if you do not know the actual owner name, select 'dbo' (under SQL Server or Sybase), or the actual name of the database administrator.
About Search Patterns
The mapping tool passes all supplied search patterns directly to the JDBC driver. It is up to the driver to correctly implement the search. The JDBC spec defines the following two special search pattern characters that can be embedded within the search pattern:
  1. "%" means match any substring of 0 or more characters.
  2. "_" means match any one character.

 

The following are predefined search patterns that can be selected from the Catalog, Schema, and Table pattern combo boxes drop down lists:

Depending on the target database, it may take some playing with all the these settings to display the desired tables in the Available list.

Once the desired tables in the Available list, use the Add or Add All buttons to move tables from the Available list to the Selected list. You can also use the Remove and Remove All buttons to move tables from the Selected list back to the Available list.

Click the Options button to bring up the DB Conversion Rules panel of the configuration dialog box if necessary to verify or update the current database to class conversion rules.

Once the Selected list displays the tables for which you want to generate a mapping schema click the Generate button to start the generation process. The generation procedure creates a Package schema object if one with the supplied package name does not already exist, and then adds Class objects for each table and Attribute objects for each column to the Package object. The status bar at the bottom edge of the mapping tool will inform you when the generation process has completed.

The generated schema objects do not overwrite any existing schema objects, instead they are added to the tree. This means you can run this procedure multiple times against multiple databases without overwriting any previous schema objects. If you do want to clear out any existing schema objects use the File->New Schema menu option before running this procedure.

 

Next Section 

Return to Table of Contents