Presentation is loading. Please wait.

Presentation is loading. Please wait.

OOPSLA Lab.1 Chapter 6 Smalltalk Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University.

Similar presentations


Presentation on theme: "OOPSLA Lab.1 Chapter 6 Smalltalk Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University."— Presentation transcript:

1 OOPSLA Lab.1 Chapter 6 Smalltalk Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University

2 OOPSLA Lab.2 Contents 6.1 Introduction 6.2 Smalltalk ODL 6.3 Smalltalk OML 6.4 Smalltalk OQL 6.5 Schema Access 6.7 Future Directions

3 OOPSLA Lab.3 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

4 OOPSLA Lab.4 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

5 OOPSLA Lab.5 6.1 Introduction(3) ODL Declarations ODL Compiler Meta Objects Class Objects Object Instance Language Binding regeneration generation type class

6 OOPSLA Lab.6 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

7 OOPSLA Lab.7 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

8 OOPSLA Lab.8 6.2 Smalltalk ODL Smalltalk/ODL Binding –based upon the OMG Smalltalk/IDL binding

9 OOPSLA Lab.9 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_yearmonthOfYear –month_of_year in IDL, becomes monthOfYear in 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

10 OOPSLA Lab.10 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:

11 OOPSLA Lab.11 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

12 OOPSLA Lab.12 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

13 OOPSLA Lab.13 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

14 OOPSLA Lab.14 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 ODL attribute Enum Rank {full, associate, assistant} rank; Smalltalk rank rank: aProfessorRank

15 OOPSLA Lab.15 6.2.2 Smalltalk ODL Binding Extensions(2) Relationship declaration –single-valued relationships ODL Relationship X Y inverse Z; IDL attribute X Y; void form_Y(in X target); void drop_Y(in X target); Smalltalk Y formY: dropY: Y: “private” ODL interface Course { …. Relationship Professor is_taught_by inverse Professor::teaches; …. } Smalltalk formIsTaughtBy:aProfessor dropIsTaughtBy:aProfessor isTaughtBy isTaughtBy: “private”

16 OOPSLA Lab.16 6.2.2 Smalltalk ODL Binding Extensions(3) –multivalued relationships Smalltalk formTeaches:aCourse dropTeaches:aCourse teaches addTeaches:aCourse “private” removeTeaches:aCourse “private” ODL Relationship set Y inverse Z; Smalltalk Y formY: dropY: addY: “private” removeY: “private” IDL readonly attribute set 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); ODL interface Course { …. Relationship set teaches inverse Course::is_taught_by; …. }

17 OOPSLA Lab.17 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

18 OOPSLA Lab.18 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

19 OOPSLA Lab.19 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

20 OOPSLA Lab.20 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

21 OOPSLA Lab.21 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

22 OOPSLA Lab.22 6.4 Smalltalk OQL Smalltalk OQL binding –loosely coupled binding Future binding –more tightly integrated with the Smalltalk language

23 OOPSLA Lab.23 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.

24 OOPSLA Lab.24 6.6 Future Directions Keys and extents A uniform set of Database administration operation


Download ppt "OOPSLA Lab.1 Chapter 6 Smalltalk Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University."

Similar presentations


Ads by Google