<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>mhinze.com &#187; auditing</title>
	<atom:link href="http://mhinze.com/tag/auditing/feed/" rel="self" type="application/rss+xml" />
	<link>http://mhinze.com</link>
	<description>Matt Hinze, learning in public</description>
	<lastBuildDate>Tue, 14 Feb 2012 16:31:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mhinze.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>mhinze.com &#187; auditing</title>
		<link>http://mhinze.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mhinze.com/osd.xml" title="mhinze.com" />
	<atom:link rel='hub' href='http://mhinze.com/?pushpress=hub'/>
		<item>
		<title>Audit options with NHibernate</title>
		<link>http://mhinze.com/2008/07/11/audit-options-with-nhibernate/</link>
		<comments>http://mhinze.com/2008/07/11/audit-options-with-nhibernate/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 13:55:27 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[auditing]]></category>
		<category><![CDATA[ddd]]></category>
		<category><![CDATA[nhibernate]]></category>

		<guid isPermaLink="false">http://mhinze.com/?p=43</guid>
		<description><![CDATA[In this post I am talking about auditing for the business, not the technical infrastructure.&#160; As an example story, users will want to see certain fields highlighted on a grid if that field has changed in the last week, and &#8230; <a href="http://mhinze.com/2008/07/11/audit-options-with-nhibernate/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhinze.com&amp;blog=678824&amp;post=43&amp;subd=mhinze&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this post I am talking about auditing for the business, not the technical infrastructure.&nbsp; As an example story, users will want to see certain fields highlighted on a grid if that field has changed in the last week, and the info about the change (who, when, what) should be a tooltip for the cell.</p>
<p><strong>Database trigger</strong></p>
<ul>
<li>See Jon Galloway&#8217;s post on <a href="http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx">Auditing with SQL Server</a></li>
<li>To <a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:59412348055">generate an audit trigger in oracle</a> you can do something similar.</li>
</ul>
<p><strong>NH Interceptor</strong> (per NH in action and the <a href="http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#manipulatingdata-interceptors">NH docs</a>)</p>
<p><strong>NH Listener</strong> (per the <a href="http://www.hibernate.org/318.html">Hibernate docs</a>)</p>
<p><strong>Domain model</strong></p>
<p>Because auditing is a simple application of interceptors there is a lot of guidance online about that approach, and using an interceptor was my first attempt at auditing. </p>
<p>But since the concept of an audit entry is important to the application (and the users!), it makes sense to promote this concept to a domain object.&nbsp; Reporting is simple and the behavior is easier to manage.&nbsp; Create a class called AuditEntry (with supporting mapping file) and hang collections of AuditEntry from the entity. Manage this collection in regular behavior:</p>
<pre class="code"><span style="color:blue;">public virtual void </span>ChangeStatus(<span style="color:#2b91af;">Employee </span>employee, <span style="color:#2b91af;">DateTime </span>time, <span style="color:#2b91af;">OrderStatus </span>status)
{
    <span style="color:blue;">if</span>(<span style="color:blue;">this</span>.Status != status)
    {
        <span style="color:#2b91af;">AuditEntry </span>entry = <span style="color:blue;">new </span><span style="color:#2b91af;">AuditEntry</span>(employee, time, <span style="color:blue;">this</span>.Status, status);
        _auditEntries.Add(entry);
    }
    Status = status;
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>After having gone down the database trigger path and the interceptor path and encountering friction I now recommend the domain model approach.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/mhinze.wordpress.com/43/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/mhinze.wordpress.com/43/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mhinze.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mhinze.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mhinze.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mhinze.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mhinze.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mhinze.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mhinze.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mhinze.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mhinze.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mhinze.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mhinze.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mhinze.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mhinze.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mhinze.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhinze.com&amp;blog=678824&amp;post=43&amp;subd=mhinze&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mhinze.com/2008/07/11/audit-options-with-nhibernate/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0d6043840ea98542a9c9331c7e7940b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mhinze</media:title>
		</media:content>
	</item>
	</channel>
</rss>
