2 System
: Property Management and Finance System
7 Description
: Generic Include to detect record replication collisions
9 The procedure for collsion detection is as follows
:
12 Try to find the given table record with the given key id
13 If it exists and the index is unique then there is a collision
15 Try to find the given table with the given key id
17 do a buffer compare between the two records
18 if the records are different then there is a collision
20 integrity error
- something strange has gone wrong
21 in replication between the two sites
23 PreProcessor Parameters
:
25 1 - Name of the table being replicated
26 2 - Indexed find clause for the given table
27 3 - yes
/no
: Whether the index was unique
29 Parameters
: record-data
- RAW description of the after image of the record
30 rep-event
- the type of replication event
32 Returns
: Collision Occurred
37 &SCOPED-DEFINE TableName {1}
38 &SCOPED-DEFINE WhereClause {2}
39 &SCOPED-DEFINE UniqueIndex {3}
41 DEF INPUT PARAMETER record-bi
AS RAW NO-UNDO.
42 DEF INPUT PARAMETER record-ai
AS RAW NO-UNDO.
43 DEF INPUT PARAMETER rep-event
AS CHAR NO-UNDO.
45 DEF TEMP-TABLE Repl
{&TableName} LIKE {&TableName}.
46 DEF VAR collision-error
AS LOGI
NO-UNDO INITIAL No.
47 DEF VAR transfer-error
AS LOGI
NO-UNDO INITIAL No.
48 DEF VAR create-error
AS LOGI
NO-UNDO INITIAL No.
49 DEF VAR not-found-error
AS LOGI
NO-UNDO INITIAL No.
50 DEF VAR records-identical
AS LOGI
NO-UNDO.
51 DEF VAR record-id-found
AS RECID NO-UNDO.
52 DEF VAR matching-found
AS INT NO-UNDO INITIAL 0.
54 DISABLE TRIGGERS FOR LOAD OF {&TableName}.
56 /* Set up the record to be replicated
*/
57 CREATE Repl
{&TableName} NO-ERROR.
58 create-error
= ERROR-STATUS:ERROR .
60 ERROR-STATUS:ERROR = No.
62 IF rep-event
= "C" THEN
63 RAW-TRANSFER record-ai
TO Repl
{&TableName} NO-ERROR.
65 RAW-TRANSFER record-bi
TO Repl
{&TableName} NO-ERROR.
67 transfer-error
= ERROR-STATUS:ERROR .
69 IF rep-event
= "C" THEN DO: /* Create
*/
70 FIND {&TableName} WHERE {&WhereClause} EXCLUSIVE-LOCK NO-ERROR.
71 collision-error
= {&UniqueIndex} AND AVAILABLE( {&TableName} ).
72 IF NOT collision-error
THEN DO:
73 CREATE {&TableName} NO-ERROR.
74 create-error
= create-error
OR ERROR-STATUS:ERROR .
75 RAW-TRANSFER record-ai
TO {&TableName} NO-ERROR.
76 transfer-error
= transfer-error
OR ERROR-STATUS:ERROR.
79 ELSE IF {&UniqueIndex} THEN DO:
80 FIND {&TableName} WHERE {&WhereClause} EXCLUSIVE-LOCK NO-ERROR.
81 IF AVAILABLE( {&TableName} ) THEN DO:
82 BUFFER-COMPARE {&TableName} TO Repl{&TableName}
83 SAVE RESULT IN records-identical.
84 collision-error
= NOT records-identical.
86 ELSE /* only return not-found error when not deleting
*/
87 not-found-error
= (rep-event
<> "D") /* Yes
*/.
90 not-found-error
= Yes.
92 FOR EACH {&TableName} NO-LOCK WHERE {&WhereClause}:
93 BUFFER-COMPARE {&TableName} TO Repl{&TableName}
94 SAVE RESULT IN records-identical.
95 IF records-identical
THEN ASSIGN
96 record-id-found
= RECID( {&TableName} )
97 matching-found
= matching-found
+ 1.
99 IF matching-found
= 1 THEN DO:
100 FIND {&TableName} WHERE RECID( {&TableName} ) = record-id-found EXCLUSIVE-LOCK NO-ERROR.
101 not-found-error
= No.
106 /* Apply the changes only if a collision
*/
107 IF rep-event
= "M" THEN
108 RAW-TRANSFER record-ai
TO {&TableName} NO-ERROR.
109 ELSE IF rep-event
= "D" THEN
110 DELETE {&TableName} NO-ERROR.
112 RETURN TRIM( (IF collision-error
THEN "COLLISION," ELSE "")
113 + (IF transfer-error
THEN "TRANSFER," ELSE "")
114 + (IF create-error
THEN "CREATE," ELSE "")
115 + (IF not-found-error
THEN "NOT FOUND," ELSE "")