Object-Oriented Databases Commercial OODBMS: Part 1

• Objectivity/DB for ++ • ObjectStore PSE Pro for Java

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 1 Persistence Strategies

ƒ Persistence by inheritance ƒ persis tence capa bilities in her ite d from pre-dfiddefined pers itisten t c lass ƒ Versant (C++), Objectivity/DB (C++) ƒ Persistence by instantiation ƒ objects made persistent and get persistence capabilities upon instantiation ƒ ObjectStore (C++) ƒ Persistence byyy reachability ƒ objects made persistent if reachable from other persistent object

ƒ O2 (C++/Java), ObjectStore (Java), Versant (Java/), Objectivity/ /(/S)DB (Java/Smalltalk), ( (/Java/.NET) )OG, ODMG

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 2 Objectivity/DB

ƒ Object-oriented database management system ƒ deve lope d s ince 1993 by Objec tiv ity, Inc. ƒ version 9.3 released in October 2006 ƒ Contributions in associations and version management ƒ Originally based on C++ ƒ extddCtended C++ w ith propr itietary concep ts ƒ implemented using a special pre-processor ƒ Now has ƒ Smalltalk API ƒ Java API ƒ Python API ƒ SQL++ interface

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 3 Objectivity Product Family

ODBC Driver n

Administration oo C++ Java Smalltalk SQL++ Tools plicati olerant tion tion TT ee pp pp

Objectivity/DB O O

Database Servers Fault Data R

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 4 Extensions to C++

ƒ Create and delete objects ƒ Maintain and navigate associations between objects ƒ Access functions ƒ name and lookup objects, map dictionaries for indexing objects ƒ over object collections ƒ query andbjtithSQLitfd access objects using the SQL++ interface ƒ Version functions ƒ creatdltte and locate vers ions o fbjtf objects ƒ track version genealogy ƒ Copy and mo ve f unctions ƒ copy and move objects between containers

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 5 C++ Application Development Process

ƒ Design schema and create data model files in DDL ƒ Process data model files using the DDL processor ƒ Complete application source code ƒ Compile C++ application source files and data model source files ggypenerated by DDL processor ƒ Link compiled code with Objectivity/C++ runtime libraries ƒ Supported by provision of a Makefile

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 6 C++ Application Development Process

DDL SCSchema Code Application Code

DDL Processor

ShSchema ShSchema Source Code Header

chema C++ Compiler S

Objectivity Runtime Library Linker

Objectivity Federated Database Objectivity Application

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 7 Storage Classes

ƒ Basic object ƒ basic objects implement com.objy. db. iapp. Pers is ten t ƒ persistence by inheriting from com.objy.db.app.ooObj ƒ Container ƒ collection of basic physically clustered objects ƒ Database ƒ collection of containers ƒ comprises default container plus user-defined containers ƒ Federated database ƒ contains user-defined databases plus schema

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 8 Logical Storage Model

Federated Database User-Defined Database

Basic Objects

User-Defined Containers DfDefault ltC Con titainers

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 9 Persistence-Capable Classes

ƒ Every persistent instance of a persistence-capable class hitditlbjtlldithas an associated internal object called a persistor ƒ contains internal state and implements persistence behavior ƒ created when transient object made persistent and when existing persistent object is retrieved ƒ any operation on a persistent object is performed by calling the appropriate method of the object’s persistor ƒ Can support four general kinds of persistence behavior ƒ implicit persistence behavior ƒ explicit persistence ƒ handle persistent events ƒ automatic persistence with relationships

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 10 Inheriting Persistence Behaviour import com.objy.db.app.ooObj; ƒ Implicit persistence behaviour public class Author extends ooObj { ƒ get and set methods required private String name; private Date birthdate; ƒ default handling for persistent events public Author((g){String name) { (activate, deactivate, pre-write...) this.name = name; ƒ Non-static, non-transient fields this.birthdate = null; } ƒ numeric attributes public String getName() { ƒ string attributes return this.name; } ƒ date or time attributes public void se tName (Str ing name ) { ƒ references to other instances of this.name = name; persistent-capable classes } ƒ arrays of the above types ... }

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 11 Containers

ƒ Physical grouping of basic objects in database ƒ Third highest level in logical storage hierarchy ƒ Two different kinds of containers ƒ garbage-collectible: deleted objects are removed automatically ƒ non-garbage-collectible: deleted objects are not removed ƒ Functionality ƒ locking of objects ƒ idindexes ƒ object caching ƒ retrieving objects ƒ clustering objects

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 12 Containers

Connection connection = Connection.open("fdb", oo.openReadWrite); Session session = new Session(); session.begin(); ooFDObj fedDb = session.getFD(); if (fedDb.hasDB("PublicationsDB")) { ooDBObj pubDb = fedDb.lookupDB("PublicationsDB"); moiraPubs = new com.objy.db.app.ooContObj(); // Make the container persistent by adding it to a database pubDB.addContainer(moiraPubs, "MoirasPublications", 0, 5, 10); // Make article persistent by clustering it in a container Article a = new Article("Document Profiling to Enhance Collaboration"); moiPbltiraPubs.cluster()(a); } else { session.abort(); return; } session.commit(); Note: exception handling has been omitted!

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 13 Objectivity/DB Associations

ƒ Supports associations between objects ƒ dldeclare dithild within classes ƒ unary and binary associations ƒ binary associations represented internally as separate construct ƒ Mutual consistency of relationships is maintained ƒ Can attach semantics with associations ƒ delete and lock propagations ƒ copying behaviour ƒ versioning behaviour

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 14 Operation Propagation along Associations

ƒ Delete and lock operations can be propagated along associtiiations

delete

lock

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 15 Defining Associations public class Author extends ooObj { ... private ToManyRelationship publications; ... public static ManyToMany publicationspublications_Relationship Relationship() { return new ManyToMany( "publications", // relationship field "ch.ethz.globis.demo.Publication", // destination class "authors", // inverse relationship Relationship.COPY_MOVE, // copying behavior Relationship.VERSION_MOVE, // versioning behavior false, // delete propagation false, // lock propagation Relationship.INLINE_NONE // storage method ); } ... }

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 16 Persistent Collections and Iterators

ƒ Built-in persistent collections provide sets, lists and maps ƒ ordddered vs. unor ddddered and sca lbllable vs. non-scalbllable ƒ implement interface com.objy.db.util.ooCollection ƒ ooTreeListX, ooHashSetX, ooTreeSetX, ooMap, ooHashMapX and ooTreeMapX ƒ Object iterators ƒ step through a group of objects found in the federated database ƒ containers ƒ Scalable-collection iterators ƒ step through the objects in a scalable persistent collection

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 17 Retrieving Objects

ƒ Creating and following links ƒ Individual and group lookup of persistent objects ƒ through keys and iterators ƒ Parallel query ƒ Parallel Query Engine (Objectivity/PQE) ƒ divid es the query scope among a num ber o f query servers ƒ Content-based filtering ƒ predica te-query ltiiititdtilanguage supporting primitive types and stings ƒ used in predicate scans in group lookups ƒ used when following a to-many relationship ƒ used to find destination objects in parallel queries

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 18 ObjectStore Product Family

ƒ Both Java and C++ environments supported ƒ ObjectStore Personal Storage Edition (PSE) Pro ƒ pure Java-based lightweight ƒ lillarge, single-user dtbdatabases ƒ small memory footprint (~500kB) ƒ multithreaded ƒ embedded systems, mobile computing and desktop applications ƒ ObjectStore Enterprise ƒ high-performance, distributed, multi-user database ƒ distributed, ppjgersistent, transactional object caching ƒ clustering, online backup, replication, high availability ƒ Miggppration of applications to from PSE to Enter pyprise easy

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 19 Model of Persistence

ƒ Persistence by reachability ƒ dtbdatabase roo ts

Author moira = new Author("Moira C. Norrie"); db.createRoot ("Authors", moira);

ƒ Persistence capable classes ƒ post-processor makes classes persistent capable ƒ Persistent aware classes ƒ can access and manipulate persistent objects but are not themselves persistent

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 20 Persistent Objects

ƒ After being loaded into memory, persistent objects can be in one o f th e f oll ow ing three s ta tes ƒ hollow: used as a proxy and loaded on demand (lazy loading) ƒ active: when the object is loaded into memory its flag is set to clean, after an update the flag becomes changed to dirty ƒ stale: no longer valid (e.g. after a commit)

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 21 Persistent Capable Classes

ƒ Class java.lang.String ƒ WlfhWrapper classes from the java.lang package ƒ Boolean, Byte, Character, Double, Float, Integer, Long and Short ƒ Arrays of primitive and of any persistence-capable types

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 22 Collections

Map OSTreeMap OSTreeMapByteArray

OSTreeMapDouble

OSTreeMapFloat Set OSTreeMapInteger

OSAbstractSet OSTreeMapLong

OSTreeMapString OSHashSet OSTreeSet

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 23 Collections

Collection List

OSHashBag OSVector OSDictionary

OSVectorList OSHashtable

Map

OSHashMap

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 24 Post-Processing

1. Compile all source files

javac *.java 2. Post-process the class files → annotated versions of the class files

osjcfp –dest . –inplace *.class 3. Run the post -processed main class

java mainClass

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 25 IPersistent

ƒ Post-processing automatically annotates the class to implement the interface com.odi. IPers is ten t

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 26 Required Steps

ƒ Create a session

Session#create(String host, java.util.Properties properties)

ƒ Join a to a session

Session#join()

ƒ Create or open a database

Database#create(String name, int fileMode)

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 27 Required Steps

ƒ Start and commit transactions

Transaction#begin(int type) Transaction#commit(int retain)

ƒ Create database roots Database#createRoot((gString name, Object object)

ƒ Ending the session and closing the database

Session#terminate()

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 28 Object Deletion

ƒ In ObjectStore objects are deleted by ƒ remove object f rom all s truc tures accessibl e from da ta base roo ts ƒ persistent garbage collector automatically removes non-reachable objects ƒ No defragmentation results

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 29 Queries

ƒ Queries can only be defined over collections ƒ Predicate expressions are used

Query qqyuery = new Query(Author.class, "getName() == \"Moira C. Norrie\"");

ƒ Query evaluation

Collection result = query.select(authors);

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 30 Relationships

ƒ Java Dynamic Data classes (JDD) ƒ creattte, store and access persi ittdtbdstent data, based on sch ema ƒ defining types and their attributes ƒ creating entities of a type ƒ querying types ƒ creating indexes ƒ JDD introduces bi-directional relationships ƒ one-to-one, one-to-many, many-to-many ƒ referential integrity is maintained ƒ relationships need to be defined at runtime

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 31 Literature

ƒ Objectivity/DB ƒ http:// www.obj ecti vit y.com/ ƒ ObjectStore ƒ http: //www.progress.com/ obj ect st ore/

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 32 Next Week Commercial OODBMS: Part 2

for Java • OODBMS Architectures, Revisited and Defended

Oktober 24, 2008 Michael Grossniklaus – Department of Computer Science – [email protected] 33