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

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

description

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

Transcript of OOPSLA Lab.1 Chapter 6 Smalltalk Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer...

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

OOPSLA Lab. 1

Chapter 6

Smalltalk Binding

Prof. Hyoung-Joo KimOOPSLA Lab.

Dept. of Computer EngineeringSeoul National University

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

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

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

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

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

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

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

OOPSLA Lab. 5

6.1 Introduction(3)

ODL Declarations ODL Compiler

Meta Objects Class Objects

Object Instance

LanguageBinding

regeneration generation

typeclass

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

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

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

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

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

OOPSLA Lab. 8

6.2 Smalltalk ODL

• Smalltalk/ODL Binding– based upon the OMG Smalltalk/IDL binding

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

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_yearmonth_of_year in IDL, becomes monthOfYearmonthOfYear 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

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

OOPSLA Lab. 10

6.2.1 OMG IDL Binding Overview(2)

• Operations– Smalltalk/IDL binding support the CORBAParameter protocol

IDLcurrent();days_in_year(in ushort year);from_hmstz(in ushort hour,ushort minute,in float second,in short tz_hour,in short tz_minute);

SmalltalkcurrentdaysInYear:fromHmstz:minute:second:tzHour:tzMinute:

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

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

IDL Smalltalkshort, unsigned short, long,unsigned long SmallInteger, LargeInteger, LargeNegativeInteger

float, double Float and Doublechar Characterboolean The Boolean values true and falseoctet SmallIntegerstring An appropriate String subclassany Object(any class that supports CORBAName)

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

OOPSLA Lab. 12

6.2.1 OMG IDL Binding Overview(4)

– compound types

– binding example

IDL SmalltalkArray An appropriate Array subclassSequence An appropriate OrderedCollection subclassStructure Implicit: A Dictionary

Structure Explicit: A class supporting accessor method to get and setof the structure fields

Union Implicit: Object(any class that support CORBAName)Union Explicit: A class that supports the CORBAUnion protocolEnum A class that supports the CORBAEnum protocol

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

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

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

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

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

ODLattribute Enum Rank {full, associate, assistant} rank;

Smalltalkrankrank: aProfessorRank

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

OOPSLA Lab. 15

6.2.2 Smalltalk ODL Binding Extensions(2)

• Relationship declaration– single-valued relationships

ODLRelationship X Y inverse Z;

IDLattribute X Y;void form_Y(in X target);void drop_Y(in X target);

SmalltalkYformY:dropY:Y: “private”

ODLinterface Course {…. Relationship Professor is_taught_by inverse Professor::teaches;….}

SmalltalkformIsTaughtBy:aProfessordropIsTaughtBy:aProfessorisTaughtByisTaughtBy: “private”

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

OOPSLA Lab. 16

6.2.2 Smalltalk ODL Binding Extensions(3)

– multivalued relationships

SmalltalkformTeaches:aCoursedropTeaches:aCourseteachesaddTeaches:aCourse “private”removeTeaches:aCourse “private”

ODLRelationship set<X> Y inverse Z;

SmalltalkYformY:dropY:addY: “private”removeY: “private”

IDLreadonly 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);

ODLinterface Course {…. Relationship set<Course> teaches inverse Course::is_taught_by;….}

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

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

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

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

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

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

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

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

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

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

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

OOPSLA Lab. 22

6.4 Smalltalk OQL

• Smalltalk OQL binding– loosely coupled binding

• Future binding– more tightly integrated with the Smalltalk language

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

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.

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

OOPSLA Lab. 24

6.6 Future Directions

• Keys and extents• A uniform set of Database administration operation