Chapter 11 discusses Object and Object-Relational Databases, covering concepts such as object identity, encapsulation, and inheritance. It introduces Object Database Extensions to SQL, including user-defined types and complex structures, along with the ODMG Object Model and Object Definition Language (ODL). The chapter emphasizes the importance of object-oriented features in managing complex data structures in databases.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
7 views54 pages
Unit1 Object Relational Database
Chapter 11 discusses Object and Object-Relational Databases, covering concepts such as object identity, encapsulation, and inheritance. It introduces Object Database Extensions to SQL, including user-defined types and complex structures, along with the ODMG Object Model and Object Definition Language (ODL). The chapter emphasizes the importance of object-oriented features in managing complex data structures in databases.
Overview of Object Database Concepts ▪ Introduction to object-oriented concepts and features ▪ Origins in OO programming languages ▪ Object has two components: • State (value) and behavior (operations) ▪ Instance variables • Hold values that define internal state of object ▪ Operation is defined in two parts: • Signature or interface and implementation
Overview of Object Database Concepts (cont’d.) ▪ Inheritance • Permits specification of new types or classes that inherit much of their structure and/or operations from previously defined types or classes ▪ Operator overloading • Operation’s ability to be applied to different types of objects • Operation name may refer to several distinct implementations
Object Identity, and Objects versus Literals ▪ Unique identity ▪ Implemented via a unique, system-generated object identifier (OID) ▪ Immutable- that is, the OID value of a particular object should not change. ▪ Most OO database systems allow for the representation of both objects and literals (or values)
Summary of Object Database Concepts ▪ Object identity ▪ Type constructor ▪ Encapsulation of operations ▪ Programming language compatibility ▪ Type hierarchies and inheritance ▪ Extents ▪ Polymorphism and operator overloading
Object-Relational Features: Object Database Extensions to ▪ Type constructors SQL ▪ Specify complex objects (row type, array type, set, list, and bag constructors) ▪ Mechanism for specifying object identity - through the use of reference type is included ▪ Encapsulation of operations ▪ Provided through user-defined types (UDTs) – abstract datatype ▪ Inheritance mechanisms ▪ Provided using keyword UNDER
Object Identifiers Using Reference Types ▪ Reference type ▪ Create unique system-generated object identifiers ▪ Examples: • REF IS SYSTEM GENERATED- indicates that whenever a new PERSON_TYPE object is created, the system will assign it a unique system-generated identifier. It is also possible not to have a system-generated object identifier and use the traditional keys of the basic relational model if desired. • REF IS <OID_ATTRIBUTE> <VALUE_GENERATION_METHOD> ; • Generation methods: SYSTEM GENERATED or DERIVED In the former case, the system will automatically generate a unique identifier for each tuple. In the latter case, the traditional method of using the user-provided primary key value to identify tuples is applied.
Creating Tables Based on the UDTs ▪ INSTANTIABLE ▪ Specify that UDT is instantiable ▪ Causes one or more tables to be created -11.4(d), where we create a table PERSON based on the PERSON_TYPE UDT. ▪ Notice that the UDTs in Figure 11.4(a) are noninstantiable and hence can only be used as ▪ types for attributes, but not as a basis for table creation. ▪ In Figure 11.4(b), the attribute PERSON_ID will hold the system-generated object identifier whenever a new PERSON record (object) is created and inserted in the table.
Encapsulation of Operations ▪ User-defined type ▪ Specify methods (or operations) in addition to the attributes ▪ Format: CREATE TYPE <TYPE-NAME> ( <LIST OF COMPONENT ATTRIBUTES AND THEIR TYPES> <DECLARATION OF FUNCTIONS (METHODS)> ); For example, in Figure 11.4(b), we declared a method Age() that calculates the age of an individual object of type PERSON_TYPE
Encapsulation of Operations (cont’d.) ▪ Constructor function TYPE_T( ) ▪ Returns a new object of that type and every attribute is initialized to its default value. ▪ Observer function A implicitly created for each attribute A ▪ A(X) or X.A return the of attribute A ▪ A Mutator function for updating an attribute sets the value of the attribute to a new value. ▪ User defined functions can internal (SQL) or external ▪ External functions written in a host language
In general, a UDT can have a number of user-defined functions associated with it. The syntax is INSTANCE METHOD <NAME> (<ARGUMENT_LIST>) RETURNS <RETURN_TYPE>;
Two types of functions can be defined: internal SQL and external.
Specifying Relationships via Reference ▪ Component attribute of one tuple may be a reference to a tuple of another table ▪ Specified using keyword REF ▪ Keyword SCOPE: Specify name of table whose tuples referenced (e.g, FK) ▪ Dot notation: Build path expressions that refer to the component attributes of tuples and row types. ▪ –> the symbol - Used for dereferencing the query below retrieves employees working in the company named ‘Microsoft’ by querying the EMPLOYMENT table: SELECT E.Employee -> Name FROM EMPLOYMENT AS E WHERE E.Company -> Name = ‘Microsoft’;
The ODMG Object Model and the Object Definition Language ODL ▪ ODMG object model ▪ Data model for object definition language (ODL) and object query language (OQL) ▪ Objects and Literals ▪ Basic building blocks of the object model ▪ Object has five aspects: ▪ Identifier, name, lifetime, structure ( atomic/collection), and creation ( new) ▪ Literal ▪ Value that does not have an object identifier -Atomic literals- basic data types of the object model include long, short, and unsigned integer numbers. ▪ Structured literals-include Date, Interval, Time, and Timestamp ▪ Collection literals - dictionary<K, V>, type generators set<T>, bag<T>, list<T>, and array<T>,
The ODMG Object Model and the ▪ Behavior refers ODL to operations (cont’d.) ▪ State refers to properties (attributes and relationships). ▪ Interface ▪ Specifies only behavior of an object type ▪ Typically noninstantiable -(that is, no objects are created corresponding to an interface). Although an interface may have state properties (attributes and relationships) as part of its specifications, these cannot be inherited from the interface. ▪ Class ▪ Specifies both state (attributes) and behavior (operations) of an object type ▪ Instantiable
Figure 11.5(a); these include operations such as copy (creates a new copy of the object), delete (deletes the object), and same_as (compares the object’s identity to another object). For example, given an object O, to compare it with another object P, we write O.same_as(P) , The result returned by this operation is Boolean and would be true if the identity of P is the same as that of O, and false otherwise. Similarly, to create a copy P of object O, we write P = O.copy() ., An alternative to the dot notation is the arrow notation: O–>same_as(P) or O–>copy().
Inheritance in the Object Model of ODMG ▪ Behavior inheritance ▪ Also known as IS-A or interface inheritance ▪ Specified by the colon (:) notation ▪ EXTENDS inheritance ▪ Specified by keyword extends ▪ Inherit both state and behavior strictly among classes ▪ Multiple inheritance via extends not permitted multiple inheritance is allowed for behavior inheritance via the colon (:) notation. Hence, an interface may inherit behavior from several other interfaces
The Object Query Language OQL ▪ Query language proposed for ODMG object model ▪ Simple OQL queries, database entry points, and iterator variables ▪ Syntax: select ... from ... where ... structure ▪ Entry point: named persistent object ▪ Iterator variable: define whenever a collection is referenced in an OQL query
Query Results and Path Expressions ▪ Result of a query ▪ Any type that can be expressed in ODMG object model ▪ OQL orthogonal with respect to specifying path expressions ▪ Attributes, relationships, and operation names (methods) can be used interchangeably within the path expressions
Other Features of OQL ▪ Named query ▪ Specify identifier of named query ▪ OQL query will return collection as its result ▪ If user requires that a query only return a single element use element operator ▪ Aggregate operators ▪ Membership and quantification over a collection
Other Features of OQL (cont’d.) ▪ Special operations for ordered collections ▪ Group by clause in OQL ▪ Similar to the corresponding clause in SQL ▪ Provides explicit reference to the collection of objects within each group or partition ▪ Having clause ▪ Used to filter partitioned sets
Overview of the C++ Language Binding in the ODMG Standard ▪ Specifies how ODL constructs are mapped to C++ constructs ▪ Uses prefix d_ for class declarations that deal with database concepts ▪ Template classes ▪ Specified in library binding ▪ Overloads operation new so that it can be used to create either persistent or transient objects
Summary ▪ Overview of concepts utilized in object databases ▪ Object identity and identifiers; encapsulation of operations; inheritance; complex structure of objects through nesting of type constructors; and how objects are made persistent ▪ Description of the ODMG object model and object query language (OQL) ▪ Overview of the C++ language binding