d53979gc11 appendix a

Upload: antonio-arroyo-paz

Post on 13-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 D53979GC11 Appendix A

    1/20

    Copyright 2009, Oracle. All rights reserved.

    Modeling the Database Schema

  • 7/27/2019 D53979GC11 Appendix A

    2/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 2

    Copyright 2009, Oracle. All rights reserved.

    Objectives

    After completing this lesson, you should be able to do the

    following:

    Describe JDevelopers tool for database modeling

    Create a schema model

    Modify the schema model

    Reconcile the modifications to the database

    Import database object definitions to an offline database

    Reconcile offline database objects with the database

    Lesson AimWhen designing an application to interact with the database, an understanding of the database

    schema is essential, along with the ability to modify the schema as needed. This lesson shows

    you how to use JDeveloper tools to define a model of a database schema and to use the model to

    modify the schema.

  • 7/27/2019 D53979GC11 Appendix A

    3/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 3

    Copyright 2009, Oracle. All rights reserved.

    Modeling Database Schemas

    With JDevelopers database modeler, you can:

    Create a schema model

    Modify the schema model

    Reconcile changes to the database

    Modeling Database SchemasOffline database object modeling in projects has been extended to provide for:

    Index-organized tables

    External tables

    Partitioned tables and indexes

    Materialized (including partitioned and indexed) views and view logs

    Object Collections

    Triggers

    Domain indexes

    Storage properties (tablespace and so on)

    Auto-generated column values SXML definition generation

    Cross-referencing multiple database objects within or between projects

  • 7/27/2019 D53979GC11 Appendix A

    4/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 4

    Copyright 2009, Oracle. All rights reserved.

    Goals of Database Modeling

    Database modeling can help you achieve the following goals:

    For existing database objects:

    Visualize the schema to help analyze whether it meets

    requirements.

    Make any necessary modifications.

    For new database objects:

    Design schema to support business requirements.

    Generate DDL to create the required database objects.

    Why Perform Database Modeling?Visualizing existing tables in a data diagram can help you understand whether the schema might

    need modifications to support the business requirements.

    If the tables do not already exist, you can use the same diagrammer to design them and generate

    the DDL scripts to create the tables.

  • 7/27/2019 D53979GC11 Appendix A

    5/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 5

    Copyright 2009, Oracle. All rights reserved.

    Characteristics of the JDeveloper Database

    Modeler

    Model existing objects, such as

    tables and foreign keys, by

    dragging from Database

    Navigator

    Use Property Inspector to set

    properties on diagram and its

    objects

    Create new objects by

    dragging from

    Component Palette.

    With the JDeveloper Database Modeler you can:

    Characteristics of the JDeveloper Database ModelerAlthough this course concentrates on working with an existing database schema, it is important

    to understand that you also can use JDevelopers database diagrammer to design and create new

    tables.

  • 7/27/2019 D53979GC11 Appendix A

    6/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 6

    Copyright 2009, Oracle. All rights reserved.

    Database Modeling Tools in JDeveloper

    You can work with database objects in the following ways:

    Online: Create and modify schema objects directly in a

    database through a JDeveloper connection.

    Offline:

    Model metadata for database objects outside the context of a

    database schema.

    Import objects from online database.

    Generate changes to online schemas.

    Diagrammer: Create and modify objects by dragging from Component

    Palette and Database Navigator.

    Import objects from offline database model.

    Generate changes to online schemas.

    Database Modeling in JDeveloperYou can use JDeveloper to work directly with database objects through a database connection.

    Alternatively you can work with offline database definitions, which you can subsequently

    generate to a database schema.

    JDeveloper provides the tools you need to create and edit database objects such as tables and

    constraints outside the context of a database. You can create new tables and views and generate

    the information to a database, or you can import database objects from a database schema, make

    the changes you want and then generate the changes back to the same database schema, to a new

    database schema, or to a file that you can run against a database at a later date. Alternatively,

    you can use JDevelopers modeling tools to visualize your offline database objects on a diagram.

    You can use JDevelopers database diagrammer to design and create new tables as well. You

    can import database objects from the offline database into the diagrammer. The diagrammer

    allows you to import database objects from online schemas and also generate changes to online

    schemas.

  • 7/27/2019 D53979GC11 Appendix A

    7/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 7

    Copyright 2009, Oracle. All rights reserved.

    Modeling Database Objects Offline

    You can create offline database definitions in the following

    ways:

    Create new offline database objects

    Copy from database with filters

    Modeling Database Objects OfflineYou can create offline database definitions based on objects that exist in a database schema in

    one of the following ways:

    Using Drag and Drop: You can drag tables, views, synonyms and sequences from a

    database schema onto a database diagram, where they become accessible as offline

    database objects.

    Using Import with Filters: You can import tables, views, sequences and synonyms from a

    database schema to an offline schema where they become available as offline database

    objects. You can apply filters in the wizard to display only the objects that you are

    interested in, and when there are a large number of objects in the schema you can turn off

    auto-query so that the wizard does not refresh every time you type a filter character.

  • 7/27/2019 D53979GC11 Appendix A

    8/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 8

    Copyright 2009, Oracle. All rights reserved.

    Creating a New Offline Database

    To create a definition for an offline database in which you

    can model database objects, perform the following steps:

    1. In the Application Navigator, right-click a project and choose

    New to display the New Gallery.

    2. In the New Gallery, expand Database Tier, and select Offline

    Database Objects.

    3. Select Offline Database to launch the Create Offline

    Database Wizard.

    4. In the pages of the wizard, enter properties for the database,

    such as its name.

    After an offline database is created, you can create various

    database object definitions within it.

    Creating a New Offline DatabaseTo create an offline database definition, perform the following steps:

    1. In the Application Navigator, expand the application and the project you want to work in.

    Right-click a project and choose New to display the New Gallery.

    2. From the New Gallery, expand Database Tier, and select Offline Database Objects.

    3. Select Offline Database to launch the Create Offline Database Wizard.

    4. In the pages of the wizard, enter properties for the database, such as its name.

    After an offline database is created, you can create various database object definitions within

    this database.

  • 7/27/2019 D53979GC11 Appendix A

    9/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 9

    Copyright 2009, Oracle. All rights reserved.

    Creating New Schema

    Objects in an Offline Database

    Create new schema objects in an offline database by using

    wizards to define: Functions

    Materialized views and view logs

    Packages

    Procedures

    Sequences

    Synonyms

    Tables

    Triggers

    Types

    Views

    Creating New Schema Objects in an Offline DatabaseYou can create new schema objects in an offline database by invoking one of the New Database

    Object wizards and entering the required information.

  • 7/27/2019 D53979GC11 Appendix A

    10/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 10

    Copyright 2009, Oracle. All rights reserved.

    Creating a Database Diagram

    Creating a Database DiagramAfter creating a named connection in the Database Navigator to browse database schema

    objects, you can create a database diagram in any JDeveloper project. To create a new diagram,

    perform the following steps:

    1. Select the project in which you want to create the diagram.

    2. Select File > New to invoke the New Gallery.

    3. In the New Gallery, expand the General category and select Diagrams.

    4. Select Database Diagram from the Items list and then click OK.

    5. In the Create Database Diagram dialog box, specify a name for the diagram and optionally

    a package name, and then click OK.

  • 7/27/2019 D53979GC11 Appendix A

    11/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 11

    Copyright 2009, Oracle. All rights reserved.

    Importing Tables to the Diagram

    from an Offline Database

    1

    2

    Importing Tables to the Diagram from an Offline DatabaseYou can import tables from an offline database as follows:

    1. In the Offline Database Navigator, select the desired offline object and drag it to the

    diagram.

    2. A depiction of the offline object appears on the diagram.

    When you drag related tables to the diagram, the foreign key relations are also depicted visually.

    Offline objects attributes can be modified in the Offline Database Navigator or on the diagram,

    and are kept in synch.

  • 7/27/2019 D53979GC11 Appendix A

    12/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 12

    Copyright 2009, Oracle. All rights reserved.

    Editing Objects on the Diagram

    In-place editing:

    Edit Table dialog box:

    Editing Objects on the DiagramThere are two ways to edit objects on the diagram:

    In-place editing: Click inside the object, such as an attribute, then click it again to put the

    text in edit mode.

    Double-click the object to invoke the editor, such as the table editor shown in the slide.

  • 7/27/2019 D53979GC11 Appendix A

    13/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 13

    Copyright 2009, Oracle. All rights reserved.

    Generating Changes from the Diagram

    to the Database

    Invoke wizard.

    In the wizard:

    Select objects.

    Specify operation.

    Set database options.

    Set SQL script options.

    SQL script opens in

    editor;right-click to run it.

    Generating Changes to the DatabaseIf you created a database diagram, you can right-click the object or objects on the diagram to

    generate DDL to create, replace, or alter those objects. From the context menu, select

    Synchronize with Database > Generate To > SQL Script. This invokes a wizard where you

    specify the object, operations, and SQL script options that you want to use. When you complete

    the wizard, the script that it generates opens in the editor, where you can run it.

  • 7/27/2019 D53979GC11 Appendix A

    14/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 14

    Copyright 2009, Oracle. All rights reserved.

    Reconciling Changes to the Database

    Choosing ALTER with Manual Reconcile enables you tochoose changes to be generated to the database.

    Reconciling Changes to the DatabaseIf you choose the Alter operation, the offline objects are compared with the online objects and

    DDL is generated to make the online objects match the offline objects. You can optionally

    specify that you want to manually reconcile the objects. After the wizard is completed, if you

    specified manual reconciliation, an additional dialog box is displayed that enables you to

    compare the objects to be generated to the database with the objects in the database, so that you

    can choose which changes to generate to the database.

  • 7/27/2019 D53979GC11 Appendix A

    15/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 15

    Copyright 2009, Oracle. All rights reserved.

    Generating Changes from the Offline Database

    Object to the Database

    To generate imported offline database objects to the database: Right-click the object

    in the Applications

    Navigator

    Select Generate To

    Select the JDeveloper

    connection, or choose

    to create a SQL script

    or SXML

    Generating Changes from the Offline Database Object to the DatabaseWhether or not you have created a database diagram, you can generate changes to the database

    by right-clicking the database object or objects in the Applications Navigator and selecting

    Generate To. You can then select a JDeveloper connection, or you can generate a SQL script or

    SXML.

    When you choose to generate to a JDeveloper connection as depicted in the slide, or to SQL

    Scripts, this also invokes the Generate SQL from Offline Database Objects Wizard. Its pages

    enable you to specify whether to create, replace, or alter, and whether to generate a SQL script,

    along with script options. If you choose to generate to SXML, an XML file is created and opens

    in the editor.

  • 7/27/2019 D53979GC11 Appendix A

    16/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 16

    Copyright 2009, Oracle. All rights reserved.

    Importing Database Objects Without a Diagram

    You can import database

    objects to an offline

    database without using a

    diagram:

    Importing Database Objects Without a DiagramIf you do not want to create a database diagram, you can use the Copy Database Objects to a

    Project item in the New Gallery by expanding Database Tier and selecting Offline Database

    Objects in the categories list. This invokes the Copy Database Objects to a Project Wizard,

    which has the following pages:

    Specify Source (shown in the slide): Choose the JDeveloper connection from which to

    import.

    Specify Target: Select the application and project to import to, and select or create a new

    offline database to contain the imported objects.

    Object Picker: Select the database objects to import.

    Choose Operation: Choose whether to create, replace, or alter offline database objects. Finish: A summary of the specified import. Click Finish to start it.

  • 7/27/2019 D53979GC11 Appendix A

    17/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 17

    Copyright 2009, Oracle. All rights reserved.

    Presenting the Storefront Schema

    Presenting the Storefront SchemaThe schema used for the course application is a subset of the Fusion Order Demo (FOD)

    schema. You can read about how to obtain the Fusion Order Demo in Section 2.2 of the Oracle

    Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework

    11g Release 1 (11.1.1).

    The main tables that are used in the course application are Persons, Suppliers, Orders, and Order

    Items. The application also uses some views, such as Products and ProductCategories.

  • 7/27/2019 D53979GC11 Appendix A

    18/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 18

    Copyright 2009, Oracle. All rights reserved.

    Summary

    In this lesson, you should have learned how to:

    Describe JDevelopers tool for database modeling

    Create a schema model

    Modify the schema model

    Reconcile the modifications to the database

    Import database object definitions to an offline database

    Reconcile offline database objects with the database

  • 7/27/2019 D53979GC11 Appendix A

    19/20Oracle Fusion Middleware 11g: Build Applications with ADF I A - 19

    Copyright 2009, Oracle. All rights reserved.

    Practice Overview:

    Modeling the Schema for the Course Application

    This practice covers the following topics:

    Creating a database diagram

    Adding existing schema objects to the diagram

    Adding a new database object to the diagram

    Creating the DDL to add the new object to the database

    Practice Overview: Modeling the Schema for the Course Application(optional)

    In this practice, you use the database diagrammer to create a visual representation of the

    database schema. You also create a new database component (a table) and create the DDL to add

    it to the schema.

    This practice may be found in the Optional Practices section of Appendix A.

  • 7/27/2019 D53979GC11 Appendix A

    20/20