<?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/"
	>

<channel>
	<title>KeaWare Blog</title>
	<atom:link href="http://blog.keaware.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.keaware.com</link>
	<description>by Justin Milling</description>
	<lastBuildDate>Thu, 22 Mar 2012 13:45:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>DuckDuckGo beats Google</title>
		<link>http://blog.keaware.com/?p=44</link>
		<comments>http://blog.keaware.com/?p=44#comments</comments>
		<pubDate>Fri, 16 Mar 2012 14:57:55 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.keaware.com/?p=44</guid>
		<description><![CDATA[I was researching a technical problem recently, and the almighty Google wasn&#8217;t giving me helpful search results. On a whim, I decided to give DuckDuckGo a shot. Lo and behold, I had several useful results come back. Given the privacy concerns involved with using Google, I&#8217;m seriously considering making a permanent switch. It does feel [...]]]></description>
			<content:encoded><![CDATA[<p>I was researching a technical problem recently, and the almighty Google wasn&#8217;t giving me helpful search results. On a whim, I decided to give <a href="http://www.duckduckgo.com">DuckDuckGo</a> a shot. Lo and behold, I had several useful results come back. Given the privacy concerns involved with using Google, I&#8217;m seriously considering making a permanent switch. It does feel strange to use something other than Google, which has been the gold standard of &#8220;search&#8221; for many years. But hey, things change.</p>
<p>UPDATE: Just came across <a href="http://blogs.msdn.com/b/jw_on_tech/archive/2012/03/13/why-i-left-google.aspx">this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.keaware.com/?feed=rss2&#038;p=44</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bridging NHibernate with Oracle Triggers and Sequences</title>
		<link>http://blog.keaware.com/?p=35</link>
		<comments>http://blog.keaware.com/?p=35#comments</comments>
		<pubDate>Wed, 16 Feb 2011 16:02:46 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://blog.keaware.com/?p=35</guid>
		<description><![CDATA[The Problem You&#8217;ve set up a .Net project using Oracle with NHibernate.  Your Id fields are auto-incremented in Oracle using triggers and sequence numbers. You&#8217;ve created your objects and mapping files, and things seem to mostly work, but you notice some strange things. For one, there are lots of holes in your Id numbers. For [...]]]></description>
			<content:encoded><![CDATA[<h2>The Problem</h2>
<p>You&#8217;ve set up a .Net project using Oracle with NHibernate.  Your Id fields are auto-incremented in Oracle using triggers and sequence numbers. You&#8217;ve created your objects and mapping files, and things seem to mostly work, but you notice some strange things. For one, there are lots of holes in your Id numbers. For another, when you save a new object that has a child collection of objects, you notice that the foreign key Id number in the parent and children are off by one. You could resort to a work-around of saving the child objects independently, but that is a major inconvenience.</p>
<h2>Underneath the Hood</h2>
<p>What is probably happening is that NHibernate is accessing your Oracle sequence number more than once, causing it to increment each time you access it. If you look at your mapping files, you probably have your Id fields set up like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Id&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;APS_JOB_SEQ&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Int32&quot;</span> <span style="color: #000066;">unsaved-value</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;native&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sequence&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>SQ_APS_JOB_SEQ<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/generator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>A Simple Solution</h2>
<p>By making a simple change in an attribute of your &lt;generator&gt; tag, you can probably make your Id problems go away:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Id&quot;</span> <span style="color: #000066;">column</span>=<span style="color: #ff0000;">&quot;APS_JOB_SEQ&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Int32&quot;</span> <span style="color: #000066;">unsaved-value</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;trigger-identity&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sequence&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>SQ_APS_JOB_SEQ<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/generator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>By setting the generator class attribute to &quot;trigger-identity&quot;, you prevent NHibernate from making separate calls to the sequence.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.keaware.com/?feed=rss2&#038;p=35</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Coalescing Undo When Dragging in a Custom View</title>
		<link>http://blog.keaware.com/?p=26</link>
		<comments>http://blog.keaware.com/?p=26#comments</comments>
		<pubDate>Sun, 06 Feb 2011 04:49:56 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[chunked]]></category>
		<category><![CDATA[coalescing]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[dragging]]></category>
		<category><![CDATA[undo]]></category>

		<guid isPermaLink="false">http://blog.keaware.com/?p=26</guid>
		<description><![CDATA[Coalescing undo, otherwise known as chunked undo, is handy for undoing a whole group of changes when the user selects Edit-&#62;Undo (or Command-Z). I recently encountered a scenario for which coalescing undo was required. My application has a custom view containing text boxes that the user can edit and drag around the view. When I [...]]]></description>
			<content:encoded><![CDATA[<p>Coalescing undo, otherwise known as chunked undo, is handy for undoing a whole group of changes when the user selects Edit-&gt;Undo (or Command-Z). I recently encountered a scenario for which coalescing undo was required.</p>
<p>My application has a custom view containing text boxes that the user can edit and drag around the view. When I implemented Undo for these action, I noticed that, after dragging a text box, the Undo action would only move the text box back a couple of pixels, and then a couple more pixels when I selected Undo again, and so on, and so on. In other words, each mouseDragged event caused the text box bounds to be updated, which in turn caused another NSInvocation to be pushed onto the Undo stack.</p>
<p>The behavior that I wanted was for the text box to go all the way back to its original position when the user selected Undo. My first attempt involved turning on the coalescing undo on the mouseDown event and turning it off on the mouseUp event. This worked, but it had the undesired side effect of placing a new item on the Undo stack even when no dragging took place, i.e., the user could simply click on a text box, and there would be an Undo item for that click. I wanted the grouping to only have an effect on dragging.</p>
<p>Here is how I got it to work without an awful lot of code. If you have a better way, please leave a comment!</p>
<p>For the mouseDown event, you invoke the undoManager and specify that the grouping, or coalescing, should begin:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mouseDown<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSEvent</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event <span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSUndoManager</span> <span style="color: #002200;">*</span>undoManager <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>document undoManager<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>undoManager beginUndoGrouping<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// your mouseDown code here...</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>For the mouseDragged event, you simply set a class variable indicating that a drag is taking place:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mouseDragged<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSEvent</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>theEvent
<span style="color: #002200;">&#123;</span>
	isDragging <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// your dragging code here...</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Finally, the mouseUp event does most of the work, which is explained below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mouseUp<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSEvent</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>theEvent
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSUndoManager</span> <span style="color: #002200;">*</span>undoManager <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>document undoManager<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>undoManager endUndoGrouping<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>isDragging<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #a61390;">NSRect</span> newBounds <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>selectedTextbox bounds<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>undoManager disableUndoRegistration<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>undoManager undoNestedGroup<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>undoManager enableUndoRegistration<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>selectedTextbox setBounds<span style="color: #002200;">:</span>newBounds<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	isDragging <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>When the mouseUp event fires, you know that the dragging has ended, so you end the grouping by calling [undoManager endUndoGrouping].</p>
<p>If you are just finishing a drag (isDragging set to YES), then record the new bounds of the text box (selectedTextbox, in this example) into an NSRect (newBounds, in this example).</p>
<p>Temporarily disable the Undo mechanism by calling [undoManager disableUndoRegistration]. Pop the group off of the Undo stack by calling [undoManager endNestedGrouping]. Turn the Undo mechanism back on by calling [undoManager enableUndoRegistration].</p>
<p>At this point, things are reset like they were before the drag began, so you need to set the bounds of the text box to the new bounds you saved a little earlier by calling [selectedTextbox setBounds:newBounds].</p>
<p>Not the perfect solution, I&#8217;m sure, but it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.keaware.com/?feed=rss2&#038;p=26</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Source Code Syntax Highlighting in WordPress</title>
		<link>http://blog.keaware.com/?p=8</link>
		<comments>http://blog.keaware.com/?p=8#comments</comments>
		<pubDate>Fri, 28 Jan 2011 03:37:11 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.keaware.com/?p=8</guid>
		<description><![CDATA[I&#8217;ve just installed WordPress to get this blog underway, and since I will be dealing with software development topics, I needed a code syntax highlighter. I found a good one named WP-Syntax. Here&#8217;s a code snippet in Objective-C: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just installed WordPress to get this blog underway, and since I will be dealing with software development topics, I needed a code syntax highlighter. I found a good one named <a href="http://wordpress.org/extend/plugins/wp-syntax/" target="_blank">WP-Syntax</a>.</p>
<p>Here&#8217;s a code snippet in Objective-C:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>createDisplayImage
<span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>displayImage <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>displayImage release<span style="color: #002200;">&#93;</span>;
		displayImage <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
	<span style="color: #002200;">&#125;</span>
	displayImage <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> alloc<span style="color: #002200;">&#93;</span> initWithSize<span style="color: #002200;">:</span>NSMakeSize<span style="color: #002200;">&#40;</span>IMAGE_DIMENSION, IMAGE_DIMENSION<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>displayImage lockFocus<span style="color: #002200;">&#93;</span>;
	<span style="color: #400080;">NSImage</span> <span style="color: #002200;">*</span>img <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>document image<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>img <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>img drawInRect<span style="color: #002200;">:</span>NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, IMAGE_DIMENSION, IMAGE_DIMENSION<span style="color: #002200;">&#41;</span>
			fromRect<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self scaledRectOfCroppedSource<span style="color: #002200;">&#93;</span>
			  operation<span style="color: #002200;">:</span>NSCompositeCopy fraction<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSColor</span> whiteColor<span style="color: #002200;">&#93;</span> set<span style="color: #002200;">&#93;</span>;
		NSRectFill<span style="color: #002200;">&#40;</span>NSMakeRect<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">0.0</span>, IMAGE_DIMENSION, IMAGE_DIMENSION<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>displayImage unlockFocus<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>To get this to work, all you have to do is switch to HTML mode when writing your post, then use the PRE tag like this:</p>
<blockquote><p>&lt;pre lang=&#8221;objc&#8221; line=&#8221;1&#8243;&gt;<em>your source code&#8230;</em>&lt;/pre&gt;</p></blockquote>
<p>Not too difficult, eh?</p>
<p>One thing I noticed, however, is that when I switched to Visual mode and then back to HTML, the &#8220;line&#8221; attribute got stripped from the PRE tag. Something to keep in mind.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.keaware.com/?feed=rss2&#038;p=8</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

