<?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>Turnleaf Design</title>
	<atom:link href="http://www.turnleafdesign.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.turnleafdesign.com</link>
	<description>Ramblings of a junior developer</description>
	<lastBuildDate>Wed, 11 Nov 2009 05:56:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mocking JDBC Connections with MockRunner</title>
		<link>http://www.turnleafdesign.com/mocking-jdbc-connections-with-mockrunner</link>
		<comments>http://www.turnleafdesign.com/mocking-jdbc-connections-with-mockrunner#comments</comments>
		<pubDate>Wed, 11 Nov 2009 05:54:11 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Mock]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=285</guid>
		<description><![CDATA[Last week I published an article, An Intro into Test Driven Development with Junit4, which got somewhat mixed reviews. One particular commenter on reddit suggested I didn't understand that unit tests shouldn't talk to its data source. I decided to do some investigating into his claims, you can check out my findings here. I was [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fmocking-jdbc-connections-with-mockrunner"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fmocking-jdbc-connections-with-mockrunner" height="61" width="51" /></a></div><p>Last week I published an article, <a href="  http://www.turnleafdesign.com/an-intro-into-test-driven-development-with-junit4" target="_blank">An Intro into Test Driven Development with Junit4</a>, which got somewhat mixed reviews. One particular commenter on reddit suggested I didn't understand that unit tests <a href="http://www.reddit.com/r/programming/comments/9yq8p/an_intro_into_test_driven_development_with_junit4/c0f29uc" target="_blank">shouldn't talk to its data source</a>. I decided to do some investigating into his claims, you can check out my findings <a href="http://www.turnleafdesign.com/ramblings-should-unit-tests-talk-to-a-data-source" target="_blank">here</a>. I was however intrigued none the less and started looking for a tool that would allow me to easily mock a JDBC connection. I found <a href="http://mockrunner.sourceforge.net/" target="_blank">Mockrunner</a> to be the easiest to use of the ones I have found. Below is a brief tutorial on how to use Mockrunner. (Keep in mind that I am still fairly new to using Mockrunner)<span id="more-285"></span></p>
<p>In the class I am testing I am explicitly calling the columns I am retrieving by name. So I need to add these column names to my mock ResultSet.</p>
<pre class="java" name="code" style="display: none;">
result.addColumn("Date");
result.addColumn("High");
result.addColumn("Low");
result.addColumn("Condition");
result.addColumn("ID");</pre>
<p>Obviously I also retrieve data from a result set so I must also insert data into the mock ResultSet. There are several ways to do this, but the easiest I found was using a list. You must add elements to the list in the same order as you added columns to the ResultSet.</p>
<pre class="java" name="code" style="display: none;">
List&lt;Object&gt; rowItems = new ArrayList&lt;Object&gt;();
rowItems.add(new Date(0));
rowItems.add(72);
rowItems.add(56);
rowItems.add("Cloudy");
rowItems.add(1);</pre>
<p>In my actual test case I can verify that I am actually gathering the contents of the result set correctly and that the correct SQL statement was run.</p>
<pre class="java" name="code" style="display: none;">
prepareRS();
ForecastDAO dao = new ForecastDaoImpl(getConnection());
List&lt;Forecast&gt; forecasts = dao.getAllForecasts();

assertTrue(!forecasts.isEmpty());
verifySQLStatementExecuted("SELECT * FROM forecast");
assertEquals(73, forecasts.get(1).getHigh());</pre>
<p>This is but scratching the surface of MockRunner's potential and using mocks at large. I hope this brief tutorial was helpful in getting you started using MockRunner. You can checkout the entire test class <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/22/trunk/%20forecastaccuracychecker/forecastchecker/test/com/tld/dao/TestForecastDaoImpl.java" target="_blank">here</a> and the class that I am testing <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/20/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">here</a>. If you want to get an entire working version of the project be sure to read the <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/20/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">technical guide</a>. Let me know if you have any questions or want to add your own comments.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Mock' rel='tag' target='_blank'>Mock</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a>, <a class='technorati-link' href='http://technorati.com/tag/Testing' rel='tag' target='_blank'>Testing</a>, <a class='technorati-link' href='http://technorati.com/tag/Unit+testing' rel='tag' target='_blank'>Unit testing</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/mocking-jdbc-connections-with-mockrunner/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ramblings: Should unit tests talk to a data source?</title>
		<link>http://www.turnleafdesign.com/ramblings-should-unit-tests-talk-to-a-data-source</link>
		<comments>http://www.turnleafdesign.com/ramblings-should-unit-tests-talk-to-a-data-source#comments</comments>
		<pubDate>Thu, 05 Nov 2009 04:48:40 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Mock]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=280</guid>
		<description><![CDATA[Last week I published an article on test driven development. One person who read my article (briefly) suggested I did not know that unit tests shouldn't talk to their data source. I plan on covering how to mock JDBC connections later this week, however I wanted to do some research to see if what my [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Framblings-should-unit-tests-talk-to-a-data-source"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Framblings-should-unit-tests-talk-to-a-data-source" height="61" width="51" /></a></div><p>Last week I published an article on test driven development. One person who read my article (briefly) suggested I did not know that unit tests <a href="http://www.reddit.com/r/programming/comments/9yq8p/an_intro_into_test_driven_development_with_junit4/c0f29uc" target="_blank">shouldn't talk to their data source</a>. I plan on covering how to mock JDBC connections later this week, however I wanted to do some research to see if what my critic says is an industry standard or a philosophical choice.</p>
<p>Surprisingly there seems to be relatively little information on this subject, or I have been incapable of finding information. From what I have gathered though, the theory that data sources should be mocked is sound, but its may not always be practical to implement it. Below is two reasons why data source connections should be mocked and three reasons why they should not. <span id="more-280"></span></p>
<h3>Why you should mock connections</h3>
<p><strong>Speed –</strong> Talking to a data source is one the primary operations that slows an application's performance. Most data sources require some sort of network connection and retrieving data is often a processor intensive task. Obviously performing these tasks take time. Unit tests are most useful when they are run automatically and frequently to ensure changes being made are not breaking the application. Unit tests that are run automatically should be somewhat speedy, by mocking a data source connection, this can reduce considerably the amount of time it takes to run unit tests.</p>
<p><strong>Remove the reliance on the data source logic –</strong> Unit tests should be testing relatively small parts of code, individual methods and/or small collections of methods. By connecting to a data source you are depending upon the logic of not only how you are connecting, but how the data source operates. This goes beyond the scope of what a unit test should be testing.</p>
<h3>Why you shouldn't mock connections</h3>
<p><strong>It's time consuming –</strong> Writing mocks can be a quite laborious task. I often avoid writing mocks like the plague, because even relatively simple mocks can require a considerable amount of time to get running and running correctly. Even my very simple example of running a single query against a five column table took several hours to setup. Granted this was my first time creating a JDBC mock and future mocks would be easier and quicker to write, but it would still take longer than simply connecting to my database.</p>
<p><strong>It's ugly –</strong> It takes a lot of typing to get even relatively simple mocks working. A lot of the rules that apply to how real business code should be written need not be followed when writing unit tests, that said looking at the code of a unit test shouldn't make your eyes bleed. Unit tests that cannot be easily maintained often become ignored when they break and broken unit test have no value (if ignored).</p>
<p><strong>It's not real – </strong>Mocks don't really care what you put into or take out of them. Real data sources are often not so forgiving. If I misspelled a column or table name in a query, a mock would not pick up on this (you can verify the sql statements run, but again that could be misspelled), where as a real database would. By actually connecting to the real data source you can be more confident that the application will perform its intended tasks.</p>
<h3>Why you should use your head</h3>
<p>Even within the same project there will be instances where mocking a connection to a data source is the right choice and instances when you should actually connect to a real data source. In the early stages of a project using mocks can be more practical as the structure of the data source is more abstract and subject to change. Rewriting a mock is often quicker and easier than restructuring a data source. However as a project matures and the unit tests become more complex, connecting to the real data source may be more practical as it is not only (more) well defined, but writing the mocks begins to require more time. As with all practices, you need decide which one is best to follow (or not) based upon your requirements and restrictions. Though I think it is worth noting standards are standards for a reason. Feel free to weigh in with your own thoughts on the subject.</p>
<p>Additional reading:<br />
<a href="http://www.javaranch.com/journal/2003/12/UnitTestingDatabaseCode.html" target="_blank">http://www.javaranch.com/journal/2003/12/UnitTestingDatabaseCode.html</a><br />
<a href="http://www.buunguyen.net/blog/unit-testing-the-data-access-layer.html" target="_blank">http://www.buunguyen.net/blog/unit-testing-the-data-access-layer.html</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Mock' rel='tag' target='_blank'>Mock</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a>, <a class='technorati-link' href='http://technorati.com/tag/Testing' rel='tag' target='_blank'>Testing</a>, <a class='technorati-link' href='http://technorati.com/tag/Unit+testing' rel='tag' target='_blank'>Unit testing</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/ramblings-should-unit-tests-talk-to-a-data-source/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Link dump 11/3</title>
		<link>http://www.turnleafdesign.com/link-dump-113</link>
		<comments>http://www.turnleafdesign.com/link-dump-113#comments</comments>
		<pubDate>Tue, 03 Nov 2009 06:07:01 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Link Dump]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=275</guid>
		<description><![CDATA[http://www.developerart.com – A new blog like my own. While not a whole lot yet, the content that is on his site is of high quality.
Kind of a smallish link dump I know. I plan on getting some new articles posted this week, namely an update to my TDD article I posted last Monday. So check [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Flink-dump-113"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Flink-dump-113" height="61" width="51" /></a></div><p><a href="http://www.developerart.com" target="_blank">http://www.developerart.com</a> – A new blog like my own. While not a whole lot yet, the content that is on his site is of high quality.</p>
<p>Kind of a smallish link dump I know. I plan on getting some new articles posted this week, namely an update to my TDD article I posted last Monday. So check back soon.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x15, created 9/22/09 */
google_ad_slot = "6237316105";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/link-dump-113/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Intro into Test Driven Development with JUnit4</title>
		<link>http://www.turnleafdesign.com/an-intro-into-test-driven-development-with-junit4</link>
		<comments>http://www.turnleafdesign.com/an-intro-into-test-driven-development-with-junit4#comments</comments>
		<pubDate>Tue, 27 Oct 2009 04:26:16 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unit]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=260</guid>
		<description><![CDATA[Please read the technical guide before starting this tutorial.
This article will mark the first of a long-term series covering professional software development. For the lowdown on this project check out this article. Be sure to give me your feedback as it will be vital in helping me develop better tutorials in the future.
Test driven development [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fan-intro-into-test-driven-development-with-junit4"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fan-intro-into-test-driven-development-with-junit4" height="61" width="51" /></a></div><p>Please read the <a href="http://www.turnleafdesign.com/?page_id=263" target="_blank">technical guide </a>before starting this tutorial.</p>
<p>This article will mark the first of a long-term series covering professional software development. For the lowdown on this project check out <a href="http://www.turnleafdesign.com/?p=266" target="_blank">this article</a>. Be sure to give me your feedback as it will be vital in helping me develop better tutorials in the future.</p>
<p>Test driven development seemed like a natural choice as a lead off to my series of tutorials as I had to explain why I am writing all these tests. It is also a very good development methodology that will actually save a lot of time by reducing the amount of time spent debugging. For this tutorial and the entire project, I will be using Junit4. For a synopsis on test driven development you can check out the wikipedia article <a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">here</a>. If you need a brief refresher on JUnit you can read my tutorial <a href="http://www.turnleafdesign.com/?p=145" target="_blank">here</a> (written in Junit3).<br />
<span id="more-260"></span><br />
The goal of this tutorial, from a project stand point, is to get the connection to our (MySQL) database working. To do this we are going to need several things: a MySQL server, a client to access the server, and a JDBC driver to allow our application to access the server.</p>
<p>The MySQL server:<br />
I will be using MySQL server 5.0 for this project, you can download it <a href="http://dev.mysql.com/downloads/mysql/5.0.html#downloads" target="_blank">here</a>. The tutorial instructions will be based upon the user being “root,” the password “turnleaf,” and the url “http://localhost:3306.”</p>
<p>The MySQL client:<br />
I will be using <a href="http://www.heidisql.com/download.php" target="_blank">HeidiSQL</a> to query and manipulate the database. Once the client is installed import this sql file to setup the database and table.</p>
<p>The JDBC Driver:<br />
You can download the JDBC driver <a href="http://dev.mysql.com/downloads/connector/j/5.0.html" target="_blank">here</a>. Please include it on your projects build path.</p>
<p>To begin this project, please checkout revision 7 from the code repository.</p>
<p>Once you have downloaded the project go ahead and navigate around it a little bit. You will notice I already have several source files; Forecast, ForecastDao, and ForecastDaoImpl. Forecast is a bean for holding all weather information for a specific date (this bean will likely be modified in the future). We also have ForecastDao which is an interface and ForecastDaoImpl which implements ForecastDao. I plan on covering interfaces in more detail in the future, but if you are unfamiliar with the concept you can read a brief description <a href="http://java.sun.com/docs/books/tutorial/java/concepts/interface.html" target="_blank">here</a>.</p>
<p>Update to revision 8 and you will see I added in my first unit test. The unit test is checking to see if I get any returns when I run getAllForecasts(). Here is the code:</p>
<pre name="code" class="java">
@Test

public void testGetAllForecasts(){

List&lt;Forecast&gt; forecasts = dao.getAllForecasts();

Assert.assertTrue(!forecasts.isEmpty());

}
</pre>
<p>If you attempt to run the test you should get a null point error when you attempt to check if forecasts is empty. If you look at the implementation of getAllForecasts() in ForecastDaoImpl it is obvious why, getAllForecasts() is returning null. This is one of the tenants of TDD, write fail first tests.</p>
<p>Go ahead and update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/9/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 9</a>. You will see I have added connection information to getAllForecasts(). Don't worry about it being messy we will refactor it later. Go ahead and run the unit test again. You will still fail, but in the console shows we are successfully connecting to the database.</p>
<p>Update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/10/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 10</a>. I have made several more changes, most noticeably if you run the test it should now pass! (If not check to make sure your database is setup correctly) Before we start celebrating too much, lets actually check the contents of the list to make sure we are getting the right data. Update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/11/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 11</a>, I have added a few more checks, and we are in fact getting the correct data, awesome!</p>
<p><strong>Author note:</strong> For some dumb reason when you create a new Junit4 test class in Eclipse it does not automatically inherit TestClass. Anyways I inherit that class now so you can just do assertEquals(expected, actual) instead of Assert.assertEquals(expected, actual).<br />
If you checked the implementation of getAllForecasts() before updating to revision 10, you will noticed I am only setting the date value of my forecast bean. My new tests initially failed (I originally thought I was setting all fields), thus the importance of not only writing unit tests, but writing good unit tests.</p>
<p>So now it is time to start refactoring. With our unit test we now have a good baseline of how the system should behave. This way when we are making changes we can be confident we are not breaking the system because we will be getting the same output for the same input.</p>
<p>Update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/13/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 13</a>. You will see that I have created the getConnection() method and that contains the database connection logic.</p>
<pre name="code" class="java">
private Connection getConnection() {

Connection conn;

try {

String userName = "root";

String password = "turnleaf";

String url = "jdbc:mysql://localhost/weather";

Class.forName("com.mysql.jdbc.Driver").newInstance();

conn = (Connection) DriverManager.getConnection(url, userName,

password);

} catch (Exception e) {

throw new DataAccessException(e);

}

return conn;

}
</pre>
<p>I pretty much just copied and pasted (one of the VERY few times copying and pasting is ok) the connection logic into this method. The most noticeable change I made is in the catch clause. There is a bunch of different exceptions that could be thrown when attempting to connect to the database, sine they all end in the same scenario, unable to connect to the database, I kept the same generic catch(Exception). However you should never just throw exception so I created my own custom exception called DataAccessException. Inside the super(Throwable) constructor I set it up to add a message stating “Unable to connect to data source,” I also have it extend RunTimeException turning it into an <a href="http://java.sun.com/docs/books/tutorial/essential/exceptions/runtime.html" target="_blank">unchecked exception</a>.</p>
<p><strong>***Philosophical warning***</strong><br />
This is philosophical decision. As projects become more complex it can become difficult to catch and/or throw an exception at every level. However, you should catch the exception at some point to give the user a reasonable error message and let you know when the application is throwing exceptions. There is another school of thought that all exceptions should be checked as it lets a developer know what exceptions and method could throw, and other various reasons.</p>
<p>Between the message and the name of the exception, it should be pretty clear that when this exception is thrown it means the application failed to connect to the database. Running the unit test we will see everything is still passing so we can be confidant that the refactoring did not break the system.</p>
<p>Update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/14/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 14</a> and you will see I refactored out the closing of the connection. Exceptions should never be ignored, personally I would say being unable to close a database connection could be a major issue. So instead of catching Exception I changed it to only catch SQLException and throw the DataAccessException except I will have my own message in their stating the connection could not be closed. Here is what the closeConnection() method looks like:</p>
<pre name="code" class="java">
private void closeConnection(Connection conn) {

if (conn != null) {

try {

conn.close();

} catch (SQLException e) {

throw new DataAccessException("Could not close connection", e);

}

}

}
</pre>
<p>From what it originally looked like, the getAllForecast() method is starting to look a lot better as well as the ForecastDaoImpl class in general. Adding new methods that retrieve data from the database will be easier as all I have to do to get a connection is call getConnection() and to close it closeConnection(Connection). On top of that if I need to change my database connection information I only have to do it in one area.</p>
<p>Despite this refactoring, this is hardly an ideal data access layer. With the test unit already created go ahead and continue to refactor getAllForecast(), a good place to start would be how I create a new Forecast object. I would also suggest adding some new functionality yourself a couple of examples might be; getForecastByDate(Date) or getForecastByCondition(String condition) (Remember create unit tests!). I will continue to refactor and update this work myself. So you can run updates and compare your work to my own.</p>
<p>Addendum and thanks:<br />
Because I am an idiot I couldn't remember how to write a JDBC connection. My initial connection method is predominantly based off of the code in this article: <a href="http://www.kitebird.com/articles/jdbc.html" target="_blank">http://www.kitebird.com/articles/jdbc.html</a><br />
For being able to go to a specific revision with a url:<br />
<a href="http://www.perhammer.com/2008/07/subversion-in-url-revision-browsing.html" target="_blank">http://www.perhammer.com/2008/07/subversion-in-url-revision-browsing.html</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x15, created 9/22/09 */
google_ad_slot = "6237316105";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_blank'>Java</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a>, <a class='technorati-link' href='http://technorati.com/tag/Unit' rel='tag' target='_blank'>Unit</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/an-intro-into-test-driven-development-with-junit4/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The start of a long journey</title>
		<link>http://www.turnleafdesign.com/the-start-of-a-long-journey</link>
		<comments>http://www.turnleafdesign.com/the-start-of-a-long-journey#comments</comments>
		<pubDate>Tue, 27 Oct 2009 04:03:22 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=266</guid>
		<description><![CDATA[A couple of weeks ago I posted about my ideas for the future of this site. Well today I start making good on those lofty promises. I will be posting my first tutorial, which will cover test driven development, shortly. Before I do that I want to give a bit of an explanation of this [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fthe-start-of-a-long-journey"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fthe-start-of-a-long-journey" height="61" width="51" /></a></div><p>A couple of weeks ago I posted about my ideas for the future of <a href="http://www.turnleafdesign.com/?p=214" target="_blank">this site</a>. Well today I start making good on those lofty promises. I will be posting my first tutorial, which will cover test driven development, shortly. Before I do that I want to give a bit of an explanation of this project, why I am doing it, what I hope to accomplish, a few other thoughts, and finally some technical notes.<span id="more-266"></span></p>
<h3>The what</h3>
<p>As I said in my previous post, this project's main goal is to check to see how accurate meteorologists really are with their predictions. NOAA offers a <a href="http://www.nws.noaa.gov/xml/">web service</a> for checking forecast information and I will be using that to gather my data. Just following the exact requirements of those project will give plenty of opportunities to learn new things, but I also intend to meander around a bit so we can learn a lot more. So when I start adding user sign in and other seemingly odd/unnecessary features, now you know why.</p>
<h3>The why</h3>
<p>I intend for this project to serve a duo purpose, to teach others and to learn a thing or two myself. One of my main goals with this site is to help teach other developers. There where many important subjects that I did not fully grasp in my early career and it really held me back. Luckily I was given the opportunity to learn from my mistakes as well as those around me. I hope to repay some of this debt by helping others.</p>
<p>There is a lot to software development,<strong> a lot</strong>. Sometimes it is hard to know where to begin, but it is said necessity is the mother of invention and I hope both intentionally and unintentionally this project forces me to learn things as it is the only way to (effectively) solve a problem.</p>
<h3>A few words on practices</h3>
<p>Occasionally there will be bad practices in this project. It will be a mixture of both intentional and unintentional. I plan on making example of why those practices are so bad, and sometimes the only effective way to do so is by actually showing the <a href="http://martinfowler.com/bliki/TechnicalDebt.html" target="_blank">technical debt</a> taken on by those practices. When I do intentionally make a bad design choice, I plan on explicitly stating so and I will also show how to fix the issues resulting from those practices.</p>
<p>That said, I am both human and a junior developer. I am going to make mistakes, lots of them. You don't need to burn me at the stake. If you see a problem in my code, please leave a comment and if possible offer a solution. If I think you are correct I will make amendments to my articles to correct any problems.</p>
<p>There will be philosophical differences. When I am cognizant of differing views points on a subject, I will state my design choice is philosophical. If you are of an opposing view please speak up and say why your choice is better, but it has to be something more substantive than “you are wrong.”</p>
<p>Lastly all practices are guidelines. For every good, great, or best practice, there is going to be a few examples out there that contradict the practice. Thus they are practices and not rules. Understand that there is no possible way I could be familiar with every person's business domain or systems the you work on or use. I have to write with a certain degree of generality.</p>
<h3>I need you</h3>
<p>I can only fix what I know to be broken. If you see a problem, want me to cover something in more detail, or anything else, please let me know. Your feedback is absolutely vital in the process of making this site and the content I publish here better. I will do the best I can to self correct, but I can only do so much alone.</p>
<h3>Technical notes</h3>
<p>All coding work will be done utilizing Eclipse 3.5 (Galileo), you can download it <a href="http://www.eclipse.org/downloads/" target="_blank">here</a>. I will be using subclipse as my primary version control client. If you need help using subclipse check out my <a href="http://www.turnleafdesign.com/?tag=svn" target="_blank">subclipse primer</a>. I will be utilizing several other technologies as this project because more advanced. As I do I'll let you know what I am using and where to get it. Hopefully in the future I will be able to do this all automatically, though network/financial issues may prevent this.</p>
<p>I'm still contemplating on how to get a live version of this project hosted. I think I may be able to use <a href="http://code.google.com/appengine/" target="_blank">Google's app engine</a>, but I am still unsure if it will fully mesh with the goals of this project. If you know of free or cheap Java hosting let me know.</p>
<p>This project is published under the MIT license. Which as far as my understanding goes allows you to do pretty much anything with the source code. Rather that be the case or not you do have my permission to use the source code in this project, at least the code I personally write, to whatever purposes you see fit (I'd prefer good). Attribute me if you want, I don't really care.</p>
<p>Well anyways I hope you like this series of tutorials. It's going to be a long, but I hope a very fun and enlightening, journey.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/the-start-of-a-long-journey/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comments are a sign of bad code and I am not sorry for saying it</title>
		<link>http://www.turnleafdesign.com/comments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it</link>
		<comments>http://www.turnleafdesign.com/comments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it#comments</comments>
		<pubDate>Fri, 23 Oct 2009 05:25:36 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=255</guid>
		<description><![CDATA[In my recent article, 8 signs your code sucks, one of my signs of bad code is: “You need to use comments to explain the code.” I have since taken a lot of flak for suggesting this and I want to clarify my point and why I am not backing down.
Not javadoc - I am [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fcomments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fcomments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it" height="61" width="51" /></a></div><p>In my recent article, <a href="http://www.turnleafdesign.com/?p=246" target="_blank">8 signs your code sucks</a>, one of my signs of bad code is: “You need to use comments to explain the code.” I have since taken a lot of flak for suggesting this and I want to clarify my point and why I am not backing down.</p>
<p><strong>Not javadoc </strong>- I am NOT referring to <a href="http://en.wikipedia.org/wiki/Javadoc" target="_blank">Javadoc</a> or its equivalents in other languages. I absolutely do agree that a method or class should have accompanying documentation at its declaration stating its purpose and its inputs and/or outputs.<br />
<span id="more-255"></span><br />
<strong>Comments are not bad, the code is</strong> – I'm not suggesting to forgo the use of comments, but that they are only band-aids. When you don't have time to properly write a piece of code; do it the “messy” way, write a comment and give it a TODO as a reminder to go back and fix it later.</p>
<p><strong>Comments make code accessible </strong>- Code should not be written to the level of the dumbest developer, the dumbest developer should be brought to the level of the code (though I want to reiterate good code should be easily readable). If a developer is unwilling or unable to meet or at least understand the rest of the team's coding standards, then questions should be asked rather you want that developer to understand the code at all.</p>
<p><strong>They are more like guidelines</strong> – When it comes to design patterns there are no rules. From day one we are taught goto statements are evil and should never be used, but <a href="http://kerneltrap.org/node/553/2131" target="_blank">there is even a time and place for them</a>. There may be rare occasions when you have to write a comment to explain a piece of code, just like you may need to use a goto to simplify the code, but both occasions are rare and when encountered in code should be scrutinized.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/comments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Thanks for the hits!</title>
		<link>http://www.turnleafdesign.com/thanks-for-the-hits</link>
		<comments>http://www.turnleafdesign.com/thanks-for-the-hits#comments</comments>
		<pubDate>Fri, 23 Oct 2009 03:30:15 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=252</guid>
		<description><![CDATA[My blog passed a major milestone today, I finally eclipsed 1,000 visitors in a single day! I want to say thanks to everybody who has visited this site and I hope you find it useful. I have a lot of big ideas for the future so be sure to check back again sometime. Help support [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fthanks-for-the-hits"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fthanks-for-the-hits" height="61" width="51" /></a></div><p>My blog passed a major milestone today, I finally eclipsed 1,000 visitors in a single day! I want to say thanks to everybody who has visited this site and I hope you find it useful. I have a lot of <a href="http://www.turnleafdesign.com/?p=214" target="_blank">big ideas for the future</a> so be sure to check back again sometime. Help support Turnleaf Design by leaving comments, or sharing posts with friends, colleague, or on social sites. Thanks again!</p>

<!-- start wp-tags-to-technorati 1.01 -->

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/thanks-for-the-hits/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>8 Signs your code sucks</title>
		<link>http://www.turnleafdesign.com/8-signs-your-code-sucks</link>
		<comments>http://www.turnleafdesign.com/8-signs-your-code-sucks#comments</comments>
		<pubDate>Thu, 22 Oct 2009 03:58:57 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=246</guid>
		<description><![CDATA[As a wide eyed junior developer when I first began working on large projects I simply accepted that it is difficult to fix bugs or find where an action is being executed. If only I knew then what I know now, I would had saved myself hours of frustration. The first step to writing good [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2F8-signs-your-code-sucks"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2F8-signs-your-code-sucks" height="61" width="51" /></a></div><p>As a wide eyed junior developer when I first began working on large projects I simply accepted that it is difficult to fix bugs or find where an action is being executed. If only I knew then what I know now, I would had saved myself hours of frustration. The first step to writing good code is accepting the code you write (or work on) is crap, but sometimes you need to know what to look for. Here are some signs that your code sucks.</p>
<p><strong>A method is larger than the screen </strong>– A method should only perform one specific task. A method should not contain the logic code to determine if the username field contains data, is valid, and that user exists. If a method is too large to fit within a single screen, that is a (very) good sign it is doing too much.<br />
<span id="more-246"></span><br />
<strong>You are reusing variables </strong>– Unless you are working on embedded devices, memory is cheap. Don't be a memory scrooge and knee cap code maintainability, which in nearly all instances trumps performance, by reusing the same variable for multiple uses.</p>
<p><strong>You are directly accessing the request/session </strong>– It not only makes writing unit tests (much) harder, but it is also difficult to know what data the application has access to. All data should be taken out of the session/request and stored in a bean. A bean, through its getters and setters, creates a “contract” of what data the application has access to, which greatly helps with code maintainability.</p>
<p><strong>You need to use comments to explain the code</strong> – Code should be able to explain itself and should be in a format that is easily readable. If you find yourself needing to explain what your code is doing then you may want to look into rewriting that code.<br />
<strong>EDIT:</strong> This is not referring to using comments (e.g. javadoc) to explain the purpose of a method/class and its inputs and outputs.</p>
<p><strong>An exception's stack trace doesn't return the original problem</strong> -  You should never “eat” an exception, that is catch an exception, but not print its stack trace. How can a bug be fixed if you don't even know where the bug is occurring?</p>
<p><strong>Your code is a mud ball</strong> – Just the name sounds ugly. A “mud ball” is when there is little separation between the layers or <a href="http://en.wikipedia.org/wiki/Concern_(computer_science)" target="_blank">concerns</a> of an application. Code should be modular allowing for ease of reusability and modifiability. Anything concerning the user interface happens in the view, program flow and usually data validation is the domain of the controller, handling business logic is the model's job, and only the model should be interacting with the data access layer.</p>
<p><strong>It is hard to write a unit test</strong> – If you find a bug or write a new piece of code and it takes you more than a few minutes to write a unit test then that portion of code is handling too complex of a task.</p>
<p><strong>The author is <a href="http://www.turnleafdesign.com/?page_id=2" target="_blank">Billy Korando</a></strong> – Wait what?!</p>
<p>Add your own experiences or signs for dealing with sucky code.</p>
<p><strong>UPDATE:</strong> There are differing opinions on my signs, since I am but a mere "grasshopper" I maybe wrong. Anyways <a href="http://www.reddit.com/r/learnprogramming/comments/9wp2a/8_signs_your_code_sucks/c0esu86" target="_blank">check it out and make up your own mind.</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x15, created 9/22/09 */
google_ad_slot = "6237316105";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/8-signs-your-code-sucks/feed</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>12 Tips to make you more productive using Eclipse</title>
		<link>http://www.turnleafdesign.com/12-tips-to-make-you-more-productive-using-eclipse</link>
		<comments>http://www.turnleafdesign.com/12-tips-to-make-you-more-productive-using-eclipse#comments</comments>
		<pubDate>Tue, 20 Oct 2009 04:28:16 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Noob Corner]]></category>
		<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=240</guid>
		<description><![CDATA[Integrated development environments make developing application fair easier. They highlight syntax, let you know if you have a compilation error, and allow you to step through your code among so many other things. Like all IDEs Eclipse has a bunch of little shortcuts and tools that can make your life a lot easier, I've compiled [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2F12-tips-to-make-you-more-productive-using-eclipse"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2F12-tips-to-make-you-more-productive-using-eclipse" height="61" width="51" /></a></div><p>Integrated development environments make developing application fair easier. They highlight syntax, let you know if you have a compilation error, and allow you to step through your code among so many other things. Like all IDEs Eclipse has a bunch of little shortcuts and tools that can make your life a lot easier, I've compiled a list of several that I use on a daily basis:</p>
<p><strong>1. Auto-complete</strong> – Eclipse has an auto-complete feature that can be accessed with ctrl + space. When clicked a small pop-up box is displayed with a list of context sensitive suggestions. If there is only one possibility then Eclipse completes it for you.<br />
<span id="more-240"></span><br />
<strong>2. Quickly format your code</strong> – Code that is being heavily modified can quickly become an ugly sight. Without proper indention it can become extremely difficult to determine what is happening in code. Code can be quickly formatted using the shortcut: Ctrl + shift + F. You can even setup your own style rules by going to: Project&gt;Preferences&gt;Java Code Style&gt;Formatter, check “enable project specific settings” edit the profile and then save it under a new name.</p>
<p><strong>3. Get rid of unnecessary code </strong>– Heavily worked on projects that aren't maintained well can quickly build up a bunch of unnecessary imports, casts, among other common easily detectable coding mistakes. Quickly remove these mistakes by running a code clean up. Right click on your project folder&gt;source&gt;clean up. Like the code formatter you can also customize your code clean up.</p>
<p><strong>4. Go to declaration</strong> – Want to know where that method, variable, or class is declared? This can easily be done by holding down ctrl and then clicking on the reference.</p>
<p><strong>5. Find all references</strong> – If you need to find all the references for a method, variable, or class highlight the desired reference right click&gt;reference and select the desired search scope.</p>
<p><strong>6. Quickly select groups of characters</strong> – Need to delete an entire string, or everything within a method's argument declaration? Select the enclosing character (e.g. the “ or "(" respectively), this will select everything within the enclosing characters. This even works with the bodies of classes and methods. You can also select an entire line by triple clicking.</p>
<p><strong>7. Rename all instances </strong>– If you need to rename a method, variable, or class you can rename ever instance by highlighting a reference and pressing alt + shift + r an box will highlight the reference and you can rename it. Upon pressing enter all instance will be renamed in your project.</p>
<p><strong>8. Change a method signature</strong> – If you need to change any part of a methods signature; a methods name, its arguments, or return type, you can quickly make a change to all references of the method in the project by highlighting the method and pressing alt + shift + c a pop-up box will appear giving you options to change the method's signature.</p>
<p><strong>9. Automatically generate getters and setters</strong> – Writing getters and setters is for suckers. After you write out all the members of a class right click anywhere in the code screen&gt;source&gt;generate getters and setters. Select the variables you want to have getters and setters made for.</p>
<p><strong>10. Javadoc is a cinch</strong> – Eclipse makes writing Javadoc easy, just type “/**” and press eneter above a declaration. Eclipse automatically creates context sensitive Javadoc annotations (i.e. a methods parameters, or the author of a class). After that you only have to write out what the method actually does.</p>
<p><strong>11. Run a unit test</strong> – To run a unit test highlight the unit test and press alt + shift + x followed by t. You can also run a unit test in the debugger by pressing alt + shift + <span style="text-decoration: line-through;"></span>d followed by t.</p>
<p><strong>12. Comment out code</strong> – If you need to quickly comment out a chunk of code, highlight the corresponding lines and press ctrl + /, you can uncomment code the say way.</p>
<p>Chime in with your own Eclipse shortcuts.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/12-tips-to-make-you-more-productive-using-eclipse/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Taming of the Subversion, a SVN primer; part 3</title>
		<link>http://www.turnleafdesign.com/taming-of-the-subversion-a-svn-primer-part-3</link>
		<comments>http://www.turnleafdesign.com/taming-of-the-subversion-a-svn-primer-part-3#comments</comments>
		<pubDate>Sun, 18 Oct 2009 23:18:44 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Promised Land]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=237</guid>
		<description><![CDATA[In the third and final part to my SVN primer I will finish up with my day to day tasks and I will go over how to add SVN properties to your project. The first two parts can be found here: 1,  2.

More Terminology:
BASE – Refers to the most recent revision currently on your local [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Ftaming-of-the-subversion-a-svn-primer-part-3"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Ftaming-of-the-subversion-a-svn-primer-part-3" height="61" width="51" /></a></div><p>In the third and final part to my SVN primer I will finish up with my day to day tasks and I will go over how to add SVN properties to your project. The first two parts can be found here: <a href="http://www.turnleafdesign.com/?p=206" target="_blank">1</a>,  <a href="http://www.turnleafdesign.com/?p=230" target="_blank">2</a>.<br />
<span id="more-237"></span></p>
<h3>More Terminology:</h3>
<p><strong>BASE</strong> – Refers to the most recent revision currently on your local workspace.</p>
<h3>SVN Commands:</h3>
<p><strong>Comparing revisions </strong>– To see what changes have been made between two revisions a comparison can be run. The changes will be highlighted in gray, along with a box showing where in the older revision the change fits in. To compare revisions right click&gt;compare with and then select the option that best suits your needs.</p>
<p><strong>Merging</strong> – One of my least favorite of SVN commands, not because there is anything wrong with the merge feature (it's actually a great feature), but often when I run merges I have to deal with several conflicts, which I never find an enjoyable experience.  Anyways merging is a little trickier than you might think. Initially you might try merging the head of your branch (or whatever you are merging) with the head of your trunk, however this is incorrect. You actually need to merge the head of your branch with the revision of your trunk when you made the branch. This needs to be done because Subversion needs to know what actually has changed since the branch was made.</p>
<p><strong>Add</strong> – If there is a file that is not under version control, but you would like it to be include this can be done by right clicking on the file team&gt;add to version control</p>
<p><strong>Ignore</strong> – On the flip side, if  you do not want a file to be under version control right clicking&gt;team&gt;add to svn:ignore</p>
<p><strong>SVN properties</strong> – One really useful feature is svn properties. There are a wide assortment of svn properties that allow you to do things like add meta information to a file (author, revision number, last modified, etc.), include a tracking number and link to a bug tracking system, among many other options. The easiest way to setup properties using subclipse is through the “Show Properties” view. Right click on the SVNProject root folder and go to Team&gt;Show Properties. To add a property right click any where in the spreadsheet looking area and select “add property.” Select the desired property and setup the property's value. To setup the ability to use a bug tracking through svn we will need the following three properties added:</p>
<p style="text-align: center;"><img class="aligncenter" src="http://www.turnleafdesign.com/images/SVNProperties.png" alt="null" /></p>
<p><strong>Bugtraq:label</strong> - Displays a message next to the box where a developer would put the (comma separated) issue numbers.<br />
<strong>Bugtraq:url</strong> – This is the url to your bug tracking system. The “%BUGID%” appends the tracking numbered entered to its location in the url.<br />
B<strong>ugtraq:message</strong> - Displays a message in the history view. “%BUGID%” creates a link to the bug entered during the commit.</p>
<p>The end product, when you select a specific revision in the view history view in the bottom left you should get a message like “Tracker #s: 123” With "123" being a link tracker 123 in your bug tracking system. Eclipse has a built in browser, so when this link is clicked a browser window should open within Eclipse taking you to the issue.</p>
<p>This concludes my SVN primer. I hope anybody who reads this finds it useful. If you have any questions let me know. For more information on SVN you can check out these links:<br />
<a href="http://markphip.blogspot.com/ " target="_blank">http://markphip.blogspot.com/ </a>- The blog run by the director of subversion engineering at Collbanet<br />
<a href="http://svnbook.red-bean.com/en/1.5/index.html " target="_blank">http://svnbook.red-bean.com/en/1.5/index.html </a>– A huge guide on how to use Subversion<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x15, created 9/22/09 */
google_ad_slot = "6237316105";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Subversion' rel='tag' target='_blank'>Subversion</a>, <a class='technorati-link' href='http://technorati.com/tag/SVN' rel='tag' target='_blank'>SVN</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/taming-of-the-subversion-a-svn-primer-part-3/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
