Object Relational

download Object Relational

of 16

Transcript of Object Relational

  • 8/3/2019 Object Relational

    1/16

    Object Relational

    Interactions with Oracle

  • 8/3/2019 Object Relational

    2/16

    Outline

    Why Object database managementsystems (ODBMSs)?

    ODBMS and RDBMS and ORDBMS

    Oracle Database Object Relational Oracle Objects

    Collection Object Type

    Object Type Methods

    Inheritance

  • 8/3/2019 Object Relational

    3/16

    Why ODBMS?

    The need for storing and manipulating complex data isincreasing. We can not use relational databases tostore this kind of data.

    The complex data types appear in several applications:

    CAD/CAM

    Geometric modeling

    Geographical Information Systems

    Knowledge-based systems / through frames

    Web applications that need to store, index, search andmanipulate diverse objects.

    The impedance mismatch becomes apparent whentrying to map these OO language properties to aRDBMS.

  • 8/3/2019 Object Relational

    4/16

    ODBMS ,RDBMS and ORDBMS

  • 8/3/2019 Object Relational

    5/16

    Oracle Database Object Relational

  • 8/3/2019 Object Relational

    6/16

    Object Types

    Simple Object Type

    A simple object type consists of scalardata types.

    Example:CREATE OR REPLACE TYPE Address_objtyp AS OBJECT(

    Street VARCHAR2(200),

    City VARCHAR2(200),

    State CHAR(2),

    Zip VARCHAR2(20),

    MEMBER FUNCTION formatAsXML RETURN VARCHAR2

    );

  • 8/3/2019 Object Relational

    7/16

    Object Types

    Reference Object Type A REFis a logical pointer to represent relationships

    between class instances.

    Example:

    CREATE OR REPLACE TYPE LineItem_objtyp AS OBJECT (

    LineItemNo NUMBER,

    Stock_refREFStockItem_objtyp,

    Quantity NUMBER,

    Discount NUMBER);

    Given a LineItem_objtyp object instance, the price of theitem is easily accessed with the following:

    .DEREF(stock_ref).price

  • 8/3/2019 Object Relational

    8/16

    Collection Object Type

    Varray An ordered and bounded collection

    CREATE OR REPLACE TYPE PhoneList_vartyp

    AS VARRAY(10) OF VARCHAR2(25);

    Nested tables.

    A nested table is an unbounded

    and unsorted collection.CREATE OR REPLACE TYPE LineItemList_ntabtyp

    AS TABLE OF LineItem_objtyp;

  • 8/3/2019 Object Relational

    9/16

    Composite Object Type

    CREATE OR REPLACE TYPE Customer_objtyp AS OBJECT (

    CustNo NUMBER,

    CustName VARCHAR2(200),

    Address_objAddress_objtyp,

    PhoneList_varPhoneList_vartyp

    ) NOT FINAL;

  • 8/3/2019 Object Relational

    10/16

    Composite Object Type

    CREATE OR REPLACE TYPE PurchaseOrder_objtyp

    AS OBJECT(

    PONo NUMBER,

    OrderDate DATE,

    ShipDate DATE,

    Cust_ref REF Customer_objtyp,

    LineItemList_ntab LineItemList_ntabtyp,

    ShipToAddr_obj Address_objtyp,

    MAP MEMBER FUNCTION

    getPONo RETURN NUMBER,

    MEMBER FUNCTION

    sumLineItems RETURN NUMBER

    );

  • 8/3/2019 Object Relational

    11/16

    Object Type Methods

    Member MethodsCREATE OR REPLACE FUNCTION formatAsXML (customer_id

    NUMBER)

    Constructor MethodsCREATE OR REPLACE TYPE Customer_objtyp AS OBJECT (

    ... some code snipped ...

    CONSTRUCTOR FUNCTION

    customer_objtyp(id IN NUMBER) RETURNSELFAS RESULT,

    ) NOT FINAL;

  • 8/3/2019 Object Relational

    12/16

    Object Type Methods

    Using ConstructorDECLARE

    newCustomer customer_objtyp := NULL;BEGIN

    newCustomer := customer_objtyp(42,Adams, Douglas,Address_objtyp(123 Handy Road,

    Dandyville, CA, 94999),phonelist_vartyp(+1-650-555-1212,

    +61-8-9555-1212));

    END;

  • 8/3/2019 Object Relational

    13/16

    Comparison Methods

    CREATE OR REPLACE TYPE Customer_objtyp AS OBJECT (ORDER MEMBER FUNCTION

    compareCustOrders(x IN Customer_objtyp) RETURN INTEGER... some code snipped ...

    ) NOT FINAL;

    CREATE OR REPLACE TYPE BODY customer_objtyp AS

    ORDER MEMBER FUNCTION compareCustOrders(x INCustomer_objtyp)

    RETURN INTEGER ISBEGINRETURN SELF.CustNo - x.CustNo;

    END compareCustOrders;... some code snipped ...

    END;

  • 8/3/2019 Object Relational

    14/16

    Inheritance

    Using the underkeyword.

    CREATE OR REPLACE TYPE OnlineCustomer_objtyp UNDERCustomer_objtyp (

    EmailAddress VARCHAR2(50),

    MEMBER FUNCTION sendEmail(subject IN VARCHAR2, msg INVARCHAR2) RETURN VARCHAR2

    ) NOT FINAL;

    /

    There can be multiple levels in thishierarchy

  • 8/3/2019 Object Relational

    15/16

    Mapping to UML Concepts

  • 8/3/2019 Object Relational

    16/16

    Conclusion

    Further reading [1] Object-Oriented Oracle , J.W.Rahayu,

    IRM Press, 2005

    [2] Professional Oracle Programming,Rick Greenwald, Wrox, 2005 (Chapter21)

    Exercise

    Using Oracle Object Types with Java ([2],page 501 - 520)