200 likes | 414 Views
ORACLE 9i. Defining Objects in SQL and the Oracle Type Translator. Objects with SQL and OTT. Overview Objects in SQL99 and Oracle Types and Tables Mapping to C++ classes using OTT Defining objects in SQL OTT usage and C++ binding Exploiting Oracle Summary and Outlook.
E N D
ORACLE 9i Defining Objects in SQL and the Oracle Type Translator
Objects with SQL and OTT • Overview • Objects in SQL99 and Oracle • Types and Tables • Mapping to C++ classes using OTT • Defining objects in SQL • OTT usage and C++ binding • Exploiting Oracle • Summary and Outlook
Overview:Objects in SQL99 • Introduction of User Defined Types (UDT) • Introduction of unique Reference (Object ID) • “A type is a class” • “A row is an object” • Introduction of single inheritance • Methods, functions, procedures and computational completeness
Overview:Objects in Oracle9i • SQL99 Object model is implemented. • Introduces an explicit OBJECT type. • Has persistent (referenceable) and embedded (nonreferenceable) Objects (also called ‘value instances’). • Transient instances of persistent objects. • SQL objects can be mapped to C++ classes using the Object Type Translator utility.
Overview:Types and Tables • An Oracle Object Type is like a 'typedef' of a structure. • An Oracle Table (of Object types) holds a set of persistent Type instances.
Overview:Mapping to C++ • The User Defined Types (objects in Oracle) are defined in a user's schema using the SQL statement CREATE TYPE typename AS OBJECT • The Object Type Translator utility (OTT) generates C++ wrapper classes for objects.
Objects with SQL and OTT • Overview • Defining objects in SQL • OTT usage and C++ binding • Exploiting Oracle • Summary and Outlook
SQL Example CREATE TYPE "Coordinate_O"AS OBJECT ( "ra" NUMBER, "dec" NUMBER); CREATE TYPE "SkyObject_O"AS OBJECT ( "coord" "Coordinate_O", "brightness" NUMBER, "constellation" CHAR(20)) NOT INSTANTIABLE NOT FINAL; CREATE TABLE "SkyObject_tab"OF "SkyObject_O" SkyObject Coordinate Embedded Object
Embedded Object Inherited Objects to-one-link SQL Example CREATE TYPE "Spectrum_O"AS OBJECT ( "specData" BLOB ); CREATE TABLE "Spectrum_tab"OF "Spectrum_O" CREATE TYPE "Star_O"UNDER "SkyObject_O" ( "classification" CHAR(5), "metallicity" NUMBER, "spec" REF "Spectrum_O" ); CREATE TYPE "Galaxy_O"UNDER "SkyObject_O" ( "deVaucouleurClass" CHAR(5), "petrosianRadius" NUMBER); SkyObject_O Coordinate_O Galaxy_O Star_O Spectrum_O
Objects with SQL and OTT • Overview • Defining objects in SQL • OTT usage and C++ binding • Exploiting Oracle • Summary and Outlook
Object Type Translator SQL DDL INTYPE file OTT Type Definitions MAPFILE file CPPFILE file HFILE file Database Server OCCI Source Compiler OCCI library Linker Object file Executable 2 1 3 4 5
OTT Usage OTT userid=pkunszt/orapasswd code=cppintype=sky_in.typ outtype=sky_out.typmapfile=sky_map.cpp hfile=sky_ott.h cppfile=sky_ott.cpp sky_ott.h sky_ott.cpp sky_map.hsky_map.cpp sky_in.typ CASE = SAMETYPE "Coordinate_O" TYPE "SkyObject_O" TYPE "Star_O"TYPE "Galaxy_O" TYPE "Spectrum_O" sky_out.typ
Generated classes only contain Oracle types and code User classes can inherit from generated ones to add methods and transient data SkyObject Coordinate Galaxy Star Spectrum Adding your code SkyObject_O Coordinate_O Galaxy_O Star_O Spectrum_O
OTT replaces SQL name with userclass name Nested types, references now point to userclass, user-defined methods can be used Letting OTT know sky_in.typCASE SAMETYPE "Coordinate_O" GENERATE Coordinate_O AS Coordinate TYPE "SkyObject_O" GENERATE SkyObject_O AS SkyObject TYPE "Star_O" GENERATE Star_O AS Star TYPE "Galaxy_O" GENERATE Galaxy_O AS Galaxy TYPE "Spectrum_O" GENERATE Spectrum_O AS Spectrum
GENERATE clause also affects inheritance User types cannot have direct inheritance, e.g. SkyObject not a direct base class of Star Inheritance scheme SkyObject SkyObject_O PObject Star Star_O
Objects with SQL and OTT • Overview • Defining objects in SQL • OTT usage and C++ binding • Exploiting Oracle • Summary and Outlook
Inheritance possibilities • Inside Oracle schema only single inheritance • Outside 'proper' C++ with multiple inheritance • Can have 'mixed' persistent classes by inheriting from a persistent and a transient class
Stored Procedures • Object types can have server-side methods written in e.g. Java • Maps to a method in C++ • Very powerful for various applications • server-side processing • use Oracle's built-in JVM • use Oracle's querying capabilities
Summary • Complex data modeling using Oracle9i's object extensions is possible • SQL is the modeling language • C++ mapping similar to JDBC • All purely relational features are also accessible
Outlook • Internals of C++ mapping need to be understood (see test plan) • Collect requirements and possibilities of automating OTT tasks • Outstanding showstoppers (bugs preventing further progress) should be fixed soon, close contact with Oracle