Object-Oriented Database Management Systems (ODBMS) By Wendy Wooters CS157B ODBMS Outline Definition Persistent Programming Languages Object-Oriented Concepts Why Who Approaches Object Class & Encapsulation Inheritance & Polymorphism Object Identifier (OID) Advantages and Disadvantages Example Code Conclusion What is an ODBMS? Database that stores data elements as objects. Uses object-oriented concepts. Object - like an entity in and E-R Diagram. SSN Hired Name Salary Employee Why use ODBMS? Product DB Complex data or relationship requirements Lack of unique, natural identification Large numbers of many to many relationships Access using traversals. Graph/Tree structure. Frequent use of type codes such as those found in the relational schema Source: http://www.service-architecture.com/object-oriented-databases Who Uses ODBMS? Typical Applications for ODBMS: Computer-aided design (CAD) Computer-aided software engineering (CASE) Multimedia databases Images, video, games, etc. Office automation systems (OIS) Expert database systems Approaches for ODBMS Relational DB extended to use objectoriented concepts. (Object-relational DB) DB is Relational Programming language is object-oriented. Application Application Translation Object-oriented DB model. ODB Application and database use same object-oriented model. Uses persistent programming languages. RDB Persistence Programming Languages A programming language that directly manipulates persistent data in a database. Persistent data exists after the program terminates. Single program for application and data management. No translation from database to application programming needed. Used with the object-oriented DB model Application approach. ODB Object-Oriented Concepts Object Object is an entity containing: Variables/Attributes – Object Data Employee SSN:int Variables Relationships – References to other objects Methods – Object Functions Messages – Accessing Methods Name:String Hired:Date Salary:double … getSSN() Methods getName() setName() … Relationships Object-Oriented Concepts Class & Encapsulation Class encapsulates the data structure and operations of the object. Internals are hidden from the user. Public class Employee { //Class Attributes private int SSN; private String name; private Date hired; private double salary; … //Class Constructor public Employee() {…} //Class Accessor Methods public int getSSN() {…} public String getName() {…} public Date getHired() {…} public double getSalary() {…} User only knows available methods and how to call them. } //Class Mutator Methods public void setName(String newName) {…} public void setHired(Date newHired) {…} public void setSalary(double newSalary) {…} … Object-Oriented Concepts Inheritance & Polymorphism Inheritance - A class (subclass) can inherit the characteristic of another class (superclass). Example: Employee has inherited attributes and methods from Person. Superclass Person Subclass Employee Supplier Customer Polymorphism - Each subclass object can respond differently to same message by overriding the superclass method. Example: Object-Oriented Concepts Object Identifier Object Identifier (OID) – The unique OID is maintained by the DBMS. ODBMS - Generated automatically by the system. Example: Reference to Date object in the Employee object for the date hired. RDBMS – Primary key. Employee Date Example: SSN for Employee ODBMS Advantages Matches the object-oriented application design: Reduces code, execution time and paging Real world data model Easier Navigation Allows reusability of objects – generic objects can be used in many applications. Manages Complex data types more efficiently. Supports distributions of data across networks more efficiently. ODBMS Disadvantages Still developing Lack of accepted standards Lack of development tools. Change is more likely to occur in model More complicated than the relational model. Takes longer to learn. Not as efficient when data and relations are simple. Java & ODB Example Example of how to access data in an ODB, using the ODMG Object Query Language (OQL): Opens DB Starts a transaction Executes a query to find a Person object named “S. M. Lee” Does additional processing on this Person object Gets Address object of Person Update street of Address object Commit transaction Close database import org.odmg.*; import java.util.Collection; Implementation impl = new com.vendor.odmg.Implementation(); Database db = impl.newDatabase(); Transaction txn = impl.newTransaction(); try { db.open("addressDB", Database.OPEN_READ_WRITE); txn.begin(); // perform query OQLQuery query = new OQLQuery( "select x from Person x where x.name = \“S. M. Lee\""); Collection result = (Collection) query.execute(); Iterator iter = result.iterator(); // iterate over the results while ( iter.hasNext() ) { Person person = (Person) iter.next(); // do some addition processing on the person (now shown) // now traverse to the address object and update its value person.address.street = "13504 4th Avenue South"; } txn.commit(); db.close(); } //exception handling would go here ... Source: http://www.service-architecture.com/object-oriented-databases Conclusion Definition Persistent Programming Languages Object-Oriented Concepts Advantages and Disadvantages of ODBMS Example Code