<?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>Borba on Software &#187; hibernate</title>
	<atom:link href="http://borba.blog.br/tag/hibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://borba.blog.br</link>
	<description>Desenvolvendo Software com Qualidade.</description>
	<lastBuildDate>Tue, 24 Jan 2012 11:16:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Um Software de Qualidade</title>
		<link>http://borba.blog.br/2009/07/um-software-de-qualidade/</link>
		<comments>http://borba.blog.br/2009/07/um-software-de-qualidade/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 19:31:00 +0000</pubDate>
		<dc:creator>Luiz Borba</dc:creator>
				<category><![CDATA[Programação]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[qualidade]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://borba.blog.br/?p=111</guid>
		<description><![CDATA[Eu vou falar um pouco mais sobre o WordPress porque acho que é um bom exemplo de um software de qualidade. Vou começar pela instalação. Para instalar o WordPress, só é necessário verificar o "Famous 5-Minute Install". Pronto. Funciona de verdade. Na verdade não é você que instala o WordPress, ele se instala sozinho, você [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-112" title="wordpress logo" src="http://borba.blog.br/wordpress/wp-content/uploads/2009/07/blue-m.png" alt="wordpress logo" width="100" height="100" />Eu vou falar um pouco mais sobre o <a href="http://www.wordpress.org" target="_blank">WordPress</a> porque acho que é um bom exemplo de um software de qualidade.</p>
<p>Vou começar pela instalação. Para instalar o WordPress, só é necessário verificar o "<a href="http://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install" target="_blank">Famous 5-Minute Install</a>". Pronto. Funciona de verdade. Na verdade não é você que instala o WordPress, ele se instala sozinho, você apenas manda ele se instalar. Não dá pra engolir softwares que só para instalar é preciso ler um livro cheio de procedimentos e depois acaba dando tudo errado e você ainda tem que ficar pesquisando na internet para ver ser descobre o que aconteceu.</p>
<p>Um dos procedimentos que ele faz na instalação é criar a estrutura do banco de dados. Hoje em dia não é difícil encontrar um framework que facilite isso (vide <a href="http://www.hibernate.org" target="_blank">Hibernate</a>), por então não fazemos isso sempre?</p>
<p>Outro exemplo que vi de como o WordPress é robusto foi quando eu resolvi mudar a configuração dos permalinks. Após alterar a configuração veja o que apareceu na tela:</p>
<p><img class="alignnone size-full wp-image-114" title="wp_permalink" src="http://borba.blog.br/wordpress/wp-content/uploads/2009/07/wp_permalink.png" alt="wp_permalink" width="668" height="367" /></p>
<p>Devido a minha escolha o wordpress precisava criar um arquivo .htaccess para atender minha necessidade, como ele sozinho descobriu que não tinha permissão de escrita no diretório, mostrou na tela as instruções detalhadas do procedimento que eu precisava fazer na mão para que os permalinks pudessem funcionar. Quantas vezes você já se deparou com algum erro desconhecido e teve que fuçar logs para descobrir qual o problema?</p>
<p>É verdade, Software Robusto demanda mais esforço mas devemos abrir mão da preguiça. Não podemos é abrir mão da qualidade dos softwares que escrevemos. Software frágeis acabam por consumir a falsa economia no desenvolvimento porque geram um imenso custo de suporte e manutenção. Siga o exemplo do Worpress.</p>
]]></content:encoded>
			<wfw:commentRss>http://borba.blog.br/2009/07/um-software-de-qualidade/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DbUnit x Hibernate</title>
		<link>http://borba.blog.br/2008/09/dbunit-x-hibernate/</link>
		<comments>http://borba.blog.br/2008/09/dbunit-x-hibernate/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 14:41:00 +0000</pubDate>
		<dc:creator>Luiz Borba</dc:creator>
				<category><![CDATA[Programação]]></category>
		<category><![CDATA[dbunit]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[princípio dry]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://metralhadoralord2.wordpress.com/2008/09/11/dbunit-x-hibernate/</guid>
		<description><![CDATA[Aqui na empresa, temos clientes que apenas mandam executar um projeto segundo a arquitetura definida por eles. Algumas vezes é frustante trabalhar neste tipo de projeto, afinal, nem sempre conseguimos seguir nossas convicções e utilizar plenamente nossos conhecimentos e experiência na definição da melhor solução para o problema. Em um desses projetos, fui convocado para [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-49" style="margin-left: 10px;" title="testing" src="http://borba.blog.br/wordpress/wp-content/uploads/2008/09/testing1.jpg" alt="testing" width="256" height="176" />Aqui na empresa, temos clientes que apenas mandam executar um projeto segundo a arquitetura definida por eles. Algumas vezes é frustante trabalhar neste tipo de projeto, afinal, nem sempre conseguimos seguir nossas convicções e utilizar plenamente nossos conhecimentos e experiência na definição da melhor solução para o problema. Em um desses projetos, fui convocado para auxiliar a equipe que estava consumindo muito tempo na implementação dos testes.</p>
<p><strong>O Cenário:</strong></p>
<p>O sistema utiliza <a href="http://java.sun.com/products/ejb">EJB</a> 2 e <a href="http://www.hibernate.org/">Hibernate</a> 2. O cliente exige implementação de testes dos métodos da <a href="http://c2.com/cgi/wiki?FacadePattern">fachada</a> utilizando <a href="http://www.junit.org/">JUnit</a> e <a href="http://dbunit.sourceforge.net/">DbUnit</a>.</p>
<p><strong>Problemas:</strong></p>
<p>A montagem dos cenários é complexa. O DbUnit entende apenas o modelo relacional, isto significa que o engenheiro tem que fazer um "desmapeamento hibernate" na cabeça dele para montar as tabelas e colunas com os valores necessários. Veja um exemplo:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">'1.0'</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">'UTF-8'</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;employee</span> <span style="color: #000066;">start_date</span>=<span style="color: #ff0000;">&quot;2001-01-01&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">first_name</span>=<span style="color: #ff0000;">&quot;Drew&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">ssn</span>=<span style="color: #ff0000;">&quot;333-29-9999&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">last_name</span>=<span style="color: #ff0000;">&quot;Smith&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;employee</span> <span style="color: #000066;">start_date</span>=<span style="color: #ff0000;">&quot;2002-04-04&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">first_name</span>=<span style="color: #ff0000;">&quot;Nick&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">ssn</span>=<span style="color: #ff0000;">&quot;222-90-1111&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">last_name</span>=<span style="color: #ff0000;">&quot;Marquiss&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;employee</span> <span style="color: #000066;">start_date</span>=<span style="color: #ff0000;">&quot;2003-06-03&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">first_name</span>=<span style="color: #ff0000;">&quot;Jose&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">ssn</span>=<span style="color: #ff0000;">&quot;111-67-2222&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">last_name</span>=<span style="color: #ff0000;">&quot;Whitson&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dataset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Claro que esse é um modelo relacional simples, agora imagine modelos de classes complexos, com heranças, relacionamentos, etc. Neste caso, dá bastante trabalho.</p>
<p>Além da dificuldade em produzir a massa de dados, existe um problema muito grave. Dentro das classes de teste é necessário fazer validações contra os valores do arquivo xml (por exemplo em métodos de consulta). Neste caso podemos fazer as validações com valores hard coded, como neste exemplo:</p>
<p><code class="codecolorer java default"><span class="java">assertEquals<span style="color: #009900;">&#40;</span>employee.<span style="color: #006633;">getFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;Jose&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span></code></p>
<p>Que é uma péssima idéia, pois viola o <a href="http://c2.com/cgi/wiki?DontRepeatYourself">princípio DRY</a> (Don't Repeat Yourself). Outra saída é obter os valores do xml através da API do DbUnit, que vai dar uma trabalheira danada, ainda mais se você quiser montar o objeto para fazer comparações deste tipo:</p>
<p><code class="codecolorer java default"><span class="java">assertEquals<span style="color: #009900;">&#40;</span>employeeActual, employeeExpected<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span></code></p>
<p>Já imaginou? Vai ter que construir outro hibernate só para pegar cada valor das tabelas e colunas do arquivo XML e remontar os objetos novamente.</p>
<p><strong>Como Resolver?</strong></p>
<p>O grande problema dessa abordagem é o fato do DbUnit entender apenas de tabelas e colunas. E se existisse um HibernateUnit? No hipotético HibernateUnit eu poderia especificar meus dados na forma de objetos. Além disso, poderia utilizar um formato mais legível e que pudesse ser transformado diretamente para objetos dentro do seu código. Esse formato pode ser o <a href="http://www.yaml.org/">YAML</a>. Veja como ficaria:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">departaments:<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006600; font-weight:bold;">&amp;</span>engineering<br />
&nbsp; &nbsp; &nbsp; id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; name &nbsp; &nbsp; &nbsp; &nbsp;: Engineering<br />
&nbsp; &nbsp; &nbsp; employees:<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">-</span> id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: <span style="color:#006666;">1</span><br />
&nbsp; &nbsp; &nbsp; startDate &nbsp; : <span style="color:#006666;">2001</span><span style="color:#006600; font-weight:bold;">-</span>01<span style="color:#006600; font-weight:bold;">-</span>01<br />
&nbsp; &nbsp; &nbsp; firstName &nbsp; : Drew<br />
&nbsp; &nbsp; &nbsp; lastName &nbsp; &nbsp;: Smith<br />
&nbsp; &nbsp; &nbsp; ssn &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color:#006666;">333</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">29</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9999</span><br />
&nbsp; &nbsp; &nbsp; departament : <span style="color:#006600; font-weight:bold;">*</span>engineering<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">-</span> id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: <span style="color:#006666;">2</span><br />
&nbsp; &nbsp; &nbsp; startDate &nbsp; : <span style="color:#006666;">2002</span><span style="color:#006600; font-weight:bold;">-</span>04<span style="color:#006600; font-weight:bold;">-</span>04<br />
&nbsp; &nbsp; &nbsp; firstName &nbsp; : Nick<br />
&nbsp; &nbsp; &nbsp; lastName &nbsp; &nbsp;: Marquiss<br />
&nbsp; &nbsp; &nbsp; ssn &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color:#006666;">222</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">90</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1111</span><br />
&nbsp; &nbsp; &nbsp; departament : <span style="color:#006600; font-weight:bold;">*</span>engineering<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">-</span> id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: <span style="color:#006666;">3</span><br />
&nbsp; &nbsp; &nbsp; startDate &nbsp; : <span style="color:#006666;">2003</span><span style="color:#006600; font-weight:bold;">-</span>06<span style="color:#006600; font-weight:bold;">-</span>03<br />
&nbsp; &nbsp; &nbsp; firstName &nbsp; : Jose<br />
&nbsp; &nbsp; &nbsp; lastName &nbsp; &nbsp;: Whitson<br />
&nbsp; &nbsp; &nbsp; ssn &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color:#006666;">111</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">67</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">2222</span><br />
&nbsp; &nbsp; &nbsp; departament : <span style="color:#006600; font-weight:bold;">*</span>engineering</div></div>
<p>Inclui um relacionamento para employee só para ficar um pouco mais rico. A vantagem dessa abordagem é que além de ficar mais legível, existem frameworks que serializam e deserializam esse formato para objetos. Com esse recurso, seria possível obter os objetos diretamente do arquivo e em seguida fazer comparações com objetos obtidos no banco. Legal, hein?</p>
<p>Acho que uma solução deste tipo poderia trazer muitos benefícios para o nosso problema. Estou fazendo uma pesquisa e se não existir nada semelhante, devo implementar essa solução como um projeto open source.</p>
<p>Pena que nosso cliente EXIGE que usemos o DbUnit.</p>
]]></content:encoded>
			<wfw:commentRss>http://borba.blog.br/2008/09/dbunit-x-hibernate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

