130 likes | 343 Views
Chapter 7 Java Binding. Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University. Contents. 7.1 Introduction 7.2 Java ODL 7.3 Java OML 7.4 Java OQL. 7.1 Introduction(1). Language design principles one principle
E N D
Chapter 7Java Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University OOPSLA Lab
Contents • 7.1 Introduction • 7.2 Java ODL • 7.3 Java OML • 7.4 Java OQL OOPSLA Lab
7.1 Introduction(1) • Language design principles • one principle • perceive the binding as a single language for expressing both database and programming operation • several corollaries • a single unified type system • respect the Java language • respect the automatic storage management semantics of Java • Language binding • two ways to declare persistence-capable Java classes • existing Java classes • Java class declaration generated by a preprocessor for ODMG ODL OOPSLA Lab
7.1 Introduction(2) • Use of Java language features • namespace • the ODMG Java API will be defined in a vendor-specific package name • implementation extensions • provide the full function signature for all the interface methods specified • Mapping the ODMG object model into Java • object and literal • ODMG object type maps into a Java object type • ODMG atomic literal types map into their equivalent Java primitive types • no structured literal types in the Java binding • structure • the object model definition of a structure maps into a Java class • implementation • interface and abstract classes cannot be instantiated OOPSLA Lab
7.1 Introduction(3) • collection classes • the Java binding provides at least one implementation for each of the following collection objects public interface Set extends Collection {….} public interface Bag extends Collection {….} public interface List extends Collection {….} • array • the ODMG array collection maps into either the primitive array type, the Java Vector class, or the ODMG VArray class • relationship • not yet supported by the Java binding • extents • not yet supported by the Java binding • keys • not yet supported by the Java binding OOPSLA Lab
7.1 Introduction(4) • names • objects may be named using methods of the Database class defined in the Java OML • exception handling • an exception is thrown using the standard Java exception mechanism OOPSLA Lab
7.2 Java ODL • Attribute declaration and types • Relationship traversal path declarations • not yet supported in the Java binding • Operation declaration • operation declarations in the Java ODL are syntactically identical to method declaration in Java OOPSLA Lab
7.3 Java OML(1) • Object creation, deletion, modification, and reference • object persistence • persistence by reachability : a transient Java object that is referenced by a persistent Java object will automatically become persistent • object deletion • no notion of explicit deletion of objects • object modification • modified persistent Java object will have their updated fields reflected in the object database • object locking • support explicit locking using methods on the Transaction object • Properties • uses standard Java syntax for accessing attributes and relationships • Operation • defined as methods in the Java language OOPSLA Lab
7.3 Java OML(2) • Collection interface • a comforming implementation must provide these collection interface • Collection • Set • Bag • List • interface Collection Public interface Collection { // Chapter 2 operations public int size(); // unsigned long cardinality() public boolean isEmpty(); // boolean is_empty() public void add(Object obj); // void insert_element(…) public Object remove(Object obj); // void remove_element(…) public boolean contains(Object obj); // boolean contains_element(…) public Enumeration elements(); // Iterator create_iterator(…) …….. } OOPSLA Lab
7.3 Java OML(3) • Transaction • implemented as object of class Transaction • the creation of new transaction object implicitly associates it with the caller’s thread • class Transaction Public class Transaction { // Create new transaction object and associate it with the caller’s thread Transaction(); // Attaches caller’s thread to this existing Transaction; // any previous transaction detached from thread public void join(); ……… public void begin(); public void commit(); public void abort(); ……. } OOPSLA Lab
7.3 Java OML(4) • Database operations • the predefined type Database represents a database • class Database Public class Database { // Access modes public static final int notOpen = 0; public static final int openReadOnly = 1; ….. // Returns the database the name specified. // Opens database if not already open. public static Database open(String name, int accessMode) throws ODMGException; public void close() throws ODMGException; // Named object binding and lookup public void bind(Object object, String name); public Object lookup(String name) throws ObjectNameNotFoundException; …… } OOPSLA Lab
7.4 Java OQL(1) • Java OQL binding • support the full functionality of the object query language • two ways that use this functionality • query method on class Collection • queries using on a stand-alone OQLQuery class • Collection query method • Collection interface has a query member function • Collection query(String predicate) • example SetOfObject mathematicians; mathematicians = Students.query( “exists s in this.takes: s.section_of.name = \”math\” ”); OOPSLA Lab
7.4 Java OQL(2) • OQLQuery class • allows the programmer to create a query • example class OQLQuery{ public OQLQuery(){} public OQLQuery(String query){…} // You can construct or .. public create(String query){….} // assign a query. public bind(Object parameter){…} public Object execute() throws ODMGException {…} } Bag mathematicians; Bag assistedProfs; Double x; OQLQuery query; mathematicians = Students.query(“exist s in this.takes: s.sectionOf.name = \”math” ”); query = new OQLQuery( “select t.assistants.taightBy from t in TA where t.salary > $1 and t in $2”); x = new Double(50000.0); query.bind(x); query.bind(mathematicians); assistedProfs = (Bag) query.executed(); OOPSLA Lab