<?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>big-oh notation - Tan Quach &#187; Programming</title>
	<atom:link href="http://www.tanquach.com/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tanquach.com/blog</link>
	<description>The secret to happiness is low expectations.</description>
	<lastBuildDate>Wed, 03 Feb 2010 22:57:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Limitations of Using MySql with Grails</title>
		<link>http://www.tanquach.com/blog/2009/08/20/limitations-of-using-mysql-with-grails/</link>
		<comments>http://www.tanquach.com/blog/2009/08/20/limitations-of-using-mysql-with-grails/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 17:29:27 +0000</pubDate>
		<dc:creator>tan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.tanquach.com/blog/?p=78</guid>
		<description><![CDATA[Since Grails uses Hibernate inherently, it is a good idea to understand the limitations before storming ahead and bashing your brain trying to figure out why things don&#8217;t work. The first issue I came across was with a domain object having a long text field, such as a &#8220;url&#8221; which can be at most 1024 characters.

class [...]]]></description>
			<content:encoded><![CDATA[<div>Since Grails uses Hibernate inherently, it is a good idea to understand the limitations before storming ahead and bashing your brain trying to figure out why things don&#8217;t work. The first issue I came across was with a domain object having a long text field, such as a &#8220;url&#8221; which can be at most 1024 characters.</div>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Merchant <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span> name
	<span style="color: #003399;">String</span> url
        <span style="color: #000000; font-weight: bold;">static</span> constraints <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
               name<span style="color: #009900;">&#40;</span>blank<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>, unique<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
               url<span style="color: #009900;">&#40;</span>maxSize<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1000</span>, unique<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>, url<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>, blank<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>\<span style="color: #339933;">&lt;</span>span style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;font-family: 'Lucida Grande', 'Lucida Sans Unicode', Tahoma, Verdana, sans-serif; line-height: 19px; white-space: normal; font-size: 13px;&quot;</span><span style="color: #339933;">&gt;</span>After starting up the app using <span style="color: #0000ff;">&quot;grails run-app&quot;</span> we run into a problem with the hbm2ddl.<span style="color: #006633;">SchemaUpdate</span> saying that<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">BLOB<span style="color: #000000; font-weight: bold;">/</span>TEXT column <span style="color: #ff0000;">'url'</span> used <span style="color: #000000; font-weight: bold;">in</span> key specification without a key length</pre></div></div>

<p>Columns with SQL type TEXT exceeding 256 characters will fail table creation because of <a href="http://forums.mysql.com/read.php?10,118630,118641#msg-118641" target="_blank">MySQL Error 1170</a>. Two immediate options for relief are: 1) hand-craft the schema DDL and generate your database schema manually, or 2) remove any constraints that might require an index (e.g. unique constraint).</p>
<p>If you choose option 1, you won&#8217;t be able to use the &#8220;create-drop&#8221; option in your DataSource.groovy configuration, or even &#8220;update&#8221; if you are introducing a new field. This slows down development considerably.</p>
<p>If you choose option 2, you will likely violate business rules and introduce data integrity issues.</p>
<h2>The Solution</h2>
<div>A proper solution (but not necessarily the most elegant) would be using a custom mapping in the domain class to override the length of the column to be used in the index. The obvious drawback of this is the duplication of column length in the constraints and the mapping.</div>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Merchant <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span> name
	<span style="color: #003399;">String</span> url
        <span style="color: #000000; font-weight: bold;">static</span> mapping <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            url sqlType<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;varchar(1000)&quot;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">static</span> constraints <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
               name<span style="color: #009900;">&#40;</span>blank<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>, unique<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
               url<span style="color: #009900;">&#40;</span>maxSize<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1000</span>, unique<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>, url<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>, blank<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The consequences of this solution is that the column is now a VARCHAR and not TEXT. In your scenario, this might not be desirable, and of course you should do your own diligence in comparing the benefits/costs of using VARCHAR as opposed to TEXT. In most cases, the differences of using VARCHAR or TEXT are negligible.</p>
<p>Further reading: <a href="http://www.amazon.ca/gp/product/1590599950?ie=UTF8&#038;tag=bigohnotation-20&#038;linkCode=as2&#038;camp=15121&#038;creative=390961&#038;creativeASIN=1590599950">The Definitive Guide to Grails, Second Edition</a><img src="http://www.assoc-amazon.ca/e/ir?t=bigohnotation-20&#038;l=as2&#038;o=15&#038;a=1590599950" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tanquach.com/blog/2009/08/20/limitations-of-using-mysql-with-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Neal Ford Talks About DSL vs. API Design</title>
		<link>http://www.tanquach.com/blog/2008/02/27/neal-ford-talks-about-dsl-vs-api-design/</link>
		<comments>http://www.tanquach.com/blog/2008/02/27/neal-ford-talks-about-dsl-vs-api-design/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 06:43:48 +0000</pubDate>
		<dc:creator>tan</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://big-oh.tantastik.org/?p=3</guid>
		<description><![CDATA[Following up with Bloch&#8217;s presentation on Effective API design, I would encourage those that are interested in programming languages to look through Neal Ford&#8217;s slides on Language Oriented Programming, which does a brief comparison on DSL vs. API design, along with how to construct good bases for DSLs in Java.
I found this presentation invigorating, and [...]]]></description>
			<content:encoded><![CDATA[<p>Following up with Bloch&#8217;s presentation on Effective API design, I would encourage those that are interested in programming languages to look through Neal Ford&#8217;s slides on <a href="http://www.nealford.com/downloads/conferences/Neal_Ford-Language_Oriented_Programming-handouts.pdf">Language Oriented Programming</a>, which does a brief comparison on DSL vs. API design, along with how to construct good bases for DSLs in Java.</p>
<p>I found this presentation invigorating, and it got me very excited. This is a refreshing new way of looking at software design, and would address many of the ugly legacy design patterns that we have inherited specifically due to J2EE. I look forward to seeing more Java frameworks evolve towards a design similar to JMock, which accurately captures behaviour, rather than function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tanquach.com/blog/2008/02/27/neal-ford-talks-about-dsl-vs-api-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
