240 likes | 353 Views
Chapter 6 Smalltalk Binding. Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University. Contents. 6.1 Introduction 6.2 Smalltalk ODL 6.3 Smalltalk OML 6.4 Smalltalk OQL 6.5 Schema Access 6.7 Future Directions. 6.1 Introduction(1).
E N D
Chapter 6Smalltalk Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University OOPSLA Lab.
Contents • 6.1 Introduction • 6.2 Smalltalk ODL • 6.3 Smalltalk OML • 6.4 Smalltalk OQL • 6.5 Schema Access • 6.7 Future Directions OOPSLA Lab.
6.1 Introduction(1) • Language design principles • two principles • bind to Smalltalk in a natural way • support language interoperability consistent with ODL • several implication • single unified type system • respect the Smalltalk syntax • respect that Smalltalk is dynamically typed • respect the dynamic memory management of Smalltalk OOPSLA Lab.
6.1 Introduction(2) • Smalltalk language binding • based upon OMG Smalltalk IDL binding • can be automated by ODL compiler • processes ODL declarations and generates a graph of meta objects • binding generator • generate Smalltalk class and method skeletons for meta objects OOPSLA Lab.
6.1 Introduction(3) ODL Compiler ODL Declarations regeneration generation Meta Objects Class Objects Language Binding type class Object Instance OOPSLA Lab.
6.1 Introduction(4) • Mapping the ODMG object model into Smalltalk • object and literal • object type maps into Smalltalk class • relationship • not directly supported by Smalltalk • implemented by Smalltalk method • names • use Smalltalk system dictionary • extents • not supported by this binding • use the database naming protocol to explicitly register and access named Collection OOPSLA Lab.
6.1 Introduction(5) • keys • not supported by this binding • use the database naming protocol to explicitly register and access named Dictionaries • collections • Smalltalk provides a rich set of Collection subclass, including Set, Bag, List, Dictionary, and Array class OOPSLA Lab.
6.2 Smalltalk ODL • Smalltalk/ODL Binding • based upon the OMG Smalltalk/IDL binding OOPSLA Lab.
6.2.1 OMG IDL Binding Overview(1) • Identifier • IDL allows the use of underscore character in its identifier • Smalltalk does not allow the use of underscore character • Smalltalk/IDL binding provides a conversion algorithm • month_of_year in IDL, becomes monthOfYearin Smalltalk • Interfaces • all objects that have IDL definition must implement a CORBAName method • anObject CORBAName • Objects • Smalltalk object that has an associated IDL definition may be a CORBA object OOPSLA Lab.
6.2.1 OMG IDL Binding Overview(2) • Operations • Smalltalk/IDL binding support the CORBAParameter protocol IDL current(); days_in_year(in ushort year); from_hmstz(in ushort hour, ushort minute, in float second, in short tz_hour, in short tz_minute); Smalltalk current daysInYear: fromHmstz:minute:second:tzHour:tzMinute: OOPSLA Lab.
6.2.1 OMG IDL Binding Overview(3) • Constants • Constants, Exception, and Enum in IDL are made available to Smalltalk in a global dictionary CORBAConstants • IDL : constant Time_Zone USpacific = -8; • Smalltalk : (CORBAConstants at: #’::Time::Uspacific) • Types • no separation of objects and datatypes in Smalltalk • simple types OOPSLA Lab.
6.2.1 OMG IDL Binding Overview(4) • compound types • binding example Union Number switch(boolean) { case TRUE: long integerValue; case FALSE: float realValue; }; struct Point{Number x; Number y;}; - Implicit bindings aPoint := Dictionary with: #x->452 with #y->687.44 - explicit bings using Smalltalk class Point OOPSLA Lab.
6.2.1 OMG IDL Binding Overview(5) • Exceptions • IDL exceptions are defined within modules and interfaces • Dictionaries are used to represent exception values Enum Weekday{Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; (CORBAConstants at: #’::Date::Wednesday) > (CORBAConstants at: #’::Date::Tuesday0 Enum exception InvalidDate{}; (CORBAConstants at: #’::DateFactory::InvalidDate’) CORBARaiseWith: Dictionary new OOPSLA Lab.
6.2.2 Smalltalk ODL Binding Extensions(1) • Interfaces and classes • interfaces and classes in ODL may be implemented by Smalltalk classes • all uses of the method CORBAName in the IDL binding are replaced by the method ODLName • this method will return the name of the ODL interfaces and classes • (ODLConstants at: #’::Date::Monday’) is a Weekday enum • (ODLConstants at: #’::Time::USpacific’) equals -8 • (ODLConstants at: #’::DateFactory::InvalidDate’) is an exception • Attribute declaration • used to define pairs of accessor operations that get and set attribute values • one-to-one correspondence between attribute defined within an ODL class and instance variables defined within the corresponding Smalltalk class • Smalltalk • rank • rank: aProfessorRank ODL attribute Enum Rank {full, associate, assistant} rank; OOPSLA Lab.
6.2.2 Smalltalk ODL Binding Extensions(2) • Relationship declaration • single-valued relationships Smalltalk Y formY: dropY: Y: “private” IDL attribute X Y; void form_Y(in X target); void drop_Y(in X target); ODL Relationship X Y inverse Z; ODL interface Course { …. Relationship Professor is_taught_by inverse Professor::teaches; …. } Smalltalk formIsTaughtBy:aProfessor dropIsTaughtBy:aProfessor isTaughtBy isTaughtBy: “private” OOPSLA Lab.
6.2.2 Smalltalk ODL Binding Extensions(3) • multivalued relationships IDL readonly attribute set<X> Y; void form_Y(in X target); void drop_Y(in X target); void add_Y(in X target); void remove_Y(in X target); Smalltalk Y formY: dropY: addY: “private” removeY: “private” ODL Relationship set<X> Y inverse Z; ODL interface Course { …. Relationship set<Course> teaches inverse Course::is_taught_by; …. } Smalltalk formTeaches:aCourse dropTeaches:aCourse teaches addTeaches:aCourse “private” removeTeaches:aCourse “private” OOPSLA Lab.
6.3 Smalltalk OML • Smalltalk OML • consist of a set of method • the syntax used to invoke operation on a persistent object should be no different from that used for objects of shorter lifetimes • all operations are invoked by sending messages to appropriate objects OOPSLA Lab.
6.3.1 Object Protocol • Object persistence • all Smalltalk object inherit from class Object • transitive persistence • a transient object that participates in a relationship with a persistent object will become persistent when a transaction commit occurs • Object deletion • no notion of explicit deletion of object • delete() operation from interface Object is not supported • an object is removed from the database during garbage collection • Object locking • two locking mode • read, write • a lock can be explicitly acquired on an object by sending the appropriate locking message it OOPSLA Lab.
6.3.2 Database Protocol(1) • Opening a database • send the open:method to an instance of the Database class database := Database new. (….set additional parameters as required …) database open:aDatabaseName • Closing a database • send the close message to the Database aDatabase close • Database names • each Database manages a persistent name space that maps string names to objects or collection of objects • bind:name: method • used to name any persistent object in a database • aDatabase bind:anObject name: aString OOPSLA Lab.
6.3.2 Database Protocol(2) • lookup:ifAbsent: method • used to retrieve the object • aDatabase lookup: aString ifAbsent: absentBlock • Schema access • the schema of a database may be accessed by sending the schema method to a Database instance • this method returns an instance of a Module that contains all of the meta objects that define the database’s schema OOPSLA Lab.
6.3.3 Transaction Protocol(1) • Transaction • implemented using methods defined on the class Transaction • transaction’s methods • aTransaction begin • aTransaction commit • aTransaction checkpoint • aTransaction abort • aTransaction join • aTransaction leave • aTransaction current • Exceptions • several exceptions that may be raised • noTransactionSignal • inactiveSignal • transactionCommitFailedSignal OOPSLA Lab.
6.4 Smalltalk OQL • Smalltalk OQL binding • loosely coupled binding • Future binding • more tightly integrated with the Smalltalk language OOPSLA Lab.
6.4.1 Query Class • Four attributes for instances of the class Query • queryResult : holds the object that was the result of executing the OQL query • queryStatus : holds the status of the query execution • queryString : the OQL query text to be executed • queryParameters : contains variable/value pairs • Example |query result| query := Query create: ‘select name from AllPeople where age > $1 and weight < $2’ params: #(45 150) query execute: Dictionary new. [query getStatus = Query complete] whileFalse: [Processor yield]. result := query getResult. OOPSLA Lab.
6.6 Future Directions • Keys and extents • A uniform set of Database administration operation OOPSLA Lab.