Wiki source code of WebObjects and Squeryl

Version 71.1 by Ravi Mendis on 2011/03/31 23:27

Hide last authors
Ravi Mendis 66.1 1 = Squeryl ~= //SQL-like// DSL in Scala =
Ravi Mendis 54.1 2
3 Advantages of [[Squeryl>>http://squeryl.org/]] over EOF:
4
5 * Concurrent
6 ** Spawns multiple database connections
7 ** Issues database transactions concurrently
8 * Scala Actor compatible
9 ** Immutable object model/graph
Ravi Mendis 60.1 10 ** Explicit transaction control
Ravi Mendis 62.1 11 * Type Safety
Ravi Mendis 54.1 12 ** Better suited for database/business "logic".
13 E.g: Exploits the compiler and IDE to catch exceptions at compile time rather than at run-time.
Ravi Mendis 68.1 14 * Uses Scala Collections
Ravi Mendis 54.1 15
16 = Migrating EOF -> Squeryl =
17
18 In contrast to EOF Squeryl maintains its ORM information programmatically - in the classes itself and collectively in a [[schema>>http://squeryl.org/schema-definition.html]]. In keeping with the strongly-typed philosophy of Scala, Squeryl has no dynamic component like EOF (i.e an EO model file).
19
20 EOF has the ability to generate classes in Java (and in Objective-C prior to WebObjects 4.5) because enforcing type has become customary in enterprise environments. We may exploit this feature of EOF to generate a Squeryl schema from an EO model.
21
22 === Preparing your EO model ===
23
24 * Make sure **all** EO entities have a class name (including abstract many-To-many "join" tables). FYI: There can be no support for entities classified as ##EOGenericRecord##.
25 * Mark the abstract many-To-Many join entities as ##Abstract##.
26 * (Temporary) Ensure all the model entities are in the same package. i.e the package is exclusive to the model.
27
28 === Generating the Squeryl Schema ===
29
30 1. Create a .eogen file for your EO model as normal. Only set the ##File Names## extension to "scala".
31 1. Use the Squeryl EO Templates:
32
33 *
34 ** Entity.eotemplate [[template>>WOL:Squeryl _Entity.eotemplate]]
35 ** Entity.eotemplate [[template>>WOL:Squeryl Entity.eotemplate]]
36
37 {{note title="Note"}}
38
39 Any custom business "logic" will have to be manually re-written in Scala
40
41 {{/note}}
42
43 == Differences Between a Squeryl Schema and EO Model/Classes ==
44
45 * Optional attributes (i.e those that ##allowsNull##) are typed as ##OptionT##
46 * To one relationships that are not mandatory (i.e optional relationships) are also typed as ##OptionT##
47 * To many relationships are represented as a Squeryl iterable (collection class) as opposed to a ##NSArray##.
Ravi Mendis 64.1 48
49 === Use of Scala Collections ===
50
51 ===== 1. Filtering =====
52
53 Instead of using EOQualifiers to filter EOs dynamically, you can apply the type safe filter in Scala:
54
55 {{code}}
56
Ravi Mendis 68.1 57 def activeFiles = files.filter(_.active == true)
Ravi Mendis 64.1 58
59 {{/code}}
Ravi Mendis 68.1 60
Ravi Mendis 70.1 61 h5 2. Iteration
Ravi Mendis 68.1 62
Ravi Mendis 70.1 63 Functional language iteration that's become increasingly popular
Ravi Mendis 68.1 64
65 {{code}}
66
67 activeFiles.foreach(f => {
68 ...
69 })
70
71 {{/code}}