76
Introduction to Seaside Randal L. Schwartz, [email protected] Version 3.05 on 18 July 2010 This document is copyright 2008, 2009,2010 by Randal L. Schwartz, Stonehenge Consulting Services, Inc. This work is licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License http://creativecommons.org/licenses/by-nc-sa/3.0/ 1 Monday, July 19, 2010

Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, [email protected]

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Introduction to Seaside

Randal L. Schwartz, [email protected] 3.05 on 18 July 2010

This document is copyright 2008, 2009,2010 by Randal L. Schwartz, Stonehenge Consulting Services, Inc.This work is licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

http://creativecommons.org/licenses/by-nc-sa/3.0/

1Monday, July 19, 2010

Page 2: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Goals

• Components• Callbacks• HTML Generation (including forms)• Persistence (including ORM)• Deploying your application• AJAX Integration• Pier Content Management

2Monday, July 19, 2010

Page 3: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Getting Seaside

• Squeak - one click image or packages• VisualWorks - Store or WebVelocity• GNU Smalltalk - ?• VisualAge - ?• GemStone/S - GLASS

3Monday, July 19, 2010

Page 4: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

The Counter Example

• Launch one-click image• Ignore GUI for a moment

• Navigate to URL• Count!• All that excitement (yawn)

4Monday, July 19, 2010

Page 5: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

The Smalltalk GUI

• Workspace - run snippets of code• Browser - edit and view code• Debugger - “d” bugs• Inspector - look at complex values• Monticello - share and load code

5Monday, July 19, 2010

Page 6: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

The Workspace

• Evaluate code snippets• “do it”: just run the code• “print it”: run the code, show the result• “debug it”: run the code in the debugger• Operates on selection• If nothing selected, line cursor is on

6Monday, July 19, 2010

Page 7: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Smalltalk in a Hurry

• Just enough to understand Seaside

7Monday, July 19, 2010

Page 8: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Objects and classes

• Everything’s an object• An object belongs to a class• An object has methods• The class (also an object) has methods

• A class inherits from a single superclass• Class-side and instance-side separately

8Monday, July 19, 2010

Page 9: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Variables• Alphanumerics• CamelCased with initial lowercase:• rate, accelerationRate

• Value belongs to a class, variables don’t care• Assign to get a value:• rate := 30

• Special vars:• self, true, false, nil, super, thisContext

9Monday, July 19, 2010

Page 10: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Methods• Unary: single name, follows variable:• rate squared

• Binary: 1-2 punctuation chars:• rate * time

• Keyword: names and colons:• rate raisedTo: 2.5• rate between: 5 and: 10

• Simple precedence!

10Monday, July 19, 2010

Page 11: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Literal data

• Strings: ‘hello world’• Numeric data: 3 2.5 1.23e45 -2e-5• Symbols: #size #foo:bar: #+

11Monday, July 19, 2010

Page 12: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Classes

• Alphanumeric, initial uppercase• Class methods are often constructors:• rates := Set new.

• But could also have other uses:• superclassOfSet := Set superclass.• defaultCar := Car default.

12Monday, July 19, 2010

Page 13: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Method syntax• Signature (like message send without self):• squared• * aNumber• raisedTo: aNumber• between: lowNumber and: highNumber

• Temporaries: | aDog aCat |• Statements separated by periods• Last statement can have ^ (“answer this”)• Comments are in “double quotes”

13Monday, July 19, 2010

Page 14: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Control structures• Conditionals:• aBoolExpr ifTrue: [some. code. here].• aBoolExpr ifFalse: [some. other. code].• #ifTrue:ifFalse:, #ifFalse:ifTrue:

• Loops:• [code. code. aBoolExpr] whileTrue.• [code. aBoolExpr] whileTrue: [code].• #whileFalse, #whileFalse:

14Monday, July 19, 2010

Page 15: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

The Code Browser• Packages - groups of classes• Classes• Class/instance/comment toggle• Method categories (including “all”)• Method names• Lower pane views/edits selection• Sometimes preloaded with a template

• Lots of coding help available in menus

15Monday, July 19, 2010

Page 16: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

The Debugger• Debug notifier: proceed/cancel/full• Full debugger:• Stack• Code pane (current line highlighted)• Instance vars• Temps and arguments

• Everything is live, editable, resumable• Action buttons to step in, over, through

16Monday, July 19, 2010

Page 17: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Hello World• Create class for top-level component• Should inherit from WAComponent

• class #canBeRoot for GUI access• Or register during class #initialize

• Components implement:renderContentOn: html

• In our case: html text: ‘hello world’.

• Stupid smart quotes:PreferenceBrowser open

17Monday, July 19, 2010

Page 18: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Configure the app

• Visit configuration screen (/config)• Create a new URL path (below /)• Select our class as the root component• Visit the URL!

18Monday, July 19, 2010

Page 19: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

When the Web Breaks

• Add time display to output• Refactor it to use concatenation• Boom! (Needs #asString)• Walkback in browser• Select debug to use Smalltalk GUI• “Proceed”, and browser refreshed

19Monday, July 19, 2010

Page 20: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Halos

• Inspect components• Edit CSS (for prototyping)• View pretty-printed HTML source• Edit source code (proof of concept)

20Monday, July 19, 2010

Page 21: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Web Velocity

• Stay in web browser for:• Code browser• Debugger• Inspector• Source code management

• Everything!• Lots of scaffolding for database views

21Monday, July 19, 2010

Page 22: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Configuring brushes• Each step separate:

brush := html heading.brush level: 3.brush with: ‘my third level heading’.

• Combining first and second steps:brush := (html heading) level: 3.brush with: ‘...’.

• Any number of configurations• But #with: has to be last!

22Monday, July 19, 2010

Page 23: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Cascades• Cascade omits common object:

batallion selectTank target: enemy; fire.• Same as (without the variable):

aTank := batallion selectTank.aTank target: enemy.aTank fire.

• So our heading looks like:html heading level: 3; with: ‘my head’.

23Monday, July 19, 2010

Page 24: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Fancier Blocks• Like methods in square brackets• Argument list (if any)

:arg1 :arg2 :arg3 |• Temporaries (if any)

| temp1 temp2 |• Statements

arg1 dothis. arg2 dothat. arg3 + arg1.• ^ exits enclosing method, not block!

24Monday, July 19, 2010

Page 25: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Example

• add3ToDoubleOf := [:x | x * 2 + 3].• a := add3ToDoubleOf.• b := a value: 17.• c := a value: (17 / 2).

25Monday, July 19, 2010

Page 26: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Callbacks• html anchor with: ‘text’ - not useful• Exterior links:

html anchor url: ‘http://www.google.com’; with: ‘go go google!’.

• Action links!html anchor callback: [self increase]; with: ‘text’.

26Monday, July 19, 2010

Page 27: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Components

• Reusable chunks of HTML• Individual instance vars for state• Example: current counter value

• State can be rewound if a URL is reused• Or not, depending on coder’s choice

• Components can be nested• Need to be declared with #children

27Monday, July 19, 2010

Page 28: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Back to the Counter

• Simple code• Instance var holds the counter• Main view shows increase/decrease buttons• Actions linked via callbacks

28Monday, July 19, 2010

Page 29: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Collection classes

• OrderedCollection• Array (fixed size OrderedCollection)• Set• Bag (counted items of Set)• SortedCollection (order from chaos)• Dictionary (key/value mappings)• Interval (5 to: 100 by: 3)

29Monday, July 19, 2010

Page 30: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Collection protocols

• collect:• fractions := (1 to: 10) collect: [:n | 1 / n]

• do:• fractions do: [:each | html div: each]

• select:• overQuarter :=

fractions select: [:f | f > 0.25]

30Monday, July 19, 2010

Page 31: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Multicounter

• Just a bunch of counters

31Monday, July 19, 2010

Page 32: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

The Back Button• Callback URLs modify instance vars• What if we reinvoke the same URL?• Might want original action on old value• Or maybe on new current value

• To act on old value, use #states• Values are associated with URLs• Frozen and thawed as necessary

• Otherwise, acts on current value

32Monday, July 19, 2010

Page 33: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Styles

• Add class to any relevant brush:html div class: ‘entry’; with: ‘some text’.

• Style with CSS• External files can be edited by designer

• Simple styles for testing defined inline• String returned by #style on component

33Monday, July 19, 2010

Page 34: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Forms• Input fields painted with brushes• Callbacks executed on form submission• No need to name anything:

html text: ‘name:’.html textInput callback: [:v | self name: v].

• Default values can be provided• With right accessors, code is simple:

html textInput on: #name.

34Monday, July 19, 2010

Page 35: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

LCM two numbers

• Build code to do this

35Monday, July 19, 2010

Page 36: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Persistence Solutions

• Saving the image• Writing objects• Object prevayler (Sandstone, Prevayler)• Object database (GemStone/S, Magma)• Object/Relational Mapper (GLORP)

36Monday, July 19, 2010

Page 37: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Why Persist?

• Objects naturally live in the image• Image lives only when it’s alive• And only on one machine

• Data survive past a reboot• Data shared with other live images• Data shared with non-Smalltalk processes

37Monday, July 19, 2010

Page 38: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Reachability

• Objects rarely stand alone• Objects contain other interesting objects• ... which in turn contain others

• Might even be circular references• Persistence must deal with this

38Monday, July 19, 2010

Page 39: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Migration

• Classes will change through development• Add methods• Add instance variables• Change instance variables• Rename classes

• Instances in storage will need to migrate• Some persistence schemes deal with this

39Monday, July 19, 2010

Page 40: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Dirty Objects

• How are updates handled?• Load object, make changes, now what?• Some systems require notification• Others notice automatically• Not relevant for some• All saving is explicit

• Flushing only changes often more efficient

40Monday, July 19, 2010

Page 41: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Strategies

• Save the image• Serialize the objects• Database access• Object-Relational Mappers• Image persistency

41Monday, July 19, 2010

Page 42: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Saving the image• Periodically create a snapshot• Use a low-priority process with delay:

[[(Delay forSeconds: 300) wait. SmalltalkImage current saveSession. ] repeat.] forkAt: Processor userBackgroundPriority.

• Simple• Could save broken image• Timestamp your image names

42Monday, July 19, 2010

Page 43: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Objects

• Serialize your application objects• Two main mechanisms• File Based• Simple

• Server Based• Can often be clustered for scaling

43Monday, July 19, 2010

Page 44: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

File Based

• ReferenceStreams• ImageSegments• SIXX• OmniBase• MinneStore• SandstoneDB

44Monday, July 19, 2010

Page 45: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

ReferenceStreams• Subclass of DataStream (and Stream)• Knows how to serialize objects• Great example from Ramon Leon’s blog:

(ReferenceStream newFileNamed: ‘blog’) nextPut: self allPosts.

• Object returned from “self allPosts” saved• And all objects referenced therein

• Restore with:allPosts := (ReferenceStream oldFileNamed: ‘blog’) upToEnd.“do something with allPosts”

45Monday, July 19, 2010

Page 46: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

ImageSegments

• Store part of the live image on disk• Automatic activation (I think)

• Documentation is obscure• Avi Bryant is was using this for DabbleDB

46Monday, July 19, 2010

Page 47: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

SIXX• Load “SIXX” and an XML parser• Every object can turn into XML and back• Customize the XML for your objects• Example read/write:

(SixxWriteStream newFileNamed: ‘blog’) nextPut: self allPosts.allPosts := (SixxReadStream readOnlyFileNamed: ‘blog’) contents

• Sadly, they don’t inherit from streams

47Monday, July 19, 2010

Page 48: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

OmniBase• Portable object database• Claims:• Good concurrency support• Large collections

• Loaded into Squeak 3.8 but not later• Any object (and descendants) can persist• “Dirty” objects must be marked• Transactions (MVCC) are supported

48Monday, July 19, 2010

Page 49: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

MinneStore• Not compatible since Squeak 3.4• Tests failed on 3.8

• minnestore.sourceforge.net claims:• English-like query language• Multiple indexes• Transactions (commit/rollback)• Automatic disk reclamation

• “main site” is now a parked domain

49Monday, July 19, 2010

Page 50: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

SandstoneDB

• Ramon Leon’s favorite tool• Maybe because he wrote it

• Prevayler-style storage• ActiveRecord API• All active objects must live in memory• Atomic save

50Monday, July 19, 2010

Page 51: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Server Based

• Increased complexity• Possibility of scaling to multiple processes• Perhaps even multiple machines

• Main players in this arena• GOODS• Magma

51Monday, July 19, 2010

Page 52: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

GOODS• Language-neutral• Even Perl, via Pogo in the CPAN

• Requires configuring a server (C++)• Persistence by reachability• Add objects• Make changes• Updates get pushed at commit

• Commits may result in exceptions• Objects updated in conflicting ways

52Monday, July 19, 2010

Page 53: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Magma

• Modern local or clustered persistence• Simple transaction protocol• ACID fault tolerance

• Handles large indexed collections• Live class migration• Active development• Production deployments

53Monday, July 19, 2010

Page 54: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Using Magma• Get a session• Remote connection via TCP• Local connection to a file (single-user)

• Use the session to make changes• Create a commit block• Via session root, update referenced data• Commit or rollback

• New reachable objects automatically added

54Monday, July 19, 2010

Page 55: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Magma and Seaside

• Seaside glue via “Magma Seaside” package• Add WAMagmaConfiguration• Use resulting configuration screen• Configure location of server• Type of connection (single, shared, pool)

• Get at Magma with “self session magma”• Can point Magma root at your app data

55Monday, July 19, 2010

Page 56: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Database access

• SQLite• PostgreSQL• ODBC• Other unmentionable databases• “Friends don’t let friends use MySQL”• “If you can afford a full-time DBA, you can

afford Oracle”

56Monday, July 19, 2010

Page 57: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

SQLite• Wrapper around fully featured SQLite lib• Transactions, triggers, stored procs, more!

• Uses FFI to talk to native SQLite lib• External dependency!

• Won’t load into Squeak 3.8, 3.9 or 3.10• “Connect” to SQLite• Use connection to execute SQL• Results returned as structure

• Doesn’t handle placeholders

57Monday, July 19, 2010

Page 58: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

PostgreSQL• Conceptually similar to SQLite• Lot more power• Nearly complete PG protocol• Placeholders• Streaming results• Events

• Slightly outdated• Needed monkey patch to work with 8.2

58Monday, July 19, 2010

Page 59: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

ODBC

• Ditto• Create connection• Send SQL• Get back data

• Haven’t played with this

59Monday, July 19, 2010

Page 60: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

O-R Mappers

• GLORP• Cincom’s ActiveRecord• Roe• CouchDB• TokyoTyrant• SqueakDBX• Cloudfork-AWS

60Monday, July 19, 2010

Page 61: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

GLORP

• Maps objects to tables• Large• Mostly underdocumented• But it comes with a large test suite

• PostgreSQL seems to be primary target• But some of it must be outdated

• SqueakDBX layer also said to be compatible

61Monday, July 19, 2010

Page 62: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

GLORP Descriptor

• What a table contains• What objects will participate• How to map them• Very flexible system• Perhaps too flexible

• Tests provide a variety of examples

62Monday, July 19, 2010

Page 63: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

GLORP Mappings• Simple mapping is one-to-one• Describe a table• Create an object that looks like a row• Describe that object and its mapping

• Complex mappings• One row becomes variant object type• Multiple rows combine for one value

• Possible to map existing objects to RDB

63Monday, July 19, 2010

Page 64: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

GLORP Basics• Create a session object• Made from an accessor object• Made from a connection object• Made from a login object

• Within a unit of work, make changes• Use session to query existing data• Create new objects and add them• Sub-objects are automatically noted

• Commit or rollback the unit of work

64Monday, July 19, 2010

Page 65: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

ActiveRecord• Cincom is building as part of WebVelocity• Handles the “simple mapping” of GLORP• Probes the database• Can also create the database

• Presumes certain naming conventions• Not good for legacy databases

• Probably handle 80% of basic persistence• Open source “soon” we’re told

65Monday, July 19, 2010

Page 66: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Roe• Relational algebra evaluator• Underdocumented• But at least it has tests

• Appears to be abandoned• But at least it talks to PostgreSQL

• Write SQL as Smalltalk using DNU-trapper• Evaluated expression pushed to RDB

• Handles queries and updates• but not inserts (I’m guessing here)

66Monday, July 19, 2010

Page 67: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

CouchDB

• Map Smalltalk objects to CouchDB• Haven’t played with this

67Monday, July 19, 2010

Page 68: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

TokyoTyrant

• Interface to Toyko Cabinet• Haven’t played with this

68Monday, July 19, 2010

Page 69: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

SqueakDBX

• Interface to OpenDBX• DB-neutral abstraction for DDL and SQL• Summer-of-code 2008 project• Haven’t played with this• Although it sounds very promising

69Monday, July 19, 2010

Page 70: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

CloudforkAWS

• Data in the cloud• Interface for Amazon S3• Haven’t played with this

70Monday, July 19, 2010

Page 71: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Image Persistency

• Have the entire image just persist• Only one player in this space• That I’m aware of

• GemStone/S• See Dale’s blog

71Monday, July 19, 2010

Page 72: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

GLASS

• GemStone/S object engine• Linux, Apache, Smalltalk, Seaside• All wrapped up in a VMWare appliance• Free to use for small applications• Even commercial applications!

• Not open source though. :(• As hits increase, scale up for modest fee

72Monday, July 19, 2010

Page 73: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Ajax

• JavaScript library integration• jQuery (now)• Scriptaculous (legacy)

• No need to write JavaScript• Everything is coded from Smalltalk!

• [demo]

73Monday, July 19, 2010

Page 74: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Testing

• Component level testing• Using standard Smalltalk Unit Tests

• HTTP level testing• SeasideTesting package• Albatross (like Selenium)

74Monday, July 19, 2010

Page 75: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

Pier

• In one-click image:PRDistribution new register

75Monday, July 19, 2010

Page 76: Introduction to Seaside - O'Reilly Mediaassets.en.oreilly.com/1/event/45/Introduction to Web... · 2010-07-19 · Introduction to Seaside Randal L. Schwartz, merlyn@stonehenge.com

More info

• http://seaside.st/• http://MethodsAndMessages.vox.com/

76Monday, July 19, 2010