INF4180, Ifi, UiO 1 10.09.2003 commercial ORDBS (examples): - ORACLE - Sybase - Informix (Illustra) - IBM - CinCom (UNISQL, Total) - Microsoft - ... INF4180, Ifi, UiO commercial OODBS (examples): - GemStone (Brokat Infosys AG) - O2 (Ardent -> Informix) - ObjectivityDB - ObjectStore (ODI -> eXcelon) - POET - Versant - Jasmine (Computer Associates) - ... two ways to integrate object-orientation into DBS -> both directions are also reflected in standards developments 3 Object-Oriented DBS vs. Object-Relational DBS 10.09.2003 Standardization Efforts Object-Oriented Database Systems INF4180, Ifi, UiO 2 ¥ ¥ ¥ ¥ ¥ 10.09.2003 INF4180, Ifi, UiO 4 Prediction: - both kinds of systems will exist, used for different kinds of applications ¥ ¥ ¥ substantial investment in SQL-based relational DBSs => evolutionary approach systems are more robust due to many years of usage and experience application development tools data security transaction processing performance day-to-day business requirements, e.g. online backup ¥ ¥ simpler way for programmers to use DBS (familiar with OOPLs) ÒseamlessnessÓ, no Òimpedance mismatchÓ OO functionality + DBS functionality => higher performance for specific applications ÒrevolutionaryÓ approach, no legacy problems ORDBS OODBS Object-Oriented DBS vs Object-Relational DBS 10.09.2003 ¥ OMG: Object Model, OMA -> CORBA, POA, PSS ¥ ODMG 3.0 version Object-Oriented DBS (OODBS) standards ¥ Object-Oriented ¥ Object-Relational Object Data System Vendors Overview Complex Data Simple Data INF4180, Ifi, UiO 10.09.2003 INF4180, Ifi, UiO Examples of other members (vendors and end-users): Informix Software Inc., Apple Computer, Philips, Olivetti, IBM, AT&T, Groupe Bull, ICL, Enfin Systems, Canon, Unisys, Architecture Project Management, British Telecom, Citicorp, Royal Bank of Canada, John Deere, Microsoft, etc. Original members: ¥ 3COM ¥ American Airlines ¥ Hewlett-Packard Co. (HP, Palo Alto, CA) ¥ Sun Microsystems Inc. (Mountain View, CA) International software industry consortium (started 1989) today: 800+ companies Object Management Group (OMG) 10.09.2003 How large is the upper-right corner? ¥ ÓMany applications will migrate from the upper-leftÓ ¥ ÓIt is growing and it will engulf upper-left and lower-rightÓ Object-Oriented DBMS File System No Query Object-Relational DBMS Relational DBMS Query Michael StonebrakerÕs Application Matrix: ¥ Classify your problem into one of the four quadrants ¥ Use a DBMS optimized for the quadrant 7 5 Object-Oriented DBS vs. Object-Relational DBS OMG Focus INF4180, Ifi, UiO INF4180, Ifi, UiO IDL (Interface Definition Language) OMA (Object Management Architecture) CORBA (Common Object Request Broker Architecture) Ð CORBA 1: 1991 Ð CORBA 3: 2000 CORBA Facilities and CORBA Services 10.09.2003 ¥ ¥ ¥ ¥ Common Goal: Create a component-based software marketplace by hastening the introduction of standardized object software. Establish industry guidelines and detailed object management specifications to provide a common framework for application development. 10.09.2003 ¥ OMG: Object Model, OMA -> CORBA, POA, PSS ¥ ODMG 3.0 version Object-Oriented DBS (OODBS) standards ¥ Object-Oriented ¥ Object-Relational Object Data System Vendors Overview 8 6 Analysis and Design Ð UML (Unified Modeling Language) Ð XMI (XML Metadata Interchange) Ð MOF (Meta-Object Facility) Real-Time CORBA ORB (Object Request Broker) 23 Domain Task Forces Ð Business Objects, C4I, e-Commerce, Finance, Healthcare, Life Science, Manufacturing, Telecommunications, etc. Facilitated by the ORB (Object Request Broker) ¥ INF4180, Ifi, UiO OMA sets the component software environment Ð how components provide services Ð how facilities provide services Ð how CORBA services provide services ¥ 10.09.2003 OMA specifies the overall object model that is used in distributed object computing environments, including Ð how objects are defined and created, Ð how client applications invoke objects, Ð how objects can be shared. ¥ OMA (Object Management Architecture) INF4180, Ifi, UiO 9 11 OMA (Object Management Architecture and Reference Model) 10.09.2003 ¥ Architecture Board ¥ Domain Technology ¥ ¥ ¥ Platform Technology OMG Technology etc. 10.09.2003 ORB: ¥ Name service ¥ Request dispatch ¥ Parameter encoding ¥É Application objects: ¥ Spreadsheet ¥ CAD tool ¥ Accounting ¥ Editors ¥ É. Application Objects INF4180, Ifi, UiO CORBA Object Services Object Request Broker (ORB) Horizontal Facilities 10 12 Object Services: ¥ Naming ¥ Transaction ¥ Persistent State ¥ Security ¥ Query ¥É Components: Vertical facilities: ¥ Account Receivable ¥ Healthcare ¥ Account Payable ¥ e-Commerce ¥ Ledger ¥ É. ¥ É. EJB CCM Vertical Component Component Facilities EJB CCM Container Container OMA Reference Model Horizontal facilities: ¥ Internationalization ¥ MOF ¥ É. INF4180, Ifi, UiO Business Object Initiative CWM (Common Warehouse Model) CCM (CORBA Component Model) Java and Internet integration MOF (Meta Object Facility) PSS (Persistent State Service) Quality of Service Control Real Time CORBA UML (Unified Modeling Language) Workflow Management XMI (XML Metadata Interchange) 10.09.2003 ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ OMG Current Efforts INF4180, Ifi, UiO 13 10.09.2003 INF4180, Ifi, UiO Implementation of OIDs is not specified. 15 Characteristics can vary over time, whereas identity (OID) is constant. OID provides a means to denote or refer to the object. Each object has a unique identity (object identifier, OID) that is distinct from and independent of any of its characteristics. OMG: Object Identiy & Object Identifiers 10.09.2003 - basic concepts - object identity and object identifiers - object types - value types - operations - subtyping and inheritance - argument passing and results - interfaces of a type - implementation CORBA includes an object model of types, operations, and subtyping. In the object model, the user can manipulate instances but not types or operations as first-class objects. OMG: CORBA Object Model OMG: Object Types INF4180, Ifi, UiO 14 10.09.2003 INF4180, Ifi, UiO Types are arranged into a type hierarchy that forms a lattice (i.e. a directed acyclic graph). Every instance of a type satisfies the interface of that type. The set of operation signatures defined on a type is called the type«s interface. Each operation has a signature, which consists of a name, set of parameters, and set of results. 16 Objects are created as instances of their types. Objects cannot change their types. Types describe these operations and thus characterize the behavior of objects. Operations applicable to an object characterize its behavior. Objects support only certain operations. 10.09.2003 Attribute: An interface may have attributes. An attribute is logically equivalent to a pair of accessor functions: one to retrieve the value and one to set the value. Operation: An operation is an identifiable entity that denotes the indivisible primitive of service provision that can be requested.. Interface: An interface is a description of a set of possible operations that a client may request of an object, through that interface. Type: A type is an identifiable entity with an associated predicate (a single-argument mathematical function with a boolean result) defined over entities. An entity that satisfies a type is called a member of the type. Object: An object is an identifiable, encapsulated entity that provides one or more services that can be requested by a client. Client: An object system provides services to clients. A client of a service is any entity capable of requesting the service.. OMG Object Model - Basic Concepts 17 10.09.2003 10.09.2003 Client INF4180, Ifi, UiO A request consists of: ¥ target object ¥ operation ¥ parameters ¥ optional request context Request ORB Object implementation OMG: Request in OMA INF4180, Ifi, UiO 19 Each operation has a signature consisting of: - name - set of parameters - the result - exceptions that may be raised by an invocation Value Types provide Ópass by valueÓ semantics OMG: Subtyping and Inheritance INF4180, Ifi, UiO 18 10.09.2003 INF4180, Ifi, UiO Operation dispatching: when an operation request is issued, a specific operation implementation (method) is selected for execution. Inheritance allows a type to be defined in terms of another type. Inheritance is a mechanism for reuse. 20 Relationships between types define the type hierarchy (directed acyclic graph) Subtyping defines the rules which objects of one type are determined to be acceptable in contexts expecting another type. Subtyping (specialization) is a relationship between types based on their interfaces. 10.09.2003 The set of operation signatures defined on a type is called the type«s interface. Request and operations are not objects. Objects + Value Types = Set of Denotable Values Basic values include Short, Long, LongLong, Ushort, Ulong, UlongLong, Float, Double, LongDouble, Fixed, Char, Wchar, String, Wstring, Boolean, Octet, Enum, Any Operation Invocation = Request: is an event that indicates an operation, possibly with a list of parameters, to perform on behalf of a requester (client), possibly causing results to be returned. Operation (definition of signature) describes an action that can be applied to parameters. OMG: Operations A value type is an entity which shares many of the characteristics of interfaces and structs. It is a description of both a set of operations that a client may request and of state that is accessible to a client. Instances of a value type are always local concrete implementations in some programming language. OMG: Value Types OMG: Implementation INF4180, Ifi, UiO 21 10.09.2003 INF4180, Ifi, UiO Implementations may vary among different instances of a type and even for the same instance over time. An individual object, at any given point in time, is an instance of one class. The combination of a type specification and one of the implementations defined for that type is called a class. 23 The object model formally specifies only the semantics of objects, nothing about implementation. 10.09.2003 If an operation request returns successfully, it was performed exactly once; if it returns an exception indication, it was performed at-most-once. Expressions result in Value Types or OIDs (denotable values). Operationally, the denotable values are copied into the formal parameters. The objects the OIDs refer to are not copied. -> check: is request legal? Execution semantics consist of arguments and return values to formal parameters. OMG: Argument Passing and Results OMG: CORBA INF4180, Ifi, UiO 22 10.09.2003 INF4180, Ifi, UiO 24 - Static and Dynamic Invocation Interfaces (SII, DII) - Interface Definition Language (IDL) - C Language Mapping - Interface Repository (IR) - ORB Interface and Server Implementation - Basic and Portable Object Adapter Interfaces The basis distributed object computing components defined in CORBA include: Standard that defines specific ways for objects and clients within a distributed environment to interact. 10.09.2003 Interface inheritance provides the composition mechanism for permitting an object to support multiple interfaces. An interface is a description of a set of possible operations that a client may request of an object, through that interface. It provides a syntactic description of how a service provided by an object supporting this interface, is accessed via the set of operations of the objectÕs type. A type exports all the operations that are defined on it. OMG: Interfaces of a Type Callee Skeleton Request ORB1 Object implementation ORB2 INF4180, Ifi, UiO IIOP (Internet Inter-ORB Protocol) hides differences in platform and software (programming language, OS, ORB) 27 Object implementation 25 Network interface Stub Caller OMG: Inter-ORB Interoperability INF4180, Ifi, UiO after Compiler Basic Object Adapter may only be used in same ORB POA = Portable Object Adapter is used across ORBs 10.09.2003 Client 10.09.2003 before Callee Caller Interface description OMG: CORBA Ð Remote Procedure Calls 10.09.2003 Accesses Client Includes Interface definitions INF4180, Ifi, UiO Client stubs Describes 28 Object implementation Includes Implement. skeletons 26 Implement. repository Implementation installation OMG: CORBA - Interfaces Upcall interface INF4180, Ifi, UiO interface/operation Object adapter Normal call interface Implement. Skeletons interface/adaptor ORB core ORB interface Proprietary interface Client stubs Object implementation interface Interface repository 10.09.2003 Dynamic invoke Client OMG: CORBA Internal Architecture OMG: CORBA Object Services INF4180, Ifi, UiO INF4180, Ifi, UiO Naming Service Trader Service Event Service Notification Service Transaction Service Concurrency Service Security Service Licensing Service Lifecycle Service Relationship Service Persistent State Service Externalization Service Property Service Query Service Time Service 10.09.2003 ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ ¥ 10.09.2003 31 29 Pseudo-Objects: requests, named-value lists, contexts, interface definition objects, implementation definition objects -- integer types -- floating point types -- char, boolean, octet - constructed types (struct, union, enum) - template types (sequence, string) - array IDL Data Types: - basic types: Object Interfaces (IDL) Type in general refers to things that may be specified as arguments or results in the signatures of operations. OMG: CORBA - Types and Object Interfaces User Interface Common Facilities Ð Internationalization Ð Printing Information Management Common Facilities Ð Meta Object Facility System Management Common Facilities Ð XCMF (superceded by CCM (CORBA Component Model)) Task Management Common Facilities Ð Workflow Facility (with Workflow Management Coalition) 10.09.2003 INF4180, Ifi, UiO Services have now much higher priority than common facilities. ¥ ¥ ¥ ¥ INF4180, Ifi, UiO OMG: Horizontal (Common) Facilities 10.09.2003 Features of operations that can be specified in IDL: - invocation semantics - parameter directions - exceptions raised - context A client initiates a request by calling a stub routine specific to the object type or by constructing the request dynamically via the DII (Dynamic Invocation Interface). A client performs a request by having access to an object reference for an object and knowing the immediate type of the object and the desired operation to be performed. 32 30 OMG: CORBA - Operations and Requests INF4180, Ifi, UiO SIGs (Special Interest Groups): Ð C4I (Command, Control, Communications, Computers and Intelligence) Ð GIS (Geographic Information Systems) Ð Analytical Data Management Ð Distributed Simulation Ð É 10.09.2003 ¥ OMG: Vertical (Domain) Facilities Ð 3 INF4180, Ifi, UiO Business Object Facilities Ð Task and Session Ð Document Repository Integration Finance Facilities Ð Currency Ð Party Ð General Ledger Electronic Commerce Facilities Ð Negotiation Ð Public Key Infrastructure Manufacturing Facilities Ð Product Data Management Ð High-Level Architecture (HLA Simulation) 10.09.2003 ¥ ¥ ¥ ¥ OMG: Vertical (Domain) Facilities Ð 1 35 33 34 10.09.2003 INF4180, Ifi, UiO network-accessible objects method Object method method method method method method method Object Object method method method method Object method method method method Object Request Broker Object Services: - interface repository - lifecycle services - transaction management -É Object Object method Object method method method method method method method Object 36 OMG: CORBA Used to Create an OODBS INF4180, Ifi, UiO Telecommunications Facilities Ð A / V Stream Control Ð Notification Ð CORBA/TMN (Telecommunication Management Network) and CORBA/IN (Intelligent Network) Interworking Facilities Ð Log Facility Transportation Ð Air Traffic Control HCI Facility Healthcare Ð Person Identifier Service Ð Lexicon Query Service Utilities Ð Utility Management System (in process) Life Science Research Ð Biomolecular Sequence Analysis (in process) Ð Genome Mapping (in process) 10.09.2003 ¥ ¥ ¥ ¥ ¥ OMG: Vertical (Domain) Facilities Ð 2 INF4180, Ifi, UiO method Object method method method method method method method Object Object method method method method Object method method method method Object Object INF4180, Ifi, UiO ¥ An implementation of an Abstract Storagehome, stores instances of its corresponding Storagetype Ð Storagehome ¥ The declared type of a container to store instances of an Abstract Storagetype Ð Abstract Storagehome ¥ An implementation of an Abstract Storagetype Ð Storagetype ¥ The declared type of stored data to persistently encode an object type (struct) Ð Abstract Storagetype ¥ Provides persistent storage for object data, may be a RDBS, OODBS, ORDBS or file system 39 37 method Object method method method method method method method Object Database (persistent objects) ODBMS PSS: Basic Concepts Ð 1 Basic Concepts Ð Datastore 10.09.2003 ¥ 10.09.2003 application structures or objects method method method method Application Program OMG: Application Access to an OODBS PSS: Sub-Storagetyping INF4180, Ifi, UiO internal interface Datastore domain type_B type_A INF4180, Ifi, UiO store_B store_A If type_B is a subtype of type_A, and if store_B is a storagehome for type_B, and if store_A is a storagehome for type_A, then store_B must be a subtype of store_A. 10.09.2003 ¥ 10.09.2003 external interface Servants ORB domain Interfaces OMG Persistent State Service 40 38 41 10.09.2003 INF4180, Ifi, UiO 43 Note: Any change to a storage object incarnation is reflected in the persistent state of the corresponding storage object (after commit, flush, etc.) storagehome PersonStoreImpl of PersonImpl implements PersonStore {}; storagetype PersonImpl implements Person {}; #include <People.psdl> // In file PeopleImpl.psdl INF4180, Ifi, UiO ¥ A CORBA object (in a process) bound to a Storage Object Ð Storage Object Incarnation ¥ A persistent state stored for an object. Is not a CORBA object, cannot be invoked, has a pid, not a CORBA Ref Ð Storage Object ¥ Kind of catalog, provides transactional semantics Ð Session ¥ Superset of IDL, used to declare PSS entities ¥ IDL + abstract storagetype, abstract storagehome, storagetype, storagehome, catalog Ð PSDL ¥ Provides access to a storagehome Basic Concepts, cont. Ð Catalog 10.09.2003 ¥ PSS: Basic Concepts Ð 2 Using PSS INF4180, Ifi, UiO 42 10.09.2003 INF4180, Ifi, UiO 44 CosPersistentState.ConnectorRegistry connectorRegistry = CosPersistentState.ConnectorRegistryHelper.narrow( myOrb.resolve_initial_references(ÒPSSÓ) ); CosPersistentState.Connector connector = connectorRegistry.find_connector(ÒÓ); // create session CosPersistentState.Session mySession = connector.create_basic_session( org.omg.CosPersistentState.READ_WRITE,ÒÓ,parameters); // find person home (personHome is a storage home instance) PersonHome personHome = (PersonHome) mySession.find_storage_home(ÒPSDL:PersonHomeImpl:1.0Ó); // create person Knut Person p = personHome.create(00010154321, ÒKnutÓ, Ò2200 9000Ó); 10.09.2003 abstract storagetype Person { readonly state long social_security_number; state string full_name; state string phone_number; }; abstract storagehome PersonHome of Person { Person create(in long ssn, in string full_name, in string phone); }; catalog People { provides PersonHome person_home; }; // In file People.psdl INF4180, Ifi, UiO 10.09.2003 DBMS ¥ 10.09.2003 Clustering Strategies ¥ get set INF4180, Ifi, UiO Access Paths (Indexes) Schema Types from Application Object Model ¥ ¥ Changes for a DBMS INF4180, Ifi, UiO get set 47 10.09.2003 ¥ What Changes? INF4180, Ifi, UiO 45 ¥ Must create an Object-Relational mapping to overcome the impedance mismatch Ð In the application only (RDBMS) Ð In both application and database (OODBMS) Ð In the database only (ORDBMS?) ¥ When using ÒObjectsÓ in an application, Where are the objects? Object-Relational Data Mapping get set Naive Architecture for a Database 10.09.2003 public class JPersonImpl implements JPerson { private long _ssn; private String _name; private String _phoneNumber; public long socialSecurityNumber() { return _ssn } // etc. } // Java public interface JPerson { public long socialSecurityNumber(); public String fullName(); public void fullName(String newName); public String phoneNumber() public void phoneNumber(String newNumber); } Transparent Persistence 48 46 Overview INF4180, Ifi, UiO INF4180, Ifi, UiO 50 10.09.2003 INF4180, Ifi, UiO ¥ OMG: Object Model, OMA -> CORBA, POA, PSS ¥ ODMG 3.0 version 10.09.2003 INF4180, Ifi, UiO 52 ¥ Most important application domains: GIS (Geographic IS), CAD (Computer Aided Design) and Genome DBS ¥ Incorporate most object-oriented concepts, but lack good support of several DBS concepts Object-Oriented DBS (OODBS) standards ¥ Developed from object-oriented programming languages (PL) Object-Oriented Databases (1. Generation) 10.09.2003 ¥ Intermediate stadium: persistent object-oriented PL (persistence means that data survive program run-time) 51 49 ¥ There are many links to info on both OODBMSs and ORDBMSs at http://www.cetus-links.org/oo_db_systems_2.html ¥ http://www.rational.com/products/rose/whitepapers.jsp ¥ http://www.sun.com/software/javablend/index.html ¥ There are links to several whitepapers on the ODMG site http://www.odmg.org/library/whitepapers.htm#Database ¥ Crossing Chasms (from PLoP 95) http://members.aol.com/kgb1001001/Chasms.htm ¥ Connecting Business Objects to Relational Databases (from PLoP 98) http://www.joeyoder.com//papers/patterns/ ¥ Relational Database Access Layers (from PLoP 96) (PLoP = The Pattern Languages of Programs Conference) http://www.sdm.de/en/tec/pub/art/art/arcus/relz_abstract.htm Object-Relational Mapping References ¥ Object-Oriented ¥ Object-Relational Object Data System Vendors 10.09.2003 > < Encapsulated Database Architecture 53 10.09.2003 INF4180, Ifi, UiO 55 - Language Bindings (OML - Object Manipulation Language) - Object Query Language (OQL) - Object Definition Language (ODL) - Object Model - (Architecture) Main components: Designed for ODS The Object Data Standard (Version 3.0) INF4180, Ifi, UiO - ObjectDesign - Objectivity - Ontos - O2 Technology (Ardent) - POET Software - Servio (Gemstone) (- SunSoft) - Versant 10.09.2003 other members: - American Management Systems - Anderson Consulting - EDS - Fujitsu - Hewlett-Packard - Intellitic - MITRE - Persistence Software - Sybase - UniData - Texas Instruments voting members: started in 1991 ODMG (Object Database Management Group) - CERN - Micro Data Base Systems - NEC - Versant other members: INF4180, Ifi, UiO 54 10.09.2003 INF4180, Ifi, UiO 56 - DBMS: shared service for transaction and lock management - DBs can be shared among applications on a network - applications access DBs, types must conform to declarations - schema declarations - source program - declarations for application schema (data + operations) - common architecture for ODS products ODMG: Architecture 10.09.2003 Object Data: OO and OR Plus 8 academic reviewers (Alagic, Dittrich, King, Liskov, Maier, Moss, Soloman, Zdonik) - eXcelon (was ObjectDesign) - Objectivity - POET Software - Sun Microsystems voting members: Release 3.0 in 2000 ODMG (Object Data Management Group) Today - syntax for object model based on IDL (CORBA) + referential integrity and collections - common data model to be supported by OODBS -- objects with OIDs -- object behavior, state of objects, named objects -- operation signatures -- properties (attributes or relationships) -- attribute / relationship signatures -- collection types -- inheritance -- ... INF4180, Ifi, UiO 10.09.2003 INF4180, Ifi, UiO -> OQL as embedded language -> complex OQL queries -> simple OQL queries - based on SQL syntax whereever possible - declarative query language for querying DB objects ODMG: Object Query Language (OQL) 10.09.2003 59 57 - subset of the object model provides interoperability across PLs ODL is intended to define object types that can be implemented in a variety of PLs: - based in OMG specifications, ODMG object model is superset of OMG object model) INF4180, Ifi, UiO 58 10.09.2003 INF4180, Ifi, UiO - 3 components of PL binding: ODL, OQL, OML 60 - PL-specific binding respects the syntax and semantics of the base PL -> small set of extensions to the base PL - one single unified type system across PL and DBS - based on extending a PL syntax and semantics in order to provide DBS capabilities rather than embedding statements in SQL or another language -> goal: seamlessness ODMG: Object Manipulation Language (OML) - Language Bindings (C++, Smalltalk, Java) - 10.09.2003 - used to define application schema; schema can subsequently be translated into declarations of desired PL ODMG: Object Definition Language (ODL) ODMG: Object Model 10.09.2003 10.09.2003 } INF4180, Ifi, UiO 0 boolean dirty ... oid myDB 0 db_Object_Id DatabaseName Type* aRef<Type> Database Memory Typical Proxy Implementation INF4180, Ifi, UiO An object which is an instance of a class that inherits from d_Object is said to be Òpersistence capableÓ. class d_Object { public: mark_modified(); //mark Object as modified void* operator new(size_t size); void* operator new(size_t size, const d_ Ref_Any &cluster, const char *typename); void* operator new(size_t size, d_Database *database, const char *typename); virtual void d_activate(); virtual void d_deactivate(); } ODMG C++ Binding 63 61 10.09.2003 10.09.2003 INF4180, Ifi, UiO T* operator->() { //dereference the Ref if (cachePtr != 0) return cachePtr; else { // validate myDB exists, permissions, etc, then ... DatabasePage* temp = new DatabasePage; // read database page containing object oid // from database myDB into temp ... // locate object oid in temp ... cachePtr = ... // Ptr to local object copy } } Typical Ref-> Implementation INF4180, Ifi, UiO d_Ref is an example of the Proxy Design Pattern template <class T> class d_Ref { public: d_Ref(); d_Ref(T *fromPtr); //constructor d_Ref(const d_Ref<T>&); //constructor ... T* operator->(); //dereference the Ref operator T*(); //applies to non-const T& operator T*() const; void delete_object(); //delete object - all copies ... } ODMG C++ Binding (cont.) 64 62 Database Sets or Navigation? Both ways! INF4180, Ifi, UiO } 65 INF4180, Ifi, UiO Ð The result of a navigational query is the desired object in the database, from which one can use a PL for further computation OQL also supports navigational queries that use paths based on pointers and relationships to navigate in the database to locate the desired data (like the network data model) 67 Ð The result to such queries is a collection object containing a collection of objects, an object, a collection of literals, or a literal (or undefined) OQL supports declarative queries that return a set of objects (like SQL does for relational databases) 10.09.2003 ¥ ¥ 10.09.2003 0 boolean dirty ... oid myDB db_Object_Id DatabaseName Type* aRef<Type> Memory Typical Ref-> Result INF4180, Ifi, UiO 10.09.2003 INF4180, Ifi, UiO ¥ Names of attributes, relationships, operations and other variable names are written in lower case (smŒ bokstaver) ¥ Names of classes (of mutable objects) are written beginning with a capital letter (stor forbokstav) ¥ OQL reserved words are written in bold font Conventions (like Eaglestone & Ridley) 10.09.2003 68 66 ¥ OQL can also be used from PLs like C++, Smalltalk, and Java ¥ OQL can be used as a stand-alone query language to write ad hoc queries ¥ OQL is a declarative (not procedural) language allowing to define what you want to know, instead of how you get to the result ¥ OQL is the query language of the ODMG standard Object Query Language (OQL) :String ÒConsultantÓ Title Engineer Consultant Salesman Secretary Recursing on OQL expr INF4180, Ifi, UiO :String ÒSecretaryÓ 69 10.09.2003 INF4180, Ifi, UiO 71 query In the OQL grammar, there is a selectExpr | expr production rule from the undercastExpr lined non-terminal to the next line orExpr | ( type ) castExpr orelseExpr { or orelseExpr } andExpr { orelse andExpr } quantifierExpr { and quantifierExpr } andthenExpr | for all inClause : andthenExpr | É equalityExpr { andthen equalityExpr } relationalExpr { ( = | != ) relationalExpr } | É additiveExpr { ( < | <= | > | >= ) additiveExpr } É multiplicativeExpr { + multiplicativeExpr } | É inExpr { * inExpr } unaryExpr { in unaryExpr } + unaryExpr | É | postfixExpr primaryExpr { ( . | -> ) identifier [ argList ] } | É ( query ) 10.09.2003 :String ÒEngineerÓ Result in SQL: :String ÒSalesmanÓ :Set<String> Result in OQL: select distinct E.title from Employees E where department = 4 Example: set query 10.09.2003 INF4180, Ifi, UiO INF4180, Ifi, UiO conversionExpr | collectionExpr | aggregateExpr | undefinedExpr | objectConstruction | structConstruction | collectionConstruction | identifier [ argList ] | queryParam | literal | ( query ) OQL Grammar primaryExpr primaryExpr ::= 10.09.2003 <query> ::= <selectExpr> | <expr> <expr> <op> <expr> ¥ or The type of sub-expressions are subject to restrictions depending on the type checking rules for the operator used <op> <expr> 72 70 With unary and binary operators <op>, expressions can be built recursively from sub-expressions: An expression returns an object or a literal A query is a query expression with no bound variables ¥ ¥ ¥ ¥ OQL: a Typed Expression Language literal with value 17 of type integer INF4180, Ifi, UiO ::= first ( query ) | last ( query ) | unique ( query ) | exists ( query ) distinct(bag(1,2,1,2,3)) = a set of 1,2,3 bag(1,2,1,3) minus bag(2) = a bag of 1,1,3 bag(1,2) union bag(1,2,3)) = a bag of 1,2,1,2,3 Operators work with multiplicity on bags. INF4180, Ifi, UiO INF4180, Ifi, UiO 10.09.2003 75 Set Operators INF4180, Ifi, UiO Set operators: union, intersect, and except (minus or difference) 10.09.2003 Type of e1+e2: if type(e1) = list(t1) and type(e2) = list(t2) and t1 is compatible with t2, then type(e1+e2) = list(lub(t1,t2)) (lub = least upper bound) 10.09.2003 listtoset ( query ) | element ( query ) | distinct ( query ) | flatten ( query ) array ( [ valueList ] ) | set ( [ valueList ] ) | bag ( [ valueList ] ) | list ( [ valueList ] ) | list ( listRange ) element({person1}) = Person: person1 ::= ::= Example: Class City {array(museum) museums } oslo.museums[2] norskMuseums = oslo.museums+bergen.museums collectionConstruction OQL Collections flatten(list(set(1,2,3),set(3,4,5,6),set(7)) = a set of 1,2,3,4,5,6,7 flatten(list(list(1,2),list(1,2,3)) = a list of 1,2,1,2,3 flatten(set(list(1,2),list(1,2,3)) = a set of 1,2,3 conversionExpr 73 (element) (element) (boolean) (boolean) First(select students from course where course.name=ÒINF4180Ó) collectionExpr Conversion Operators for Collections 10.09.2003 select c.name bag of String (names of cities) where the city from c in Cities has more than 5 museums in the database where c.name in ( select m.name from m in Museums group by m->city having count > 5) Cities set of City objects in the database assuming City.extent is named Cities and there are no duplicates set of Person objects with name=ÒEarlÓ or the unique Person object with name = ÒEarlÓ assuming type(Pindex) is dictionary<Person, String> Pindex.lookup(ÒEarlÓ) 17 Example OQL Queries 76 74 INF4180, Ifi, UiO scope of y 10.09.2003 INF4180, Ifi, UiO The LEAST_FIXED_POINT operator can easily be implemented by a method written in this language However, OQL is computationally supplemented by an OO programming language through one of the ODMG programming language bindings (DML) The LEAST_FIXED_POINT operator (as defined in OMGÕs object algebra) cannot be expressed in OQL OQL is not Computationally Complete! 10.09.2003 select f ( y [, partition] ) from x in X where p(x) scope of x group by y: g(x) having h(y, partition) order by o(y, partition) selectExpr ::= select [ distinct ] projectionAttributes fromClause [ whereClause ] [ groupClause ] [orderClause ] OQL selectExpr 79 77 10.09.2003 from w in t.description ) ) ) INF4180, Ifi, UiO Type of result = struct(Museum, set(Tour)) from m in Museum where m in ( select distinct w.what from t in Tour and s.capacity > 20 ) where s.theme = t.theme from s in Tour Tours: flatten ( select ( select s select struct( M: m, have the same theme as some tour that already visits the museum. For each museum, find all tours with a capacity of more than 20 that Complex Example 78