    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: The Last Word in Patterns</title>
        <link>https://members.accu.org/index.php/journals/2446</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">Overload Journal #142 - December 2017 + Programming Topics</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c380/">o142</a>
                    (7)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c65/">Programming</a>
                    (877)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c380-65/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c380+65/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;The Last Word in Patterns</h1>
<p><strong>Author:</strong>&nbsp;Bob Schmidt</p>
<p>
<strong>Date:</strong> 04 December 2017 22:36:34 +00:00 or Mon, 04 December 2017 22:36:34 +00:00</p>
<p><strong>Summary:</strong>&nbsp;What can you do in a single transaction in a database? Paul Grenyer writes us his Single CrUD pattern.</p>
<p><strong>Body:</strong>&nbsp;<p>Software patterns have their roots in architecture. In 1978, Christopher Alexander published a book called <em>A Pattern Language: Towns, Buildings, Construction</em> about the patterns heâ€™d discovered designing buildings [<a href="#[Alexander78]">Alexander78</a>]. A pattern can be thought of as a tried and tested way of doing something which can be applied in different contexts. Think about how the <span class="pattern">Observer</span> or <span class="pattern">Visitor</span> pattern is implemented across languages such as Java, Ruby and JavaScript, where the different language idioms dictate slightly different implementations of the same basic pattern.</p>

<p>Software patterns became popular with the publishing of the Gang of Four book, <em>Design patterns: elements of reusable object-oriented software</em> [<a href="#[GoF94]">GoF94</a>]. It contains a number of patterns, most of which every developer should know, even if itâ€™s to know to avoid the likes of <span class="pattern">Singleton</span>. However, these arenâ€™t the only patterns! Indeed, patterns are not created, they are discovered and documented. Whole conferences [<a href="#[Europlop]">Europlop</a>] are dedicated to software patterns, where delegates are encouraged to bring their pattern write-ups for appraisal by their peers and the experts.</p>

<p>When I joined ACCU in 2000, I was encouraged by another member to write for the groupâ€™s magazine, but I didnâ€™t think Iâ€™d have anything to contribute that someone hadnâ€™t already thought of and written about. As I gained experience, I found I had quite a lot to write about and to challenge.</p>

<p>In the same way, youâ€™d have thought that 23 years after the Gang of Four book most, if not all, of the software patterns had been discovered and documented. Of course, they havenâ€™t and I believed, from checking with industry experts, that what Iâ€™m calling the <span class="pattern">Single CrUD Transaction</span> pattern, although used by many, hadnâ€™t been written up anywhere publicly. However, after submitting the pattern to <em>Overload</em> for review, it was pointed out that it is part of the <span class="pattern">Foreign Key Mapping</span> pattern as written up by Martin Fowler [<a href="#[Fowler02]">Fowler02</a>]. Iâ€™ve just gone into a little more detail.</p>

<h2>Name: Single CrUD Transaction</h2>

<h3>Intent</h3>

<p>To create, update and delete items in a datastore within a single transaction. </p>

<h3>Problem</h3>

<p>Sometimes itâ€™s necessary to create, update and delete items in a datastore in a single transaction. Traditional web applications support create, update and delete in separate transactions and require the page to be reloaded between each action.</p>

<p>Modern web applications allow the items of a list to be created, updated and deleted in a browser without any interaction with the server or the underlying datastore. Therefore when the list is sent to the server side it must determine which items are new, which already exist and must be updated and which have been removed from the list and must be deleted.</p>

<p>One simple solution is to delete all of the items from the datastore and simply replace them with the list of line items passed from the browser to the server. There are at least two potential drawbacks with this approach:</p>

<ul>
	<li>If the datastore (such as a relational database) uses unique, numerical ids to identify each item in the list, the size of the ids can become very big, very quickly.</li>
	
	<li>If the datastore (such as a relational database) has other data which references the ids of the items in the list, the items cannot be deleted without breaking the referential integrity.</li>
</ul>

<h3>Solution</h3>

<p>The <span class="pattern">Single CrUD Transaction</span> pattern gets around these drawbacks by performing three operations within a single transaction:</p>

<ul>
	<li>Delete all of the list items from the datastore whose ids are not in the list passed from the browser to the server.</li>
	
	<li>Update each of the items in the datastore whose ids match ids in the list passed from the browser to the server.</li>
	
	<li>Create new items in the datastore for each item in the list passed from the browser to the server which do not yet have ids.</li>
</ul>

<p>Each action is executed within a single transaction so that if any individual action fails the list is returned to its original state. </p>

<h3>Applicability</h3>

<p>Use the <span class="pattern">Single CrUD Transaction</span> pattern when:</p>

<ul>
	<li>Datastores cannot have new items added, existing items updated and/or items removed in separate transactions.</li>
	
	<li>Creating new ids for each item in the list each time the datastore is modified is expensive or cumbersome.</li>
	
	<li>Removing all the items of a list from a datastore and recreating the list in the datastore breaks referential integrity.</li>
</ul>

<h3>Advantages and disadvantages</h3>

<ul>
	<li>Advantage: Entire update happens within a single transaction.</li>
	
	<li>Disadvantage: Three separate calls to the datastore within a single transaction.</li>
</ul>

<h2>References</h2>

<p class="bibliomixed"><a id="[Alexander78]"></a>[Alexander78] Christopher Alexander, 1978, <em>A Pattern Language: Towns, Buildings, Construction</em>, OUP USA (ISBN-13: 978-0195019193)</p>

<p class="bibliomixed"><a id="[Europlop]"></a>[Europlop] EuropPLoP (European Conference on Pattern Languages of Programs), <a href="http://www.europlop.net/">http://www.europlop.net/</a></p>

<p class="bibliomixed"><a id="[Fowler02]"></a>[Fowler02] Martin Fowler, 2002, <em>Patterns of Enterprise Application Architecture</em>, Addison Wesley, (ISBN-13: 978-0321127426)</p>

<p class="bibliomixed"><a id="[GoF94]"></a>[GoF94] Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, <em>Design patterns: elements of reusable object-oriented software</em>, 1994, (ISBN-13: 978-0201633610)</p>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
