@@ -9,8 +9,9 @@ As an example, consider an email application. Users of the applications will wan
99A Project:M36 notification is comprised of three user-selected parts:
1010
11111. an arbitrary notification name: used to uniquely identify the notification in the server and client
12−2. a trigger relational expression: when the outcome of this relational expression changes between two transactions, the notification is fired
13−3. a report relational expression: when the notification fires, the expression is evaluated and passed along
12+1. a trigger relational expression: when the outcome of this relational expression changes between two transactions, the notification is fired
13+1. a report relational expression for the pre-change context: when the notification fires, the expression is evaluated in the old context and passed along
14+1. a report relational expression for the post-change context: when the notification fires, the expression is evaluated in the new context and passed along
1415
1516By separating the "trigger" and "report" expressions, database users control what kind of reporting they receive when the outcome of a relational expression changes.
1617
@@ -21,7 +22,7 @@ Currently, notifications are sent to all connected clients and not only to the c
2122Notifications can be created in the ```tutd``` TutorialD interpreter with the following syntax:
2223
2324```
24−notify <notification name> <trigger relational expression> <report relational expression>
25+notify <notification name> <trigger relational expression> <report relational expression (pre-change)> <report relational expression (post-change)>
2526```
2627
2728## Deleting a Notification
@@ -39,21 +40,23 @@ Consider the following ```person``` relation variable where "name" is a key:
3940```
4041TutorialD (master/main): person:=relation{tuple{name "Steve",address "Main St."},tuple{name "John", address "Elm St."}}
4142TutorialD (master/main): :showexpr person
42−┌────────┬─────┐
43−│address │name │
44−├────────┼─────┤
45−│Elm St. │John │
46−│Main St.│Steve│
47−└────────┴─────┘
43+┌─────────────┬──────────┐
44+│address::Text│name::Text│
45+├─────────────┼──────────┤
46+│"Main St." │"Steve" │
47+│"Elm St." │"John" │
48+└─────────────┴──────────┘
4849```
4950
5051If a remote application is currently the address in the tuple for "Steve", then it would install a notification for that tuple's key:
5152
5253```
53−TutorialD (master/main): notify steve_change person where name="Steve" (person where name="Steve"){address}
54+TutorialD (master/main): notify steve_change person where name="Steve" true (person where name="Steve"){address}
5455TutorialD (master/main): :commit
5556```
5657
58+In this case, we pass `true` as the old context report expression because we plan to ignore the result.
59+
5760Then, when any client including the initiating client updates the "Steve" tuple, an asynchronous notification is fired:
5861
5962```
@@ -62,16 +65,17 @@ TutorialD (master/main): :commit
6265TutorialD (master/main): Notification received "steve_change": ...
6366```
6467
65−The asynchronously-received notification contains the result from the evaluated report relational expression. The expression, in this case, is the result of the report expression evaluated against the parent transactoin
68+The asynchronously-received notification contains the result from the evaluated report relational expression. The expression, in this case, is the result of the report expression evaluated against the new transaction:
6669
6770```
6871TutorialD (master/main): Notification received "steve_change":
6972Project (AttributeNames (fromList ["address"])) (Restrict (AttributeEqualityPredicate "name" (NakedAtomExpr Atom "Steve")) (RelationVariable "person"))
70−┌────────┐
71−│address │
72−├────────┤
73−│Main St.│
74−└────────┘
73+┌─────────────┐
74+│address::Text│
75+├─────────────┤
76+│"Grove St." │
77+└─────────────┘
78+
7579```
7680
7781## Notifications with ProjectM36.Client
@@ -80,10 +84,10 @@ First, implement a ```NotificationCallback``` function to perform an IO action w
8084
8185Each ProjectM36 Connection can only have one callback and it cannot be changed after Connection creation.
8286
83−Then, create a DatabaseExpr using the AddNotification constructor:
87+Then, create a DatabaseContextExpr using the AddNotification constructor:
8488
8589```
86−AddNotification <notification name::Text> <change expression::RelationalExpr> <report expression::RelationalExpr>
90+AddNotification <notification name::Text> <change expression::RelationalExpr> <report old context expression::RelationalExpr> <report new context expression::RelationalExpr>
8791```
8892
8993and execute it using ```executeDatabaseContextExpr```. In order for a notification to take effect, it must be committed as well.