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

<channel>
	<title>Marcio Garcia</title>
	<atom:link href="http://marciogarcia.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://marciogarcia.com</link>
	<description></description>
	<pubDate>Sun, 30 May 2010 14:32:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Heroku - No ssh public key found</title>
		<link>http://marciogarcia.com/?p=262</link>
		<comments>http://marciogarcia.com/?p=262#comments</comments>
		<pubDate>Sun, 30 May 2010 14:28:48 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[Git]]></category>

		<category><![CDATA[Heroku]]></category>

		<category><![CDATA[Mac OS]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[MacOS]]></category>

		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=262</guid>
		<description><![CDATA[On my first project uploaded on Heroku I got the problem: 
No ssh public key found in /Users/mmangar/.ssh/id_[rd]sa.pub.  You may want to specify the full path to the keyfile.

Full Error: 

How to solve it? Luckily that&#8217;s not hard, actually it&#8217;s simple, you just have to generate a RSA key and a DSA key. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>On my first project uploaded on Heroku I got the problem: </p>
<blockquote><p>No ssh public key found in /Users/mmangar/.ssh/id_[rd]sa.pub.  You may want to specify the full path to the keyfile.</p></blockquote>
<p></p>
<p><b>Full Error: </b><br />
<script src="http://gist.github.com/419056.js?file=Heroku+Problem"></script></p>
<p>How to solve it? Luckily that&#8217;s not hard, actually it&#8217;s simple, you just have to generate a RSA key and a DSA key. It&#8217;s simple, trust me! </p>
<p><b>Generating the RSA: </b> <br />
<script src="http://gist.github.com/419056.js?file=Generating+RSA"></script></p>
<p><b>Generating the DSA: </b> <br />
<script src="http://gist.github.com/419056.js?file=Generating+DSA"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=262</wfw:commentRss>
		</item>
		<item>
		<title>Testing code with dependency of static methods</title>
		<link>http://marciogarcia.com/?p=252</link>
		<comments>http://marciogarcia.com/?p=252#comments</comments>
		<pubDate>Mon, 10 May 2010 12:14:06 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Maven]]></category>

		<category><![CDATA[Mockito]]></category>

		<category><![CDATA[PowerMock]]></category>

		<category><![CDATA[Test-Driven Development]]></category>

		<category><![CDATA[Unit Test]]></category>

		<category><![CDATA[Test]]></category>

		<category><![CDATA[Unit Tests]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=252</guid>
		<description><![CDATA[




The point here is not to discuss if using static methods is good or not. If you prefer just to use dependency injection and pure object orientation instead of static methods, that&#8217;s with you.
However sometimes you have to live with code not made by you.
You can see this as &#8220;Such nasty code, thanks good the [...]]]></description>
			<content:encoded><![CDATA[<p><center><br />
<a href="http://farm4.static.flickr.com/3088/2293012908_9782b102d5_m.jpg" border="0"><br />
<img src="http://farm4.static.flickr.com/3088/2293012908_9782b102d5_m.jpg" /><br />
</a><br />
</center></p>
<p>The point here is not to discuss if using static methods is good or not. If you prefer just to use dependency injection and pure object orientation instead of static methods, that&#8217;s with you.<br />
However sometimes you have to live with code not made by you.<br />
You can see this as &#8220;Such nasty code, thanks good the project is almost finishing and I&#8217;ll no longer see this code anymore!&#8221;<br />
Did you noted the tense? &#8220;Almost finishing&#8221; it&#8217;s not done yet and it&#8217;ll depend of you to finish it.<br />
Or you can have a different approach - that&#8217;s my favourite:<br />
&#8220;This code suchs! Let&#8217;s do something better and learn something with that.&#8221;</p>
<h2>Starting&#8230;</h2>
<p>That&#8217;s the start point:<br />
I have a code with some static methods and I have to test the code that use these static methods from outside classes.</p>
<h3>Environment</h3>
<p>The environment is: Java, Maven, JUnit4, <a href="http://code.google.com/p/mockito/">Mockito</a> and <a href="http://code.google.com/p/powermock/">PowerMock</a> (when the magic happens)</p>
<h3>Pom.xml</h3>
<p>Some configuration is necessary to make use of Powermock:</p>
<p><script src="http://gist.github.com/393473.js?file=pom.xml"></script></p>
<p>Pay attention on the <a href="http://code.google.com/p/powermock/wiki/MockitoUsage">version of your Mockito/JUnit/Powermock</a> it&#8217;s a bit tricky.</p>
<h3>Static file</h3>
<p>The static file looks like this:<br />
<script src="http://gist.github.com/393473.js?file=StaticClass.java"></script></p>
<p>The piece of code that calls the FileHelper.saveFile(..) is this one:</p>
<p><script src="http://gist.github.com/393473.js?file=Controller.java"></script></p>
<h3>Testing</h3>
<p>Take a look at the code that&#8217;s gonna test the Controller&#8230;</p>
<p><script src="http://gist.github.com/393473.js?file=Test.java"></script></p>
<h2>Important</h2>
<p>- Two new annotations on the class level:<br />
@RunWith(PowerMockRunner.class)<br />
@PrepareForTest(FileHelper.class) : Tells to PowerMock what is the class that shoud be static mocked.<br />
- PowerMockito.mockStatic(StaticClass.class) : mocks the class</p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=252</wfw:commentRss>
		</item>
		<item>
		<title>Uploading files using SpringMVC</title>
		<link>http://marciogarcia.com/?p=242</link>
		<comments>http://marciogarcia.com/?p=242#comments</comments>
		<pubDate>Thu, 06 May 2010 11:34:03 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Maven]]></category>

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[Spring]]></category>

		<category><![CDATA[SpringMVC]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=242</guid>
		<description><![CDATA[
A quick setup to upload files using SpringMVC.
Dependencies
I&#8217;m using Maven so the very first step is to add some extra dependencies: commons-io and commons-fileupload:

Application Context
Second step is to setup the application context to make usage of multipart feature:  
Controller
Third step is to create your controller. Note that there is a new type here: MultipartFile [...]]]></description>
			<content:encoded><![CDATA[<p><center><a href="http://www.flickr.com/photos/edupov/4504089105/" border="0"><img src="http://farm5.static.flickr.com/4042/4504089105_45ef1f7992_m.jpg" /></a></center></p>
<p>A quick setup to upload files using SpringMVC.</p>
<h2>Dependencies</h2>
<p>I&#8217;m using Maven so the very first step is to add some extra dependencies: commons-io and commons-fileupload:</p>
<p><script src="http://gist.github.com/392016.js?file=gistfile1.txt"></script></p>
<h2>Application Context</h2>
<p>Second step is to setup the application context to make usage of multipart feature:  <script src="http://gist.github.com/392019.js?file=gistfile1.txt"></script></p>
<h2>Controller</h2>
<p>Third step is to create your controller. Note that there is a new type here: MultipartFile as parameter.</p>
<p><script src="http://gist.github.com/392020.js?file=gistfile1.java"></script></p>
<h2>View</h2>
<p>And the last step: your JSP page.  <script src="http://gist.github.com/392021.js?file=gistfile1.jsp"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=242</wfw:commentRss>
		</item>
		<item>
		<title>Differentiating Object from Data Structure</title>
		<link>http://marciogarcia.com/?p=183</link>
		<comments>http://marciogarcia.com/?p=183#comments</comments>
		<pubDate>Sat, 30 Jan 2010 23:43:11 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Patterns]]></category>

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[Test-Driven Development]]></category>

		<category><![CDATA[Unit Test]]></category>

		<category><![CDATA[Good Practices]]></category>

		<category><![CDATA[Unit Tests]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=183</guid>
		<description><![CDATA[//alert('Howdy!');
Let&#8217;s start from begin: What is the difference between Object and Data Structure?
From wikipedia a Data Structure is: a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.[1][2]
As well as Object is: any entity that can be manipulated by the commands of a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://marciogarcia.com/wp-content/uploads/2010/01/egg.gif" alt="egg" title="egg" width="300" height="209" class="alignleft size-full wp-image-221" /><script>//alert('Howdy!');</script><br />
Let&#8217;s start from begin: What is the difference between <a href="http://en.wikipedia.org/wiki/Object_(computer_science)" target="wiki">Object</a> and <a href="http://en.wikipedia.org/wiki/Data_Structure" target="wiki">Data Structure</a>?</p>
<p>From wikipedia a Data Structure is: a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.[1][2]</p>
<p>As well as Object is: any entity that can be manipulated by the commands of a programming language, such as a value (computer science), variable, function, or data structure.</p>
<p>Just to put some code in it.</p>
<p>This is a Data Structure:<br />
<script src="http://gist.github.com/266506.js?file=gistfile1.java"></script></p>
<p>And this is an Object:<br />
<script src="http://gist.github.com/266506.js?file=gistfile2.java"></script></p>
<p>This is how I&#8217;m policing myself to code. Letting VOs, DTOs, Entities exactly as a data structure, just with fields, getters and setters. Even constructors I am letting outside it. Maybe I&#8217;m exaggerating do not creating the constructors or switching them to static methods into the VOs. However, my experience with this approach tells me that letting them out is more productive specially when we are talking about testable code and isolating responsibilities improving the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle" target="wiki">Single Responsibility Principle</a>.</p>
<p>You may be asking: &#8220;Are telling that I&#8217;m not more able to create my own Entities directly?</p>
<p>The answer is yes and no. I&#8217;ll explain.</p>
<p>To a simple task just create an instance of an Data Structure, you could just call the default constructor.<br />
But to create a more sophisticated instance of that object for some specific porpoise instead of using a static method describing the  usage of that as suggested by <a href="http://twitter.com/unclebobmartin" target="twitter">Uncle Bob Martin</a> on his book <a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882" target="amazon">Clean Code</a> I suggest you to use an Object to handle the creation of the Data Structure initializing it with the propers values for the specific usage.</p>
<p>Do you disagree? Let your comment down here! </p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=183</wfw:commentRss>
		</item>
		<item>
		<title>Hibernate - Insert Before Delete</title>
		<link>http://marciogarcia.com/?p=229</link>
		<comments>http://marciogarcia.com/?p=229#comments</comments>
		<pubDate>Mon, 11 Jan 2010 03:50:54 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[Hibernate]]></category>

		<category><![CDATA[JPA]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=229</guid>
		<description><![CDATA[


Today I faced a problem that I already had faced some time before, but I didn&#8217;t documented that in blog entry or even in my &#8220;ProblemsThatCanNotBeForgotten.TXT&#8221;. So that&#8217;s the time for that.
The problem is: I have an entity called Team who has a List of Players (other entity). I&#8217;m trying to move an Player from [...]]]></description>
			<content:encoded><![CDATA[<p><center><br />
<img src="http://marciogarcia.com/wp-content/uploads/2010/01/deadlock.jpg" alt="deadlock" title="deadlock" width="500" height="400" class="alignnone size-full wp-image-240" /><br />
</center><br />
Today I faced a problem that I already had faced some time before, but I didn&#8217;t documented that in blog entry or even in my &#8220;ProblemsThatCanNotBeForgotten.TXT&#8221;. So that&#8217;s the time for that.</p>
<p>The problem is: I have an entity called Team who has a List of Players (other entity). I&#8217;m trying to move an Player from one team to the other at the same transaction. Follow some code:</p>
<p><script src="http://gist.github.com/271818.js?file=gistfile1.java"></script><br />
<center><i>Original Team.java</i></center></p>
<p>After load this Entity by the JPA/Hibernate engine and have the tables created this is the structure and the indexes created:<br />
<center><br />
<img src="http://marciogarcia.com/wp-content/uploads/2010/01/table_team_player_one2many.png" alt="table_team_player_one2many" title="table_team_player_one2many" width="400" height="344" class="alignnone size-full wp-image-234" /><br />
</center></p>
<h2>The Problem</h2>
<p>As happens in the real world some teams wants to trade their players, so the software has to be able to transfer one player from one team to another.<br />
The code wich do this is very simple, just remove a player from one collection&#8217;s player team from the seller team and then insert the remove player to the buyer team.<br />
After the transfer, the application apply this changes on the Database with merge(entity) call.</p>
<p><script src="http://gist.github.com/271826.js?file=gistfile1.java"></script><br />
<center><i>Call that merge a Team</i></center></p>
<p>Doing this a message telling that it&#8217;s impossible to insert a duplicate row blows up on the console.</p>
<p>This is because Hibernate does the INSERT statement BEFORE the DELETE.</p>
<p>After looking at Internet I didn&#8217;t find anything to solve that. Just a workaround that fixes that. But as I said, it&#8217;s a workaround.</p>
<h2>Solving (woking it around)</h2>
<p>To solve that problem I changed the reference from Team to Player from @OneToMany to @ManyToMany. The problem with this approach is that I lose the rule in the DB that has the control over the unicity of a player belonging to just one Team.</p>
<p>This is how the code and the table at the DB look like:</p>
<p><script src="http://gist.github.com/271818.js?file=gistfile2.java"></script><br />
<center><i>New Team.java</i></center></p>
<p><center><br />
<img src="http://marciogarcia.com/wp-content/uploads/2010/01/table_team_player_many2many.png" alt="table_team_player_many2many" title="table_team_player_many2many" width="400" height="344" class="alignnone size-full wp-image-236" /><br />
</center><br />
<center><i>Table without the constraint</i></center></p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=229</wfw:commentRss>
		</item>
		<item>
		<title>Faces config editor with problems to load the designer view on Eclipse</title>
		<link>http://marciogarcia.com/?p=212</link>
		<comments>http://marciogarcia.com/?p=212#comments</comments>
		<pubDate>Fri, 08 Jan 2010 12:35:25 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[JSF]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=212</guid>
		<description><![CDATA[


After create a maven project directly on Eclipse and setting JavaServer Faces Facet for that project I faced a problem that the visual editor of the faces-config files didn&#8217;t load it. Just the XML view was OK.
Surfing on the Internet I have found some tips about that, one of them was to include the JSF [...]]]></description>
			<content:encoded><![CDATA[<p><center><br />
<img src="http://marciogarcia.com/wp-content/uploads/2010/01/45687289.gif" alt="45687289" title="45687289" width="336" height="273" class="aligncenter size-full wp-image-216" /><br />
</center></p>
<p>After create a maven project directly on <a href="http://www.eclipse.org" target="eclipse">Eclipse</a> and setting JavaServer Faces Facet for that project I faced a problem that the visual editor of the faces-config files didn&#8217;t load it. Just the XML view was OK.<br />
Surfing on the Internet I have found some tips about that, one of them was to include the JSF Facet. It can be found <a href="http://www.vogella.de/articles/JavaServerFaces/article.html#firstjsf_project" target="jsf">here</a> and <a href="http://www.eclipsezone.com/eclipse/forums/t90085.rhtml" target="jsf"> here</a>. But it didn&#8217;t solve my problem. What realy solved that was to include a line directly into the .settings/org.eclipse.wst.common.component file.<br />
Follow bellow my .settings/org.eclipse.wst.common.component file in two versions, the first one with out the visual jsf config editor working and the second one with it running OK.<br />
Note that the only thing that has changed was the inclusion of the one line in the wb-module.</p>
<p><script src="http://gist.github.com/268224.js?file=gistfile1.xsl"></script><br />
<center><i>Version 1: Not working</i></center></p>
<p><script src="http://gist.github.com/268224.js?file=gistfile2.xsl"></script><br />
<center><i>Version 2: Working!</i></center></p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=212</wfw:commentRss>
		</item>
		<item>
		<title>Jersey, Maven and Spring</title>
		<link>http://marciogarcia.com/?p=151</link>
		<comments>http://marciogarcia.com/?p=151#comments</comments>
		<pubDate>Sat, 02 Jan 2010 13:00:24 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Jersey]]></category>

		<category><![CDATA[Maven]]></category>

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=151</guid>
		<description><![CDATA[





Recently I needed to work on a project where all the communication between fron and backend was done usin HTTP requests. At the beginning we considered to use Servlet with some helpers wich acted as a clue mapping the URL&#8217;s parameters to a Map object. Internally this Map was &#8220;injected&#8221; in all resource classes.


It was [...]]]></description>
			<content:encoded><![CDATA[<p><center><br />
<a href="http://www.flickr.com/photos/sharkbait/3415708872/sizes/m/in/set-72157600014134111/" target="_a"><br />
<img src="http://farm4.static.flickr.com/3361/3415708872_357d08559a.jpg" border="0" /><br />
</a><br />
</center></p>
<p>
Recently I needed to work on a project where all the communication between fron and backend was done usin HTTP requests. At the beginning we considered to use Servlet with some helpers wich acted as a clue mapping the URL&#8217;s parameters to a Map object. Internally this Map was &#8220;injected&#8221; in all resource classes.
</p>
<p>
It was a solution to be considered but how it was the very first idea that the team had, we decided to discard it.
</p>
<p>
As required by the client we had to use <a href="http://maven.apache.org/" target="_a">Maven</a> and <a href="http://www.springsource.org/" target="_a">Spring</a>. However all others libraries we could decide and bear with it.</p>
<p>So, the second idea was to use <a href="http://en.wikipedia.org/wiki/RESTful" target="_a">RESTful</a> simply to facilitate the job of mapping the parameters coming from the URL and the internal code.
</p>
<p>
We researched the first lib <a href="https://jersey.dev.java.net/" target="_a">Jersey</a> since it is the standard implementation of the <a href="https://jsr311.dev.java.net/nonav/releases/1.1/index.html" target="_a">JSR-311</a> we also researched the <a href="http://www.restlet.org/" target="_a">Restlet</a> API.<br />
We decided to go again the ideology to refuse he first option at this time. We studied both of them.<br />
Both frameworks had unique aspects and a vast documentation. Each one with their singularities, for instance on Restlet it is necessary to configure the &#8220;routes&#8221; in a subclass of Application.
</p>
<p>But the main reasons that made us to decide to use Jersey were:</p>
<ol>
<li> Be the standard implementation of the specification</li>
<li> Less bureaucracy on the implementation of the resources</li>
<li> Almost natural integration with Spring for classes and resources(Request, Response, ServletContext) injection.</li>
</ol>
<p>
This &#8220;walk through&#8221; has the objective to exemplify how to create a simple application using: Spring, Maven and Jersey made simple.
</p>
<h2>Setup</h2>
<ol>
<li>Include the entry for the jersey-spring repository in the pom.xml file.</li>
<p><script>
//alert('Howdy!');
</script><br />
<script src="http://gist.github.com/261968.js?file=gistfile1.xsl"></script></p>
<li>Include the libs as dependencies: jersey  spring</li>
<p><script src="http://gist.github.com/261970.js?file=gistfile1.xsl"></script> </p>
<li>Configure the web.xml file</li>
<p><script src="http://gist.github.com/261979.js?file=gistfile1.xsl"></script>
</ol>
<h2>It&#8217;s time do code!</h2>
<ol>
<li>Configuring the Spring (applicationContext.xml)</li>
<p>Create applicationContext.xml file on META-INF directory of your app. This code tells to Spring engine to that com.mng.jerseydemo package is available for dependency injection. Follow a model of this file:<br />
<script src="http://gist.github.com/261981.js?file=gistfile1.xsl"></script> </p>
<li>Create the first resource.</li>
<p><script src="http://gist.github.com/261997.js?file=gistfile1.java"></script><br />
At this snipped there are some annotations between then:</p>
<ol>
<li><b>@Path</b></li>
<p>This is the URL pattern that will be handled by the class (resource). It can be informed variables following the model: {valiableName}. For instance: @Path(&#8221;/user/{username}/{password}&#8221;). </p>
<li><b>@Autowired</b></li>
<p>Injects an object from the variable type.</p>
<li><b>@GET</b></li>
<p>Response request made via GET. There are also: @POST, @PUT and @DELETE that can be used at the same way then @GET.</p>
<li><b>@Produces</b></li>
<p>Inform the return type of a method. This annotation can be informed for a method as well as for a class together with @Path.<br />
If specified at the class all methods inside this one without a specific @Produces will follow the @Produces of the class.</p>
<li><b>@PathParam</b></li>
<p>Translate mapped variables from a URL to an object. This will be mapped to a variable informed at the signature of the method.
</ol>
</ol>
<h2>Getting access</h2>
<p>To get access to a resource just created you can use your own browser (Chrome or Firefox) with then is easy to test the &#8220;verb&#8221; GET.<br />
However, if you are in the &#8220;X&#8221; world (Linux, Unix or even Mac OS) relax, take a cup of tea and use <a href="http://curl.haxx.se/" target="_a">cUrl</a>.<br />
In a fast and simple way this is how you can use to test all the verbs available (GET, PUT, POST and DELETE) through the parameter: &#8220;-X&#8221; informing the method to be used.<br />
<script src="http://gist.github.com/263187.js?file=gistfile1.bat"></script></p>
<p>And with the &#8220;-F&#8221; parameter you can specify the key value parameters for the POST method (@QueryParam).<br />
<script src="http://gist.github.com/263188.js?file=gistfile1.bat"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=151</wfw:commentRss>
		</item>
		<item>
		<title>Controlling domain data with Hibernate and Enum</title>
		<link>http://marciogarcia.com/?p=169</link>
		<comments>http://marciogarcia.com/?p=169#comments</comments>
		<pubDate>Wed, 30 Dec 2009 22:00:36 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[Hibernate]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Patterns]]></category>

		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=169</guid>
		<description><![CDATA[It is common to have a field into the table that his domain is no bigger to created a domain table just for that field and let it &#8220;free&#8221; as a String is a bit insecure.
A possible solution - if possible in your company - could be the creation of a big table for all [...]]]></description>
			<content:encoded><![CDATA[<p>It is common to have a field into the table that his domain is no bigger to created a domain table just for that field and let it &#8220;free&#8221; as a String is a bit insecure.</p>
<p>A possible solution - if possible in your company - could be the creation of a big table for all simple domain data such as: gender(M/F) conditional(Yes/No) and so on.</p>
<p>But talking about Hibernate and Java (1.5+) we could use a more sophisticated solution such as Enuns.</p>
<p>Let&#8217;s start our sample defining the Enum and the Client class:</p>
<p><script>
//alert('Howdy!');
</script></p>
<p><script src="http://gist.github.com/265630.js?file=gistfile2.java"></script><br />
<center><i>Client class</i></center></p>
<p><script src="http://gist.github.com/265630.js?file=gistfile1.java"></script><br />
<center><i>Gender enum</i></center></p>
<p>The annotation @Enumerated has just one param and it can had two values:</p>
<ol>
<li>EnumType.ORDINAL</li>
<li>EnumType.STRING</li>
</ol>
<p>The difference between them are not visible from the Object&#8217;s point of view. For this field will be associated an Enum with all it&#8217;s structure.<br />
However, the difference between ORDINAL and STRING can be seen when you take a look at the database. When you define ORDINAL the position defined in Enum for that value will be stored. Starting from zero (zero based). For instance if you define the EnumType as ORDINAL and create an object like this:<br />
<script src="http://gist.github.com/265640.js?file=gistfile1.java"></script></p>
<p>And store it in database the record stored will looks like this:<br />
<img src="http://marciogarcia.com/wp-content/uploads/2009/12/enum_ordinal.png" alt="enum_ordinal" title="enum_ordinal" width="155" height="56" class="aligncenter size-full wp-image-172" /></p>
<p>On the other hand, if the definition of the EnumType is defined as STRING, for the same creation code will produce this record in the database:<br />
<img src="http://marciogarcia.com/wp-content/uploads/2009/12/enun_string.png" alt="enun_string" title="enun_string" width="159" height="59" class="aligncenter size-full wp-image-173" /></p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=169</wfw:commentRss>
		</item>
		<item>
		<title>Problems with Ruby: can&#8217;t find header files for ruby on Snow Leopard</title>
		<link>http://marciogarcia.com/?p=136</link>
		<comments>http://marciogarcia.com/?p=136#comments</comments>
		<pubDate>Mon, 28 Dec 2009 14:00:56 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[Mac OS]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[XCode]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=136</guid>
		<description><![CDATA[



A couple of days ago I installed (upgrade actually) my Mac with the Snow Leopard (Mac OX 10.6.2). This was my first migration to the Mac World, before that I just went crazy at the beginning from Win3.11 to Win95 to Win98. After that I just backed up all my files formated the HD and [...]]]></description>
			<content:encoded><![CDATA[<p><center><br />
<a href="http://www.flickr.com/photos/spiral-static/83051034/sizes/s/" border="0"><br />
<img src="http://farm1.static.flickr.com/41/83051034_718981dd39_m.jpg" border="0" alt="" /><br />
</a></center><br />
A couple of days ago I installed (upgrade actually) my Mac with the <a href="http://www.apple.com/macosx/what-is-macosx/" target="m">Snow Leopard (Mac OX 10.6.2)</a>. This was my first migration to the Mac World, before that I just went crazy at the beginning from Win3.11 to Win95 to Win98. After that I just backed up all my files formated the HD and installed a fresh copy of the brand new and &#8220;marvelous-solve-all-your-problems&#8221; last Windows.</p>
<p>After some time decided to try <a href="http://www.ubuntu.com/" target="l">Ubuntu 7.10</a> and the migration to 8.04 was just simple without traumas and the same from 8.04 to 8.10.</p>
<p>So, at this time I decided that after a backup using <a href="http://en.wikipedia.org/wiki/Time_Machine_(Apple_software)" target="w">Time Machine</a> I&#8217;ll try to upgrade that, and leave behind all the bad memories of the my Windows past tragedies.</p>
<p>All ran gloriously! It took around one hour to migrate from the &#8220;old&#8221; Leopard - totally upgraded - to the Snow.</p>
<p>For the project that I was in I just needed Java running with all that stuffs such as: JDK6, <a href="http://www.eclipse.org" target="j">Eclipse</a>, <a href="http://www.springsource.org/" target="j">Spring</a>, <a href="https://www.hibernate.org/" target="j">Hibernate</a>, <a href="http://www.mysql.com/" target="j">MySQL</a>, <a href="http://www.oracle.com/index.html" target="j">Oracle</a>, <a href="http://tomcat.apache.org/" target="j">Tomcat</a>, <a href="https://glassfish.dev.java.net/" target="j">Glassfish</a>. But now that I wanna start a new personal project with <a href="http://rubyonrails.org/" target="ror">Ruby on Rails</a> with <a target="ror">Heroku</a> I got a problem installing the Heroku gem:</p>
<p><script src="http://gist.github.com/264322.js"></script></p>
<p>Actually this is not a problem with Heroku. After some researches I realized that I had on Leopard the XCode installed but I didn&#8217;t installed it on the Snow one.  The solution? Put the same DVD for the install of the SL and click on the icon to install the XCode. </p>
<p><a href="http://marciogarcia.com/wp-content/uploads/2009/12/steps_install_xcode_snowleopard.gif" target="i"><br />
<img src="http://marciogarcia.com/wp-content/uploads/2009/12/steps_install_xcode_snowleopard.gif" alt="steps_install_xcode_snowleopard" title="steps_install_xcode_snowleopard" width="800" height="208" class="aligncenter size-full wp-image-146" /><br />
</a></p>
<p>After the installation I could install the Heroku gem<br />
<script src="http://gist.github.com/264471.js?file=gistfile1.txt"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=136</wfw:commentRss>
		</item>
		<item>
		<title>JSF and Facelets</title>
		<link>http://marciogarcia.com/?p=101</link>
		<comments>http://marciogarcia.com/?p=101#comments</comments>
		<pubDate>Tue, 01 Sep 2009 11:11:27 +0000</pubDate>
		<dc:creator>mgarcia</dc:creator>
		
		<category><![CDATA[JSF]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[Facelets]]></category>

		<guid isPermaLink="false">http://marciogarcia.com/?p=101</guid>
		<description><![CDATA[If on the one hand you have the absolutely perfect Tiles working together (almost inside) Struts, on the other hand Facelets is a very useful, simple and powerful solution for layout design when you are using JSF. In this article I&#8217;ll describe how to configure it in a simple way.
Starting
Download the Facelets lib, I&#8217;m using [...]]]></description>
			<content:encoded><![CDATA[<p>If on the one hand you have the absolutely perfect Tiles working together (almost inside) Struts, on the other hand Facelets is a very useful, simple and powerful solution for layout design when you are using JSF. In this article I&#8217;ll describe how to configure it in a simple way.</p>
<h2>Starting</h2>
<p>Download the Facelets lib, I&#8217;m using the version 1.1.14: <a href="https://facelets.dev.java.net/servlets/ProjectDocumentList?folderID=3635&amp;expandFolder=3635&amp;folderID=0">facelets download.</a> Put the package in your classpath, generally in the WEB-INF/lib directory of your web app.</p>
<p>If you don&#8217;t this is the time to create your &#8220;Dynamic Web Application&#8221; using Eclipse:</p>
<p><img class="aligncenter size-full wp-image-104" title="eclipse-dynamic-web-project" src="http://marciogarcia.com/wp-content/uploads/2009/08/eclipse-dynamic-web-project.png" alt="eclipse-dynamic-web-project" width="594" height="364" />Figure 1: Creating a Dynamic Web Project with Eclipse.</p>
<p>Using Eclipse, locate and double click in the faces-config.xml file, located at: WebContent/WEB-INF/faces-config.xml. You should be able to see a friendly and easy view to configure the faces configurations. Down on the bottom click in the &#8220;Others&#8221; tab, locate the &#8220;View Handler&#8221;, click in &#8220;Add&#8221; and type: com.sun.facelets. select the first option. It should be: com.sun.facelets.FaceletViewHandler.</p>
<p><img class="aligncenter size-full wp-image-106" title="configuring-facelets-eclipse" src="http://marciogarcia.com/wp-content/uploads/2009/08/configuring-facelets-eclipse.png" alt="configuring-facelets-eclipse" width="603" height="302" /></p>
<p>Figure 2: Configuring the FaceletViewHandler</p>
<p>At this point you may be wondering what the magic happened here? That&#8217;s no magic, actually it was just some XML tags added inthe faces-config.xml:</p>
<p><script src="http://gist.github.com/178146.js"></script></p>
<p>Now it&#8217;s time to configure the web.xml. That&#8217;s not so easy like the faces-config, you&#8217;ll have to open the file in the source mode. I reckon that for the web.xml the source view is more productive than the design. Add the follow instructions:</p>
<p><script src="http://gist.github.com/178160.js"></script></p>
<p>Note that this is my complete web.xml. Probably you don&#8217;t need all these stuffs, copy and paste just the difference and the configurations related with the Facelets.</p>
<h2>XHTML versus JSP</h2>
<p>I didn&#8217;t find any good sample using JSP, actually I didn&#8217;t find any. All of them used the xhtml as the extension instead of jsp. For me that&#8217;s fine, but if it&#8217;s not for you a solution that I&#8217;ve found was to <a href="https://facelets.dev.java.net/servlets/ProjectDocumentList?folderID=4190&amp;expandFolder=4190&amp;folderID=3635" target="_blank">download the .tld</a> from the facelets website and put it in the tld directory inside your WEB-INF dir. I dunno if it works, I think that this is too much workaround and decided to give up of this approach and use the well-known and documented xhtm extension. The benefits that I&#8217;ve encountered was that all the HTML inserted in the file is &#8220;compiled&#8221; in runtime, if something wrong was typed you can see the stack trace on the page.</p>
<h2>Layout</h2>
<p>Great all configurations are done, now it&#8217;s time to see our work. First of all we have to create our layout. The strategy here is simple, just a header, content and a footer file. I decided to put these files in the WEB-INF/layout dir.</p>
<p><img class="aligncenter size-full wp-image-112" title="layout" src="http://marciogarcia.com/wp-content/uploads/2009/08/layout.png" alt="layout" width="170" height="92" />Take a look in each content:</p>
<p>Header.xhtml:<br />
<script src="http://gist.github.com/178164.js"></script></p>
<p>Footer.xhtml:<br />
 <script src="http://gist.github.com/178165.js"></script></p>
<p>Layout.xhtml:<br />
<script src="http://gist.github.com/178166.js"></script></p>
<h2>First Page</h2>
<p>The target here is to replace the content and keep the header and the footer sections. For that, let&#8217;s create a file called index.xhtml with the follow content:</p>
<p>Index.xhtml<br />
 <script src="http://gist.github.com/178168.js"></script></p>
<p>Start the tomcat and point your browser out at: http://localhost:8080/your_app/index.jsf</p>
<p>Pay attention, the extension in the URL is JSF and NOT XHTML NOR JSP.</p>
<p>Play with the content and with the variables like title and template to see the difference.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://marciogarcia.com/?feed=rss2&amp;p=101</wfw:commentRss>
		</item>
	</channel>
</rss>
