ODMG Object Programming Language Bindings

Similar documents
ODBMS: PROTOTYPES & PRODUCTS. The ODBMS Manifesto [M.Atkinson & al 89]

Chapter 11 Object and Object- Relational Databases

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 21 1

Chapter 12 Object and Object Relational Databases

Chapter 21 9/4/2012. Object Database Standards, Languages, and Design. Chapter 21Outline. Chapter Objectives. ODMG Objects and Literals

ObjectStore and Objectivity/DB. Application Development Model of Persistence Advanced Features

ODMG 2.0: A Standard for Object Storage

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Glossary. abort. application schema

ODMG C++ Binding Guide

Object Database Standards, Languages, and Design

Part 3: Object-Oriented Database Management Systems

What are the characteristics of Object Oriented programming language?

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Introduction to Programming Using Java (98-388)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

ITCS Jing Yang 2010 Fall. Class 16: Object and Object- Relational Databases (ch.11) References

Tokens, Expressions and Control Structures

Persistency. Author: Youhei Morita

CSE 431S Type Checking. Washington University Spring 2013

Object Query Standards by Andrew E. Wade, Ph.D.

C++ (Non for C Programmer) (BT307) 40 Hours

VALLIAMMAI ENGINEERING COLLEGE

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Chapter 5 Object-Oriented Programming

3. Object-Oriented Databases

15CS45 : OBJECT ORIENTED CONCEPTS

Java Overview An introduction to the Java Programming Language

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

CS2141 Software Development using C/C++ C++ Basics

Java Primer 1: Types, Classes and Operators

Instantiation of Template class

5/23/2015. Core Java Syllabus. VikRam ShaRma

CS201 Latest Solved MCQs

Short Notes of CS201

TYPES, VALUES AND DECLARATIONS

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

CS201 - Introduction to Programming Glossary By

Introduction to Databases Object and Object-Relational Databases

Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt

W5.L2. Week 5, Lecture 2

Object Oriented Paradigm

2. The object-oriented paradigm

STRUCTURING OF PROGRAM

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

1 Shyam sir JAVA Notes

Object typing and subtypes

Object-Oriented Design

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

ADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Chapter 6 Introduction to Defining Classes

Introducing C++ to Java Programmers

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Procedure and Object- Oriented Abstraction

COP 3330 Final Exam Review

Ch. 21: Object Oriented Databases

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

C++11 and Compiler Update

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Types. What is a type?

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Motivation was to facilitate development of systems software, especially OS development.

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

EECS 2011 M: Fundamentals of Data Structures

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Objects Managing a Resource

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Object Oriented Programming. Solved MCQs - Part 2

Sample Copy. Not for Distribution.


Modern Programming Languages. Lecture Java Programming Language. An Introduction

C# and Java. C# and Java are both modern object-oriented languages

3. Java - Language Constructs I

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

Motivation was to facilitate development of systems software, especially OS development.

COURSE 11. Object-Oriented Databases Object Relational Databases

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduction to C++ with content from

C++ Important Questions with Answers

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

Inheritance and Interfaces

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review

Polymorphism. Contents. Assignment to Derived Class Object. Assignment to Base Class Object

Advanced Systems Programming

Java Language Features

A flow chart is a graphical or symbolic representation of a process.

Several major software companies including IBM, Informix, Microsoft, Oracle, and Sybase have all released object-relational versions of their

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

JVA-103. Java Programming

PROGRAMMING IN C++ COURSE CONTENT

An Object Oriented Programming with C

Transcription:

ODMG Object Programming Language Bindings 1 Objectives Implement the abstract model mapping concepts mapping types mapping collections Adapt the model whenever necessary some concepts are not supported by the language interface: in C++ ==> class association: in C++ and Java ==> attributes of type Ref <T> keys: in C++ and Java ==> no keys! Integrate the OQL Query Language 2 1 1

Benefits Extend programming language with persistent capability migrate programming applications in memory to databases manipulate object databases with standard programming language Provide to programming language database functionality: querying transactions security indexing,... OODB 3 Architecture PL ODL Declarations ODL Pre-processor Generated Declarations in PL Application Source Code in PL ODBMS Metadata ODBMS Runtime PL Compiler Object Code Linker Database Objects Executable Application ODBMS Runtime 4 2 2

I) ODMG C++ BINDING 5 Design Principles Provide a C++ library where there is a unified type system across the programming language and the database The C++ binding maps the ODMG Object Model into C++ through a set of persistence-capable classes Uses C++ template classes for implementation Based on the smart pointer ( ref-based ) approach Main Features Mapping between ODMG types and C++ types Access to Meta-schema C++/OQL Coupling The OML/C++ is C++ compliant (i.e. standard C++ compilers) Compatible with Standard Template Library (STL) + persistence 6 3 3

Persistence-capable Classes For each persistence-capable class, a twin class is defined Instances of a persistence-capable class behave like C++ pointers (but OIDs C++pointer) Instances may contain built-in types, user-defined classes, or pointers to transient data accessible through C++ references during a transaction The C++ binding defines the class as the superclass of all persistence-capable classes Persistence propagation by inheritance Persistence declaration during creation time The notion of interface is implicit in ODMG C++ binding interface: public part of C++ class definitions implementation: protected and private parts of C++ class definitions 7 Persistence-capable Classes: An O2 Example class Person: public { private: char* name; d_ref<person> spouse; d_set<d_ref<person>> family; public: Person (char* name); ~Person(); }; Persistence-capable class class Person: { private: char* name; d_ref<person> spouse d_set<d_ref<person>> family; public: Person (char* name); ~Person(); protected: virtual void o2_new(); virtual void o2_read(); virtual void o2_write();... }; Twin class in O2 8 4 4

Mapping the ODMG Object Model into C++ ODMG Φ C++ Φ Φ Φ Φ Φ Φ Φ 9 ODMG C++ ODL The database schema is derived from the C++ class hierarchy All primitive C++ data types are explicitly supported except: unions, bit fields, and references Objects may refer others only through a smart pointer called Several predefined structured literal types are provided, including: A number of basic fixed-length types is also supported There is a list of parameterized collection classes:, C++ interpretation of the ODMG relationships The class provides an interface to the extent for a persistence-capable class 10 5 5

C++ ODL Basic Types Basic Type Range Description d_short 16 bits signed integer d_long 32 bits signed integer d_ushort 16 bits unsigned integer d_ulong 16 bits unsigned integer d_float 32 bits single precision d_double 64 bits double precision d_char 8 bits ASCII d_octet 8 bits no interpretation d_boolean d_true,d_false 11 C++ ODL d_ref A is parameterized by the type of the referenced object is defined as a class template: can be converted into, in order to support a reference to any type, similar to that of Operators and are defined to compare the objects referenced, rather than memory addresses (shallow copy semantics) The dereferencing operator ( ) is used to access members of the persistent object addressed by the specific reference 12 6 6

C++ ODL Collections,,,, are subclass of The collections classes are delivered as templates: Elements therein are accessed through iterators Elements to be inserted in a collection must define: default ctor, copy ctor, dtor, assignment op, and equality op; types requiring ordering must also provide the less-than op 13 C++ ODL Collections: Examples R T R S R R... T T S R R... T T S T T... 14 7 7

C++ ODL Relationships Declaring various types of relationships between classes 1-1: 1-n: or and m-n: or and or Relationships are also implemented with class templates Creating, traversing and updating relationships using C++ OML 15 C++ ODL Relationships: Example extern const char _dpt[],_emps[]; class Department { d_rel_set <Employee,_dpt> emps; }; class Employee { d_rel_ref <Department,_emps> dpt; }; const char _dpt[] = "dpt"; const char _emps[] = "emps"; d e dpt emps initial state d e dpt emps final state 16 8 8

C++ ODL d_extent<t> The class provides an interface to the extent of a persistence capable class in the C++ binding The database schema definition contains a parameter for each persistent class specifying whether the ODBMS should maintain the extent for the class The content of this class is automatically maintained by the ODBMS The class includes optional support for polymorphism Comparison and set operations are not defined for this class 17 ODMG C++ OML Object creation Object deletion Object modification Object naming Manipulating collections C++/OQL 18 9 9

Database and Memory Cache The class allows the type definer to specify when a class is capable of having persistent, as well as transient instances persistent Cache Pointers to transient objects in a newly retrieved persistent object must be initialized by the application When a persistent object is committed, the ODBMS sets its embedded s to transient objects to null Binding-specific member functions and called when a persistent object enters, or exits respectively the application cache transient Database 19 Object Creation Whether an object is transient or persistent is decided at creation time Objects are created with the operator, overloaded to accept arguments specifying object lifetime transient object persisted object to be placed near the object persistent object to be placed in the database (unspecified clustering) Examples: 20 10 10

Object Deletion Deleting a persistent object is done with the operation, which is a member function of the class The effect of the delete operation is to cut the link between the referenced object in memory and the corresponding object into the database The definitive deletion is subject to transaction commit persistent Cache transient Database 21 Object Modification When a persistent object is brought into memory, its initial state is identical to the database state In memory, the state is modified by updating properties or by invoking operations on it, as regular C++ ops To inform the runtime ODBMS that the state has been modified we need a special function of class In some implementations, it is possible to detect that the state of an object has been modified The ODBMS updates the database at transaction commit time persistent Cache transient Database 22 11 11

Object Naming & To retrieve objects in a database we need persistent names These names are the root of the persistency A name can identify a unique object or a collection of objects Object names can be assigned and modified at run-time The facility for naming is related with the class Objects of this class are transient and their semantics do not include actual database creation Other supported operations include opening and closing an existing database 23 Examples of Object Naming d_session session; d_database base; d_transaction trans; session.set_default_env; session.begin(argc, argv); base.open("origin"); trans.begin( ); d_ref<person> adam=new(&base) Person("adam"); base.set_object_name(adam,"adam"); trans.commit; base.close( ); session.end( );... session.set_default_env; session.begin(argc,argv); base.open("origin"); trans.begin( ); adam=base.lookup_object("adam ); d_ref<person> eve=new (&base) Person ("eve"); adam -> spouse = eve; d_ref <Person> cain=new (&base) Person ("cain"); adam->family.insert_element (cain); trans.commit; base.close( ); session.end( ); 24 12 12

Iterating on Collections To iterate on collections a template class is defined Iterators can be obtained though the method defined in the class The function return the value of the currently pointedto element in the collection (if any) The function checks the end of iteration, advancing the iterator and returning the current element Iterators mean great flexibility: collection type independence element type independence generality and reusability d_iterator <d_ref<person>> iter= adam->family.create_iterator ( ); d_ref <Person> s; while (iter.next (s)) {... } 25 OQL Embedded in C++ Queries are supported in two forms: collections vs database Directed queries on collections made through the method of collection classes they require as parameter the query predicate in a string; the syntax is that of the OQL where clause the result is returned in a second collection class Queries on the database first an object of type must be constructed then the query must be executed with the function Professor teaches Course taught_by takes taken_by Student 26 13 13

Query Examples d_set < d_ref < Student > > Students, mathematicians, old; Students.query (mathematicians, "exists c in this.takes: c.subject = Math "); d_oql_query q1( "select s from s in $1 where exists c in s.taken_by: s.age > c.taught_by.age"); query = q1 << Students; d_oql_execute ( query, old ); query = q1 << others; d_oql_execute ( query, old); 27 Queries on the Database returns either a collection, or an iterator on a collection (both are type-checked) queries can be constructed incrementally (using ) queries can be parameterized parameters in the query string are signified with the shift-left operator ( ) is used to provide values as right-hand operands the clear method re-initializes the query, so that it can be reused with different values upon successful execution of a query the values are automatically cleared 28 14 14

Schema Access The ODMG database schema can be accessed through appropriate interfaces defined in the C++ binding The schema-access API is in effect an object-oriented framework C++ specific ODL extensions are included in the schema-access API (the C++ ODL is a superset of the ODMG ODL) Currently only the read interface is defined; the write interface is vendor-dependent Schema access is necessary not only for inspecting a database schema, but also for manipulating it at run-time (e.g. extents) 29 The ODMG Schema Access Class Hierarchy - d_scope - d_meta_object - d_module [d_scope] - d_type - d_class [d_scope] - d_ref_type - d_collection_type \- d_keyed_collection_type - d_primitive_type \- d_enumeration_type [d_scope] - d_structure_type [d_scope] \- d_alias_type - d_property - d_relationship \- d_attribute - d_operation [d_scope] - d_exception - d_parameter \- d_constant - d_inheritance 30 15 15

II) ODMG Java BINDING 31 Main Features Unified type system between the Java language and the database No modifications to Java syntax Java classes can be made persistence-capable importation: Java classes ODMG ODL exportation: ODMG ODL Java classes Automatic storage management semantics of Java transient, dynamic persistency Transparent access and update to the database Collections Query facilities 32 16 16

Persistency Persistency is by reachability from persistent roots All the persistent objects are directly or transitively attached to the persistent root At commit time if an object is connected to a persistent root then the object is written automatically into the database The class allows to define persistent roots and to retrieve them: (Object, String) // give a name ( String) // retrieve an object by its name 33 Retrieving and Creating Objects: Example Database base = new Database; Database base = new Database; base.open ("origin"); base.open ("origin"); Transaction trans = new Transaction; Transaction trans = new Transaction; trans.begin ( ); trans.begin ( ); Person adam = base.lookup("adam"); Person adam = new Person ("adam"); Person eve = new Person ("eve"); base.bind (adam, "adam"); Person cain = new Person ("cain"); trans.commit ( ); adam.spouse = eve; base.close ( ); adam.family.insertelement(cain); trans.commit ( ); base.close ( ); 34 17 17

Interface Database public class Database { public static Database open ( String name) throws ODMGException; public void close ( ) throws ODMGException; public void bind (Object obj, String name); public Object lookup (String name) throws ObjectNaneNotFoundException; } 35 Primitive Java Types Basic Type Description integer Integer class short Short class long Long class float Float class boolean Boolean class char, byte, string Char class 36 18 18

Mapping from ODMG to Java ODMG Date Struct or tuple Set (t) Bag(t) List (t) Array (t) Iterator. Java java.sql.date Java Class interface Set interface Bag interface List array type [ ] or Vector Enumeration.. 37 ODMG Java OML Same Java syntax for manipulating persistent or transient objects Object creation is done with the operator If an object type intermixes persistent data and transient data only persistent data is loaded in memory, transient data is set to default There is no object deletion since persistency is by reachability Modification of objects is done with standard Java operations At commit time modifications are written back automatically Collection interfaces Collection, Set, Bag, List The interface Transaction provides standard operations as: ( ), ( ), ( ) Operations are also defined for using the possibility of multithreading in Java, such operations are: join, current, etc. Java/OQL Coupling similar to the C++ binding; is used instead of 38 19 19

Interface Collection public interface Collection { public int size ( ); public boolean isempty ( ); public removeelement ( );... public Collection query (String predicate); } 39 Interface Set public interface Set extends Collection { public Set union (Set otherset); public Set intersection (Set otherset);... public boolean propersubsetof (Set otherset);... } 40 20 20

Interface List public interface List extends Collection { public void add (int index, Object obj) throws ArrayIndexOutOfBounds; public void put (int index, Object obj) throws ArrayIndexOutOfBounds;... public Object get (int index) throws ArrayIndexOutOfBounds; public List concat (List other); } 41 OQL Embedded in Java Directed queries on collections Filtering a collection with the operation defined in the interface Example : SetOfObject mathematicians; mathematicians = Students.query("exists c in this.takes: c.subject= Math "); Queries on the database Using the class (String question) and the operations (Object parameter) and () Example : Set Students, young; OQLQuery q1; q1 = new OQLQuery ("select s from s in $1 where s.age = $2"); q1.bind(students); q1.bind(25); young = (Set) q1.execute ( ); 42 21 21

General Architecture Java Application read, write Java Object Cache ODBMS Engine Object Database 43 Conclusion Java is well adapted to become a database programming language Some features of the ODMG model are not supported: Relationships & collections are not parameterized by a type or a class Extents & Keys The concepts of Java interface and implementation allow the possibility to define very powerful implementations for Set and List with HashSet, ArraySet, ArrayList, LinkedList, etc. 44 22 22

V) REFERENCES G. McFarland, A. Rudmik, and D. Lange: Object-Oriented Database Management Systems Revisited, Modus Operandi, Inc. 1999 F. Manola: An evaluation of Object-Oriented DBMS Developments Technical Report GTE Labs, 1994 C. Delobel: The ODMG PL Bindings, Course Slides, University of ORSAY B. Amann: Object-Oriented Database Systems, Course Slides, CNAM, Paris G. Gardarin: Bases de Données - Relationnel et Objet Course Slides, Université de Versailles Saint-Quentin-en-Yvelines A. Paramythis: Object Database Standard 2.0: Programming Language Bindings, Course CS551 Presentation, Heraklion Crete 45 23 23