Changes for page Development-Audit Trails

Last modified by Theodore Petrosky on 2013/06/17 13:31

From version 31.1
edited by Pascal Robert
on 2007/09/03 15:18
Change comment: There is no comment for this version
To version 32.1
edited by Johan Henselmans
on 2009/11/20 12:20
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.probert
1 +XWiki.johanhenselmans
Content
... ... @@ -35,3 +35,68 @@
35 35   super.saveChanges()
36 36  
37 37  {{/code}}
38 +
39 +=== Houdah Frameworks: ===
40 +
41 +(scooped from the mailinglist)[[http://www.mail-archive.com/webobjects-dev@lists.apple.com/msg25686.html]]
42 +
43 +Take a look at Houdah Frameworks. I think the Audit Trail [[1>>||anchor="1"]] [[2>>||anchor="2"]] solution provided by this framework could be helpful.
44 +
45 +The Wonder Bug Tracker application also includes support for audit trail. Maybe you can learn something from there.
46 +
47 +[[||anchor="1"]] [[http://code.google.com/p/houdah-webobjects-frameworks/wiki/HoudahAuditTrail]]
48 +[[||anchor="2"]] [[http://code.google.com/p/houdah-webobjects-frameworks/wiki/AuditTrail]]
49 +
50 +=== Dov Rosenberg ===
51 +
52 +(scooped from the mailinglist)[[http://www.mail-archive.com/webobjects-dev@lists.apple.com/msg25683.html]]
53 +
54 +Most of the projects I worked on with this requirement used the built in audit tracking functions of the database. Most DBA's didn't leave the requirement to the developers to enforce. That way everything is tracked in a consistent fashion across applications.
55 +
56 +=== Ken Anderson ===
57 +
58 +(scooped from the mailinglist)[[http://www.mail-archive.com/webobjects-dev@lists.apple.com/msg25691.html]]
59 +
60 +I use a hybrid approach...
61 +
62 +I use the database to copy every row modified or deleted to an audit table. Every object has a trans//id field, which is a foreign key relationship to a transaction table. The primary key of that table increases like regular unique integer primary keys.//
63 +
64 +In EOF, I have sub-entities of all my EOs that have a prefix (like Aud...). These EOs are also subclasses of their main counterparts, then have an imported text file that represents the code I want all audit EOs to share (here's a good case for multiple inheritance!).
65 +
66 +The Aud.. EOs have an additional real column called resp//trans//id (the transaction RESPonsible for causing the row to move to the audit table), plus an additional 'fictitious' attribute called 'asof//trans//id'. This is the trans//id that you want the entire object structure to be 'as of'.//
67 +
68 +The primary key of the audit EOs is the oid AND asof//trans//id so you can have multiple historical audit EOs in the EC.
69 +
70 +The Aud EOs then have store procedures for fetching single objects (faulting), that respects the asof//trans//id. The stored procedure finds the right object for that asof//trans//id. For instance, if I have a fault:
71 +
72 +AudOrder oid = 72, asof//trans//id = 155
73 +
74 +the stored proc first checks to see if the trans//id of the primary Order table is less than 155. If it is, then this object hasn't changed since trans//id 155, and the primary row is returned (but an AudOrder object is still the object created). If not, we find the audit row who's trans//id is less than or equal to 155. If none exists, the fault fails.//
75 +
76 +In the AudOrder entity, you can decide whether to override existing relationships (like items) to be from audits, or for reference data, you could just keep the original relationship. For to-many audit relationships, you need another stored proc that will build the unique set, and the asof//trans//id value has to travel along (part of the relationship keys). So, the items relationship would be replaced with an items relationship to AudItem. The stored procedure would build a result set that includes all the items ASOF trans//id 155 (a union between the primary table and the audit table).//
77 +
78 +Primary entities have a method called 'auditObjects' that goes out and gets all the historical versions of an object.
79 +
80 +Whew!
81 +
82 +OK - NOW, you have the ability to say:
83 +
84 +I have this order EO. Give me the top 10 historical versions...
85 +
86 +You'll get an array of 10 AudOrder objects, which you can present to the user.
87 +
88 +You can display the date/time of the transaction record that the audit is related to, so the user can pick the version of history they want.
89 +
90 +Now that the user has selected an AudOrder object, when you fire the items to-many fault, it runs the stored proc that builds the union of unique objects that existed asof trans//id 155.//
91 +
92 +You can keep going and going, faulting more historical objects over time.
93 +
94 +Cool, huh?
95 +
96 +Ken
97 +
98 +One important bit that I left out....
99 +
100 +Depending on the database you're using, it might be difficult for the delete triggers to easily know the current transaction to update the responsible transaction ID (since on deletes, we're obviously not sending data). In Oracle, I use a trigger on the transaction table to update a temporary table that has a lifetime of just the current transaction. The insert trigger on the transaction table inserts a row into the temporary table with the OID of the new transaction, and the delete triggers read from that table to know the responsible trans ID.
101 +
102 +Ken