Typen von Datenbanksystemen 4 Objektorientierte Datenbanksystemene Beispiele: POET, ObjectStore, Versant Objektorientierte Datenbanksysteme müssen haben: Komplex strukturierte Objekte (wie Java und C++) Objektidentität Kapselung Klassen Spezialisierungshierarchien Vererbung von Methoden, evtl. Mehrfachvererbung Statische Typisierung Datenbankprogrammiersprache (z.Zt. Java und C++) Erweiterbarkeit Versionsverwaltung Persistente Speicherung Sekundärspeicher Weitere Eigenschaften Anfragesprache Mehrbenutzerbetrieb Transaktionen Verteilte Datenhaltung Lange Transaktionen Es geht um: Objektmodell (Javaanpassung, ODL, Präprozessor oder Postprozessor) Objektspezifikationssprache Objektanfragesprache Programmiersprachenanbindungen Einige Charakteristika: Java-Klassen sind Datenbankdatentypen. Mismatch zwischen Programmiersprache und SQL: Navigation und Resultatorientierung ODL und OQL TFH Berlin/Steyer Typen von Datenbanksystemen Anwendung Bookshop ER-Modell Author Category Publisher Book OrderItem BookOrder Customer Ablauf der Programmentwicklung und -nutzung 1) Compilation des Programms (Java-like) 2) Postprozessor (oder Praeprozessor) verarbeitet die Java-Datentypdefinitionen. (In einer Datei stehen Datenbank, persistent gewünschte Klassen, gewünschte Indexe) 3) Ausführung (Java-like)/Programmablauf öffnen der Datenbank Beginn einer Transaktion suchen, wenn gefunden -> Ausgabe wenn nicht gefunden -> einfügen TFH Berlin/Steyer Typen von Datenbanksystemen void PopulateObj() throws ODMGException { Transaction txn = new Transaction (); txn.begin; try { Author a1 = new Author (“Andreas”, “Heuer”); Author a2 = new Author (“Gunter”,”Saake”); Book book = new Book (“3-8266-0513-6”); Book.setTitle (“Datenbabnken”); Book.setPrice (69.0); Book.addAuthor (a1); Book.addAuthor (a2); a1.addBook (book); a2.addBook (book); dbase.bind (book, “Mein Buch”); } catch (ODMGException exc) { txn.abort (); throw exc; } txn.commit (); } public static void main (String args[]) { if (args.length != 1) { System.out.println (‘usage: Populate dbname’); System.exit(1)); } try { Database db = Database.open (args[0]; Database.openReadWrite); Populate app = new populate (db); If (! App.lookupObj (); App.populateObj (); } catch (ODMGException exc) { exc.printStackTrace (); } } } TFH Berlin/Steyer Typen von Datenbanksystemen Book.java package bookshop; import COM.POET.odmg.collection.*; import java.util.Enumeration; /** * */ public class Book { String isbn, title; Double price; Publisher publishedBy; // invers zu Category classification; // invers zu ListOfObject writtenBy; // invers zu int stock; public Book (String isbn) { isbn = isbn; writtenBy = new ListOfObject (); } /** * */ public String getISBN () { return isbn; } public void setPrice (double p) { price = p; } public void setTitle (String s) { title = s; } public void setPublisher (Publisher p) { publishedBy = p; } public Publisher getPublisher () { return publishedBy; } public void addAuthor (Author a) { writtenBy.add (a); } Enumeration getAuthors () { Return writtenBy.elements (); } TFH Berlin/Steyer Typen von Datenbanksystemen public void setCategory (Category c) { classifiedIn = c; } public void Category getCategory () { return classifiedIn; } public void setStock (int num) { stock = num; } public double getPrice () { return price; } public void getStock () { return stock; } /** * */ public boolean reduceStock (int num) { if (stock > num) { stock -= num; return true; else return false; } /** * */ public String toString () { return “Book [“ + isbn + “, “ + title + “ : “ + stock + “]”; } } Author.java package bookshop; import COM.POET.odmg.collection.*; import java.util.Enumeration; /** * */ TFH Berlin/Steyer Typen von Datenbanksystemen public class Author { String firstname, lastname; ListOfObject hasWritten; // invers zu public Author (String first, String last) { firstname = first; lastname = last; hasWritten = new listOfObject(); } /** * */ public void addBook (Book b) { hasWritten.add (b);; } public Enumeration getBooks () { return hasWritten.elements (); } } Customer.java package bookshop; /** * */ public class Customer { int id; String name, city; Int zipcode; public Customer (int id, String s) { id = id; name = s; } /** * */ public void setAddress (int zip, String s) { zipcode = zip; city = s; } public String getName () { return lastname; } TFH Berlin/Steyer Typen von Datenbanksystemen public long getCustId () { return id; } } BookOrder.java package bookshop; import java.util.Date; import java.util.Enumeration; import COM.POET.odmg.collection.*; /** * */ public class BookOrder { public final static int OPEN = 1; public final static int DELIVERED = 2; double price; Date date; ListOfObject contains; int status; Customer orderedBy; public BookOrder () { price = 0.0; date = new Date (); contains = new ListOfObject (); status = OPEN; } /** * */ public void addItem (Book b, int n) { contains.add (new OrderItem (b, n)); } /** * */ public void setCustomer (Customer cust) { orderedBy = cust; } public Date getDate () { return date; } TFH Berlin/Steyer Typen von Datenbanksystemen public Enumeration getItems () { return contains.elements (); } /** * */ public boolean deliver () { Enumeration e; } // e = getItems (); while (e.hasMoreElements ()) { OrderItem item = (OrderItem) e.nextElement (); If (! Item.isAvailable ()) Return false; } // calculatePrice (); // e = getItems (); while (e.hasMoreElements ()) { OrderItem item = (OrderItem) e.nextElement (); Item.book.reduceStock (item.num); } // status = DELIVERED; return true; } /** * */ private void calculatePrice () { price = 0.0; Enumeration e = getItems (); while (e.hasMoreElements ()) { OrderItem item = (OrderItem) e.nextElement (); Price += item.getPrice (); } } } TFH Berlin/Steyer Typen von Datenbanksystemen OrderItem.java package bookshop; /** * */ class OrderItem { Book book; int num; public OrderItem (Book b, int n) { book = b; num = n; } /** * */ public boolean isAvailable () { return book.getStock () >= num; } /** * */ public double getPrice () { return book.getPrice () = num; } } Publisher.java package bookshop; import COM.POET.odmg.collection.*; import java.util.Enumeration; /** * */ public class Publisher { String name; String address; ListOfObject hasPublished; // public Publisher (String name, String addr){ name = name; address = addr; hasPublished = new ListOfObject (); } TFH Berlin/Steyer Typen von Datenbanksystemen /** * */ public String getName () { return name; } public String getAddress () { return address; } public String addBook (Book b) { hasPublished.add (b); } void Enumeration getBooks () { return hasPublished.elements (); } } Category.java package bookshop; import COM.POET.odmg.collection.*; import java.util.Enumeration; /** * */ public class Category { String name; ListOfObject contains; // public Category (String s) { name = s; contains = new ListOfObject (); } /** * */ public String getName () { return name; } public String addBook (Book b) { contains.add (b); } public Enumeration getBooks () { return contains.elements (); } } TFH Berlin/Steyer Typen von Datenbanksystemen Objekt-Browser Zeigt an: Klassen, roots, views TFH Berlin/Steyer