Presentation is loading. Please wait.

Presentation is loading. Please wait.

OBJECT DATABASES and An Advent Open Source : DB4O Gözde Özahi CEng553 / Fall 2008.

Similar presentations


Presentation on theme: "OBJECT DATABASES and An Advent Open Source : DB4O Gözde Özahi CEng553 / Fall 2008."— Presentation transcript:

1 OBJECT DATABASES and An Advent Open Source : DB4O Gözde Özahi CEng553 / Fall 2008

2 Introduction to ODBMS Short History  İn existence now for nearly 2 decades  started with accomodating OO languages like Smalltalk, C++ and Java  with commercial products shipping the mid 90’s  today used in large scale applications including telecommunication, banking, manufacturing, insurance, shipping.  for applications having complex data  good at storing complex data

3 Introduction to ODBMS Important milestones of history  Early 1980s – Orion Research Project at MCC  Late 1980s – First wave of commercial products  1991 – ODMG (with 5 major OODMS vendors)  1995 – OODMS Manifesto (Malcolm Atkinson)  2001 – Final ODMG 3.0 standards released  2004 – Advent of Open Source (db4o released as free)

4 What is ODBMS? Referred as object-oriented DBMS Modeling and creation of data as objects  Support for classes of objects  Inheritance of class properities and methods by subclasses ODBMS must satisfy two criteria (The OODBMS Manifesto)  should be a DBMS  should be an OO system

5 What is ODBMS? no standard for what consituted ODBMS no standard query language (as SQL in RDBMS) originally thought to replace RDBMS (for better fit with OO languages). high switching cost directed to ORDBMS now established as a complement, not a replacement to RDBMS

6 ODBMS vs. RDBMS An object database (ODBMS) stores objects directly An object database (ODBMS) stores objects directly

7 Reational Model Weaknesses Data Model  A single bulk data type (relation)  No direct support Hierarchies (part-of or is-a). Advanced data types (spatial, multimedia...) Programming  impedance mismatches due to query language emphasis  Challenging to make existing application data persist.

8 Object Databases Motivation:to overcome RDB Weaknesses  Richer data models  Closer integration with programming languages Kinds of ODBs  Object relational (Oracle, DB2, PostgreSQL).  Semantic data model(Jasmine).  Programming language centred (Objectivity, FastObjects, Versant, ObjectStore).

9 Object Database Standards SQL-99:  Mainstream SQL standard.  Oracle, DB2, Informix. Object data management group (ODMG):  Outgoing mainstream object database standard.  Objectivity, FastObjects, Versant. Java data objects (JDO):  Java-specific object-based database access.  Poet, Versant, ObjectStore, SolarMetric...

10 Object Query Language (OQL) Declarative query language  Not computationally complete Syntax based on SQL (select, from, where) Additional flexibility (queries with user defined operators and types)

11 Example of OQL query The following is a sample query “what are the names of the black colored product?” Select distinct p.name From products p Where p.color = “black”  Valid in both SQL and OQL, but results are different.

12 Result of the query (SQL) Original table Product noNameColor P1Ford MustangBlack P2Toyota CelicaGreen P3Mercedes SLKBlack Result Name Ford Mustang Mercedes SLK The statement queries a relational database. => Returns a table with rows.

13 Result of the query (OQL) Product noNameColor P1Ford MustangBlack P2Toyota CelicaGreen P3Mercedes SLKBlack - The statement queries an object- oriented database => Returns a collection of objects. String Ford Mustang Result Original table String Mercedes SLK

14 Comparison Queries look very similar in SQL and OQL, sometimes they are the same In fact, the results they give are very different Query returns: OQLSQL Object Collection of objects Tuple Table

15 ODBMS for RDBMS Users RDBMS vendors (IBM, Informix, Oracle.. Adding ORDBMS functionality) OODM architecture and user expectations get into mix While RDB architectures are very similar, OODB architectures vary considerably. Consider your application’s characteristics and find which OODB architecture is best suited

16 Structured Data Types SQL:1999 allow uses to define new data types, in additions to built-in data types (e.g. integers) SQL:1999 also introduced two type constructors Types defined by using type constructors are structured data types  ROW  base ARRAY

17 Operations On Structured Data Creating a “row type” Example: create row type AddressType( street char(50), citychar(20)); create row type StarType( name char(30), address AddressType);

18 Operations On Structured Data Creating “Table” create table Address of type AddressType; create table MovieStar of type StarType; Instances of Row types are tuples in tables

19 Operations On Structured Data(sample query ) Find the names and street addresses of those MovieStars who stay in the city “Ankara”: select MovieStar.name, MovieStar.address.street from MovieStar where MovieStar.address.city = “Ankara”;

20 When to use an ODBMS (some example conditions) Embedded DBMS Applications Complex Data (object) Relationships Deep object Structures Changing Data (object) Structures Usage of agile techniques in development team Programming in an OO Language Used objects in developemtn is including collections

21 Advent of Open Source: DB4O

22 What is db4o? Open source object database 1,000,000 downloads, 20,000 registered community members 200 customers smoothly integrates into an OO system cutting down on development time by skipping the costly object-relational mapping stays highly reliable and performant

23 DB4O Concepts Object Container Querying Transaction Object Identity Indexing Inheritance

24 Object Container simple and straightforward interface to object persistence – ObjectContainer ObjectContainer is your db4o database  Java: ObjectContainer container = Db4o.openFile(filename)  open an ObjectContainer when the application starts and close it, when the session is finished all the basic functionality to work with persistent objects  save a new or updated object of any class using ObjectContainer#set(object)  Deletion is done with => Java: container.delete(object)

25 Object Container - Storing Objects public static void storePilot() { new File(YAPFILENAME).delete(); ObjectContainer db=Db4o.openFile(YAPFILENAME); try { Pilot pilot=new Pilot("Michael Schumacher",0); db.set(pilot); System.out.println("Stored "+pilot); // change pilot and resave updated pilot.addPoints(10); db.set(pilot); System.out.println("Stored "+pilot); } finally { db.close(); }

26 Querying db4o supplies three querying systems  Query-By-Example (QBE),  Native Queries (NQ), and  the SODA Query API.

27 Querying - QBE you provide db4o with a template object. db4o will return all of the objects which match all non-default field values public static void retrievePilotByName(ObjectContainer db) { Pilot proto=new Pilot("Michael Schumacher",0); ObjectSet result=db.get(proto); listResult(result); }

28 Querying - QBE QBE has some obvious limitations:  db4o must reflect all members of your example object.  You cannot perform advanced query expressions. (AND, OR, NOT, etc.)  You cannot constrain on values like 0 (integers), "" (empty strings), or nulls (reference types) because they would be interpreted as unconstrained.  You need to be able to create objects without initialized fields. That means you can not initialize fields where they are declared. You can not enforce contracts that objects of a class are only allowed in a well-defined initialized state.  You need a constructor to create objects without initialized fields.

29 Querying - NQ main db4o query interface recommended way to query databases from your application  simply use the semantics of your programming language  perfectly standardized  safe choice for the future your provide the ability to run one or more lines of code against all instances of a class

30 Querying - NQ db4o will attempt to optimize native query expressions and run them against indexes public static void primitiveQuery(ObjectContainer db) { List pilots = db.query(new Predicate () { public boolean match(Pilot pilot) { return pilot.getPoints() == 100; } }); }

31 Querying – SODA Query API db4o's low level querying API allowing direct access to nodes of query graphs SODA uses strings to identify fields  Not perfectly typesafe  compile-time not checked  quite verbose to write For most applications Native Queries will be the better querying interfaceNative Queries

32 Querying – SODA Query API public static void retrieveAllPilots() { ObjectContainer db=Db4o.openFile(YAPFILENAME); try { Query query=db.query(); query.constrain(Pilot.class); ObjectSet result=query.execute(); listResult(result); } finally { db.close(); } how our familiar QBE queries are expressed with SODA

33 Transaction All work within db4o ObjectContainer is transactional implicitly started when you open a container the current transaction is implicitly committed when you close it again. ACID transaction model Data transaction journaling  zero data loss in case of system failure  automatic data recovery after system failure db4o core is thread-safe for simultaneous operations

34 Transaction – Commit choose to make a commit explicit or you may leave it for the #close() call public static void storeCarCommit(ObjectContainer db) { Pilot pilot=new Pilot("Rubens Barrichello",99); Car car=new Car("BMW"); car.setPilot(pilot); db.set(car); db.commit(); }

35 Transaction – Rollback do not want to save changes to the database, you can call rollback resetting the state of our database to the last commit point public static void storeCarRollback(ObjectContainer db) { Pilot pilot=new Pilot("Michael Schumacher",100); Car car=new Car("Ferrari"); car.setPilot(pilot); db.set(car); db.rollback(); }

36 Object Identity Db4o keeps references to all persistent objects whether they were retrieved, created or activated in this session The main role of the reference system  to provide access to the required data with the best speed  lowest memory consumption Performance and usability of the reference system depend much on how the system manages objects identities

37 Indexing Allows to index fields To request an index to be created by API method called in configuration file // assuming class Foo { String bar; } Db4o.configure().objectClass(Foo.class).objectField("bar").indexed(true); Once created will remain in database

38 Inheritance Subclasses and Inheritance with an example public class SensorReadout { private Date time; private Car car; private String description; /* * Suppose constructors and methods are here */ } public class TemratureSensorReadout extends SensorReadout {.... } public class PressureSensorReadout extends SensorReadout {.... }

39 Inheritance Suppose sensors are added to the database (two times) history.add(new TemperatureSensorReadout(new Date(), this, "oil", pollOilTemperature())); history.add(new TemperatureSensorReadout(new Date(), this, "water", pollWaterTemperature())); history.add(new PressureSensorReadout(new Date(), this, "oil", pollOilPressure())); retrieveTemperatureReadoutsQBE SensorReadout proto= new TemperatureSensorReadout(null,null,null,0.0); ObjectSet result=db.get(proto); listResult(result);

40 Inheritance Output: 4 BMW[Rubens Barrichello/99]/6 : Tue Jan 23 23:32:01 CET 2007 : oil temp : 0.0 BMW[Rubens Barrichello/99]/6 : Tue Jan 23 23:32:01 CET 2007 : water temp : 0.2 BMW[Rubens Barrichello/99]/6 : Tue Jan 23 23:32:01 CET 2007 : oil temp : 0.30000000000000004 BMW[Rubens Barrichello/99]/6 : Tue Jan 23 23:32:01 CET 2007 : water temp : 0.8

41 References Malcolm P. Atkinson, François Bancilhon, David J. DeWitt, Klaus R. Dittrich, David Maier, Stanley B. Zdonik: The Object-Oriented Database System Manifesto.The Object-Oriented Database System Manifesto Moira Norrie, Object Oriented Databases - Complete and up to date lecture series, ETH Zürich Moira Norrie www.db4o.com db4o-6.0-tutorial.pdf Db4o Reference Guide


Download ppt "OBJECT DATABASES and An Advent Open Source : DB4O Gözde Özahi CEng553 / Fall 2008."

Similar presentations


Ads by Google