Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
In Relational Database, DDL is used to specify the database schemas, similarly, the ODL
allows you to specify a logical schema foran object-oriented database. ODL is a programming-
language-independent specificationlanguage for defining OODB schemas. Just as an SQL DDL
schema is portableacross SQL-compliant relational DBMSs, an ODL schema is portable across
ODMGcompliantODBMSs.
class Student {
attribute string name;
attributeDate dateOfBirth;
attribute string address;
attribute string phone;
short age( );
floatgpa( );
// relationship between Student and CourseOffering
relationship set<CourseOffering> takes inverse CourseOffering::taken_by;
// operations
booleanregister_for(string crse, short sec, string term);.
};
class Course {
attribute string crse_code;
attribute string crse_title;
attribute short credit_hrs;
// plus relationships and operation . . .
};
IT8001 course ( );
This creates a new instance of Course. The object tag name, IT8001, can be used
to reference this object. We have not specified the attribute values for this object at this
point. Suppose you want to create a new student object and initialize some of its
attributes.
You can also specify the values for the attributes within a structure, as in the following
example:
Koushikastudent (
name: “Koushika”, dateOfBirth: 2/12/93,
address: {street_address “310 College Rd”, city “Chennai”, state “TN”, zip 600043},
phone: {personal_number123456789});
OQL
We will now describe the Object Query Language (OQL), which is similar to
SQL-92 and has been set forth as an ODMG standard for querying OODBs. OQL allows
you a lot of flexibility in formulating queries. You can write a simple query such as
Kumutha.dateOfBirth;
which returns Kumutha’s birth date, a literal value, or
PadmaPriya.address;
This returns a structure with values for street address, city, state, and zip. If instead we
want to simply find in which city Roshini resides, we can write
Roshini.address.city;
Advances in Database | Semester 5 | M.Tech-IT| Vivekanandan D, Dept of IT, MIT, AU
OQL-Basic Select Command
We have specified the attributes crse_title and credit_hrs for the extent (i.e., set of all
Course instances in the database) in the select clause, and stated the condition
c.crse_code = “IT8001” in the where clause.
selectc.crse_title, c.credit_hrs
from courses c
wherec.crse_code = “IT8001”
Because we are dealing with only one extent, we could have left out the variable c
without any loss in clarity.
selects.age
from students s
where s.name = “Muthulakshmi”
select s
from students s
wheres.gpa> = 8.0 and s.address.city ! = “Chennai”
You create an object type using the CREATE TYPE statement. The following example
uses the CREATE TYPE statement to create an object type named t_address. This object type is
used to represent an address and contains four attributes named street, city, state, and zip:
You can use the DESCRIBE command to get information on an object type. The
following examples show the t_address, t_person types:
A constructor is a built-in method for the object type, and it has the same name as the
object type; the constructor accepts parameters that are used to set the attributes of the new
object. The constructor for the t_product type is named t_product and accepts five parameters,
one to set each of the attributes; for example, t_product(1, pasta, 20 oz bag of pasta, 3.95, 10)
creates a new t_product object and sets its id to 1, name to pasta, description to 20 oz bag of
pasta, price to 3.95, and days_valid to 10.
The following query retrieves these rows from the products table; notice that the product
column objects’ attributes are displayed within a constructor for t_product:
You can also retrieve an individual column object from a table; to do this, you must
supply a table alias through which you select the object. The following query retrieves product
#1 from the products table; notice the use of the table alias p for the products table, through
which the product object’s id attribute is specified in the WHERE clause:
The following UPDATE statement modifies the description of product #1; notice that the table
alias p is used again:
Tables as Objects
You can use an object type to define an entire table, and such a table is known as an
object table. The following example creates an object table named object_products, which stores
objects of type t_product; notice the use of the OF keyword to identify the table as an object
table of type t_product:
When inserting a row into an object table, you can choose whether to use a constructor to
supply attribute values or to supply the values in the same way that you would supply column
values in a relational table.
The following query retrieves these rows from the object_products table:
Oracle Database 9i introduced object type inheritance, which allows you to define
hierarchies of object types. For example, you might want to define a business person object type
and have that type inherit the existing attributes from t_person. The business person type could
extend t_person with attributes to store the person’s job title and the name of the company they
work for. For t_person to be inherited from, the t_person definition must include the NOT
FINAL clause:
The NOT FINAL clause indicates that t_person can be inherited from when defining another
type.
Table Inheritance
More Examples
Definition of People object
We may want to store extra information in the database about people who are students,
and about people who are teachers.
The primary goal of the ODMG was to put forward a set of specifications that allowed a
developer to write portable applications for object database and object-relational mapping products.
In order to do that, the data schema, programming language bindings, and data manipulation and
query languages needed to be portable.
Object Model. This was based on the Object Management Group's Object Model. The OMG core
model was designed to be a common denominator for object request brokers, object database
systems, object programming languages, etc. The ODMG designed a profile by adding
components to the OMG core object model.
Object Specification Languages. The ODMG Object Definition Language (ODL) was used to
define the object types that conform to the ODMG Object Model. The ODMG Object
Interchange Format (OIF) was used to dump and load the current state to or from a file or set of
files.
Object Query Language (OQL). The ODMG OQL was a declarative (nonprocedural) language
for query and updating. It used SQL as a basis, where possible, though OQL supports more
powerful object-oriented capabilities.
C++ Language Binding. This defined a C++ binding of the ODMG ODL and a C++ Object
Manipulation Language (OML). The C++ ODL was expressed as a library that provides classes
and functions to implement the concepts defined in the ODMG Object Model. The C++ OML
syntax and semantics are those of standard C++ in the context of the standard class library. The
C++ binding also provided a mechanism to invoke OQL.
Smalltalk Language Binding. This defined the mapping between the ODMG ODL and Smalltalk,
which was based on the OMG Smalltalk binding for the OMG Interface Definition Language
(IDL). The Smalltalk binding also provided a mechanism to invoke OQL.
Java Language Binding. This defined the binding between the ODMG ODL and the Java
programming language as defined by the Java 2 Platform. The Java binding also provided a
mechanism to invoke OQL.
-End of unit 2
Handouts to follow.