51
Practically using Glorp Karsten Kusche, Georg Heeg eK 28.08.2012 Donnerstag, 30. August 12

Practically Using Glorp

  • Upload
    esug

  • View
    535

  • Download
    0

Embed Size (px)

DESCRIPTION

ESUG 2012, Ghent

Citation preview

Page 1: Practically Using Glorp

Practically using GlorpKarsten Kusche, Georg Heeg eK

28.08.2012

Donnerstag, 30. August 12

Page 2: Practically Using Glorp

Georg Heeg eK25 Years

Donnerstag, 30. August 12

My Name is Karsten, i work for Georg Heegi want to talk about glorphighly flexible object relational mapping framework for Smalltalkthroughout the last year we had several successful projects using Glorp

Page 3: Practically Using Glorp

Glorp

TablesObjects

Valley of „You Don‘t Want To Be Here“

Donnerstag, 30. August 12

Objects and Tables are like water and oil, you need a third component for a good resultGlorp is very flexible yet easy to use

Page 4: Practically Using Glorp

GlorpObjects Database

Classes

Tables

Mapping

Descriptor-System

Donnerstag, 30. August 12

sits between objects and classesneeds to know classes, tables, their relationshipChange your Objects or your Database, adjust your descriptor system!!

Page 5: Practically Using Glorp

First Steps

Donnerstag, 30. August 12

Very simple Datastructure - logging messages with severity1 Class: LogItem, with timestamp, message, severitySmall Database, Small descriptor system

Page 6: Practically Using Glorp

Demo

Donnerstag, 30. August 12

Create the DescriptorSystem for a LogItem class and its table.

Page 7: Practically Using Glorp

Donnerstag, 30. August 12

the video

Page 8: Practically Using Glorp

session transact: [ aLogItem ].

tenMinutesAgo := Timestamp now - 10 minutes.session read: LogItem where: [:each | each timestamp > tenMinutesAgo].

Writing

Reading

Donnerstag, 30. August 12

Page 9: Practically Using Glorp

So much writing

Donnerstag, 30. August 12

much writing for the descriptorwhen the objects or the tables change, adjust the descriptor systemconnect to existing database is boring and time consuming, error prone

Page 10: Practically Using Glorp

Donnerstag, 30. August 12

the solution to manual labor is automation, next are some technologies that ease the pain

Page 11: Practically Using Glorp

Mapping Tool

Donnerstag, 30. August 12

part of ObjectStudiodefine the mapping by hand or let the Mapping Tool help you

Page 12: Practically Using Glorp

Active Record

Donnerstag, 30. August 12

Got popular in Ruby on RailsUsed in Web VelocityNaming Conventions

Page 13: Practically Using Glorp

Easy

• If you know the rules of Active Record

• If you have control over the database

Donnerstag, 30. August 12

Page 14: Practically Using Glorp

Limitations

• Ugly existing databases

• Steep learning curve

• Debugging problems

Donnerstag, 30. August 12

know the conventions, the rulesexisting databases with weird constraints and namesdebugging inference code is no fun

Page 15: Practically Using Glorp

Wishes• Automatic Conversion

• Ease of use

Donnerstag, 30. August 12

Page 16: Practically Using Glorp

Built my own Tool

• Active Record Compiler

• Creates Classes from Tables

• Creates Mappings from Constraints

Donnerstag, 30. August 12

Reads meta information from database,Supports One-One, One-Many, Many-To-Many Mappings

Page 17: Practically Using Glorp

Best Case Scenario

• Proper Database Description

• Proper Classes

• Working DescriptorSystem

Donnerstag, 30. August 12

Page 18: Practically Using Glorp

Best Case Scenario

• Proper Database Description

• Proper Classes

• Working DescriptorSystem

Worst

Donnerstag, 30. August 12

At Least, it creates a basis for your mapping and you can edit

Page 19: Practically Using Glorp

Donnerstag, 30. August 12

select database, enter class names, runChange database, run again!Update Domain Model Code, but not your Mapping

Page 20: Practically Using Glorp

Demo

Donnerstag, 30. August 12

create SQLite3 Store Database, create Mapping for it, inspect the databaseshow the created descriptor system

Page 21: Practically Using Glorp

Donnerstag, 30. August 12

the video

Page 22: Practically Using Glorp

Benefits

• Design in the DB

• Quick Recreation

• Smart Recreation

Donnerstag, 30. August 12

Database Tools provide Simplest way of describing databasesat least SQL Server Management Studio

Page 23: Practically Using Glorp

Drawbacks

• Backpointers

• Instance Variable Names

Donnerstag, 30. August 12

create properly named methods to access methods with weird names

Page 24: Practically Using Glorp

Donnerstag, 30. August 12

described how to edit your tables in order to get your objectsnow about the opposite approach

Page 25: Practically Using Glorp

Donnerstag, 30. August 12

described how to edit your tables in order to get your objectsnow about the opposite approach

Page 26: Practically Using Glorp

O r p h e u sDonnerstag, 30. August 12

Orpheus is software we acquired

Page 27: Practically Using Glorp

Donnerstag, 30. August 12

One ring to rule them allOne Database schema for all objects

Page 28: Practically Using Glorp

Virtual Mapping

varchar text datetime

ShortString LargeString Timestamp

title comment timestampObject

Tables

DB Types

Donnerstag, 30. August 12

Objects are stored in multiple tablesone table per database-datatypeChange your objects, and your mapping, but not your database

Page 29: Practically Using Glorp

ObjectsObjects

id class1 Person2 City

Personname: Karsten

Cityname: Munich

zip: 80331

city

ShortStringShortStringShortString

object instVar value

1 name Karsten2 name Munich

ObjectReferencesObjectReferencesObjectReferences

object instVar value

1 city 2

IntegerInteger

object instVar value

2 zip 80331

Donnerstag, 30. August 12

How to store Objects into that kind of database

Page 30: Practically Using Glorp

ObjectsObjects

id class1 Person2 City

Personname: Karsten

Cityname: Munich

zip: 80331

city

ShortStringShortStringShortString

object instVar value

1 name Karsten2 name Munich

ObjectReferencesObjectReferencesObjectReferences

object instVar value

1 city 2

IntegerInteger

object instVar value

2 zip 80331

Donnerstag, 30. August 12

How to store Objects into that kind of database

Page 31: Practically Using Glorp

ObjectsObjects

id class1 Person2 City

Personname: Karsten

Cityname: Munich

zip: 80331

city

ShortStringShortStringShortString

object instVar value

1 name Karsten2 name Munich

ObjectReferencesObjectReferencesObjectReferences

object instVar value

1 city 2

IntegerInteger

object instVar value

2 zip 80331

Donnerstag, 30. August 12

How to store Objects into that kind of database

Page 32: Practically Using Glorp

ObjectsObjects

id class1 Person2 City

Personname: Karsten

Cityname: Munich

zip: 80331

city

ShortStringShortStringShortString

object instVar value

1 name Karsten2 name Munich

ObjectReferencesObjectReferencesObjectReferences

object instVar value

1 city 2

IntegerInteger

object instVar value

2 zip 80331

Donnerstag, 30. August 12

How to store Objects into that kind of database

Page 33: Practically Using Glorp

ObjectsObjects

id class1 Person2 City

Personname: Karsten

Cityname: Munich

zip: 80331

city

ShortStringShortStringShortString

object instVar value

1 name Karsten2 name Munich

ObjectReferencesObjectReferencesObjectReferences

object instVar value

1 city 2

IntegerIntegerInteger

object instVar value

2 zip 80331

Donnerstag, 30. August 12

How to store Objects into that kind of database

Page 34: Practically Using Glorp

Tiny String

DateTime

Number Bytes Large

String

City

Person

P1 P2 P3C1 C2Objects

Virtual Tables

Actual Tables

Donnerstag, 30. August 12

Create virtual tables that only glorp knows, so that it can work properly. They are created by orpheus automatically

Page 35: Practically Using Glorp

OrpheusObjects Database

Classes

Tables

Mapping

Orpheus-Descriptor-

System

Donnerstag, 30. August 12

Only describe your classes

Page 36: Practically Using Glorp

Donnerstag, 30. August 12

Class Model describes classUsed for virtual tableused for mappingcreates constraints on possible object composition

Page 37: Practically Using Glorp

Lens Migration

Donnerstag, 30. August 12

Orpheus was written in LensPorting to Glorpinteresting problems

Page 38: Practically Using Glorp

Proxies

• Glorp keeps Proxies

• == doesn‘t work

Person

name: Karsten

city:

City

name: Köthen

Proxy

Donnerstag, 30. August 12

OnewayBecome is slow!

Page 39: Practically Using Glorp

Per Session Objects

• no Session Pool

Donnerstag, 30. August 12

Good for seaside, not so good for desktop client appscannot fetch objects in the background

Page 40: Practically Using Glorp

Method Inlining

Donnerstag, 30. August 12

problems on how glorp creates SQL statements

Page 41: Practically Using Glorp

Person

Karsten

City

Köthen

Country

Germany

city

country

session read: Person where:[:each | each city country name = 'Germany']

session read: Person where:[:each | each countryName = 'Germany']

countryName ^self city country name

Donnerstag, 30. August 12

Glorp knows each is a Person and checks for the attributes ,city‘ -> ,country‘ -> ,name‘.the attribute ,countryName‘ does not exist and would create errors

Page 42: Practically Using Glorp

Query OptimizationBefore: [:a | a = 2 & (false | true) | NOT(true)]

After: [:a | a = 2]

Donnerstag, 30. August 12

Not supported by MS SQL, supported by Postgres -> optimize it away

Page 43: Practically Using Glorp

Glorp Bashing

Donnerstag, 30. August 12

glorp has some strange behavior for somethings

Page 44: Practically Using Glorp

Column Width

50 Characters VS varchar[20]

Donnerstag, 30. August 12

Glorp trims and doesn‘t notify

Page 45: Practically Using Glorp

Multithreading

One Process Per Session VS

Two Sessions Share No Objects

Donnerstag, 30. August 12

One session on multiple processes crashes badly and you need to login againsharing objects between sessions also not possible

Page 46: Practically Using Glorp

Vicious Cache`´

Donnerstag, 30. August 12

read object, modify in DB, read again... no changetell Query or Session to refresh

Page 47: Practically Using Glorp

Register Object

Change Object

Fetch Object

Start Transaction

Commit Transaction

x

Modifying Objects

Donnerstag, 30. August 12

Page 48: Practically Using Glorp

Dictionaries

object dictionary at: #a put: 123.session transact:[

session register: object.object dictionary at: #a put: 456.

]

Donnerstag, 30. August 12

Glorp will not persist that.Copy of Dictionary -> same associations

Page 49: Practically Using Glorp

<pragma: class>

#classModelForLogItem:

#descriptorForLogItem:

#tableForLOGITEM:

Donnerstag, 30. August 12

it‘s impossible to find these methods using „references of class LogItem“

Page 50: Practically Using Glorp

Conclusion

• Glorp is simple, flexible, fast

• platform independent

• supports complex mappings

• tools could be better

• we built our own tools

Donnerstag, 30. August 12

Page 51: Practically Using Glorp

ThanksMonument Valley - http://www.flickr.com/photos/aigle_dore/5824866641/Little Feet - http://www.flickr.com/photos/goulao/173213992Single pencil - http://www.flickr.com/photos/ardabalkan/353004619Easy Button - http://www.flickr.com/photos/bravo213/376781221ObjectStudio © Cincom Systems IncWebVelocity © Cincom Systems IncThumb up - http://www.flickr.com/photos/krissen/6340984211Birthday cake - http://www.flickr.com/photos/laughingsquid/260374487/Tools - http://www.flickr.com/photos/zzpza/3269784239Bus - http://www.flickr.com/photos/eschipul/250836634Prometheus © 20th Century FoxLens - http://www.flickr.com/photos/96dpi/682994554/Bags - http://www.flickr.com/photos/stevendepolo/3407679411/Skates - http://www.flickr.com/photos/videimage/3981923034/Balloon http://www.flickr.com/photos/topsynette/4337734907Braveheart © ParamountStreet Fighter © CAPCOMPath - http://www.flickr.com/photos/atoach/3551829101/

Donnerstag, 30. August 12