Changes for page WebObjects and Squeryl

Last modified by Ravi Mendis on 2011/04/01 11:14

From version 149.1
edited by Ravi Mendis
on 2010/11/10 03:18
Change comment: There is no comment for this version
To version 166.1
edited by Ravi Mendis
on 2023/11/13 11:55
Change comment: Renamed back-links.

Summary

Details

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