Posts Tagged ‘parttimedeveloper’

Part Time Developer No More!

Tuesday, May 6th, 2008

You read the headline correctly, I am going to be a “full time developer” now.  Last Wednesday I accepted a Java developer position.  Thursday I turned in my resignation, and after next week I’m no longer in the education field.  I’ll be working for what I feel is a great company doing what I enjoy doing.  Add in a great employment package and a great feeling of being wanted and I’m pretty excited.

The only downside is we’ll be moving up around 75 minutes to the north.  Still close enough to see family and friends now and then, but it does require uprooting the girly-wogs to a new school.  I’ve tried to avoid putting them through that, but this last job search pretty much convinced the wif-al unit and myself that what I’m looking for ain’t around here.  Even the original opportunity that started the Part Time Developer series was a couple hours to the south.  They’re handling it better than I thought they would, but we’re probably still going to end up spoiling them as much as we can.

So now has begun the fun of completing all those house projects that we’ve put off over the years.  Putting the house on the market.  Finding a nice house to move to.  All the unplanned expenses (COBRA - yuck!).  These are the times that try men’s souls.  Indeed it will be interesting.

So goodbye to management life (and good riddance!).  Goodbye to having to worrying about what everyone else is working on.  To doing tech support for third party software packages.  To the frustration of not doing what I so desperately want and need to do.  To my MacBook Pro (nearly the most painful of all :) ).  To the friends here that I’ve made.

But also goodbye to softball (I’m probably too old anyways).  Goodbye to childhood friends (and new ones).  To country small town living.  To the house that we’ve made home.

The wif-al unit, the girlywogs, and myself all say that it doesn’t seem like this is really happening.  We’ve begun working on the house, cleaning, boxing, etc.  We know that we will be moving once we find something and our house is sold, but it hasn’t really hit us.  I think that’s going to make the last time we drive out of our driveway that much harder.

It’s going to be a while before the house is on the market.  And until we find our new home.  I’ll be commuting for a while, but hopefully not too long.  It seems like we’re a long ways off, but I’m sure time will fly.

The Part Time Developer 6: Adding Hibernate to the Spring Tutorial

Saturday, March 22nd, 2008

The code formatting in this post is crap. I’ve been fighting with the WordPress code tag all day and I’m giving up. It doesn’t seem to work if I have blank lines and would reposition itself to not include the entire code fragment that I inserted. It also would do away with my tab spacing. So I’m done putting code in here until I can find out how I’m supposed to use it or find a plugin that works better.

So to document this for myself, I thought I’d add an additional section to the Developing a Spring Framework MVC application step-by-step tutuorial. So here’s part 7 of the tutorial: Swapping in Hibernate for Database Persistence.

I didn’t keep track of all the jars I added to the WEB-INF/lib directory, but here’s what I think I added. I probably missed something.
antlr-2.7.6.jar
asm.jar
asm-attrs.jar
c3p0-0.9.1.jar
cglib-2.1.3.jar
commons-collections-2.1.1.jar
commons-dbcp.jar
doms4j-1.6.1.jar
hibernate3.jar

Add the normal HibernateUtil.java to the springapp.repository package. This makes it easier to grab a session object when it’s needed.
package springapp.repository;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
private static SessionFactory sessionFactory;
static {
//Static initializers must catch and wrap any exceptions
try {
sessionFactory = new Configuration().configure()
.buildSessionFactory();
} catch (Throwable ex) {
System.out.println(ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
// Alternatively, you could look up in JNDI here
return sessionFactory;
}
public static void shutdown() {
// Close caches and connection pools
getSessionFactory().close();
}
}

Then we’ll create a Hibernate version of our ProductDao interface, HibernateProductDao.java.

package springapp.repository;
import java.util.List;
import org.hibernate.Session;
import springapp.domain.Product;
public class HibernateProductDao implements ProductDao {
public List
getProductList() {

Session sess = HibernateUtil.getSessionFactory().openSession();
List
products = sess.createQuery(”from Product”).list();
return products;
}
public void saveProduct(Product prod) {
Session sess = HibernateUtil.getSessionFactory().openSession();
sess.beginTransaction();
sess.saveOrUpdate(prod);
sess.getTransaction().commit();
}
}
Now add the necessary hibernate mapping and configuration files:
I added my table mapping file for the product table to war/WEB-INF/classes/springapp/domain directory. I don’t know if this would be the normal place you’d put it. It’s where it should be in a running system. In my previous experience we would put it next to the definition of the product class and then copy it here, but I don’t like having to remember to copy it down when you change it. I’m still looking for an elegant way for doing this.
Product.hbm.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE hibernate-mapping PUBLIC
“-//Hibernate/Hibernate Mapping DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”>
<hibernate-mapping>
<class name=”springapp.domain.Product” table=”products”>
<id name=”id” column=”id”>
<generator class=”native”/>
</id>
<property name=”description”/>
<property name=”price”/>
</class>
</hibernate-mapping>

Here’s the war/WEB-INF/classes/springapp/hibernate.cfg.xml configuration file
<!DOCTYPE hibernate-configuration SYSTEM
“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”>
<hibernate-configuration>
<session-factory><property name=”hibernate.connection.driver_class”>org.hsqldb.jdbcDriver</property>
<property name=”hibernate.connection.url”>jdbc:hsqldb:hsql://localhost</property>
<property name=”hibernate.connection.username”>sa</property>
<property name=”hibernate.dialect”>org.hibernate.dialect.HSQLDialect</property><!– Use the C3P0 connection pool provider –>
<property name=”hibernate.c3p0.min_size”>5</property>
<property name=”hibernate.c3p0.max_size”>20</property>
<property name=”hibernate.c3p0.timeout”>300</property>
<property name=”hibernate.c3p0.max_statements”>50</property>
<property name=”hibernate.c3p0.idle_test_period”>3000</property>

<!– Show and print nice SQL on stdout –>
<property name=”show_sql”>true</property>
<property name=”format_sql”>true</property>
<property name=”use_sql_comments”>true</property>

<!– List of XML mapping files –>
<mapping resource=”springapp/domain/Product.hbm.xml”/>
</session-factory>
</hibernate-configuration>

Now that all the groundwork as been put into place, the final piece of the puzzle is to use the power of Spring dependency injection and switch the class we’re using for our ProductDao implementation. Modify the applicationContext.xml file and comment out the previous productDao bean and add our new Hibernate version.<bean id=”productDao” class=”springapp.repository.HibernateProductDao”/>
<!–
<bean id=”productDao” class=”springapp.repository.JdbcProductDao”>
<property name=”dataSource” ref=”dataSource”/>
</bean>
–>
And that’s it. Rebuild, redeploy, reload, and browse to the application and things still work as before. Only now we’re using Hibernate for interacting with the database rather than using JDBC and Spring. That’s the power of these tools. If for some reason you need to switch implementations, it’s easy to do. Nothing in your plain Java objects is explicitly tied to a certain technology. By coding to interfaces, it’s easy to switch implementations.

The Part Time Developer 5: Spring

Sunday, March 16th, 2008

So now that I’m relatively back in the land of the healthy (except for some remaining congestion and constant runny nose) I figured I needed to come clean with what I’ve been working on. Before the big week of sickness I had started to reacquaint myself with the Spring Framework, which is now up to version 2.5 (I’m not sure but I think when I was using it it was like version 1.2 or something). I was working my way through a pretty nice little tutorial on Spring MVC. I continued it over lunches at work this week, and expanded on it this weekend.

Let’s get a little explanation of what this stuff is. Spring’s basic claim to fame (though not only) is dependency injection (or Inversion of Control). This allows you to “inject” things into your programming objects that they “depend” on. This is easiest to understand with an example. Most of this stuff involves programming to interfaces. As I’ve mentioned previously, interfaces are like placeholders in code that state the type of object it can be (I’m finding this leads to too many examples.) For example, an Animal interface could have an eat() method, and then I could have a Dog class that implements the eat() method. So then wherever an Animal is needed, I could use the Dog class since it implements the requirements of the Animal interface (namely the eat() method). (Sometime I’ll have to do a Programming terms for non-programmers series.)

So let’s say I’ve finally put some functionality in place in Pit where police show up and start fighting with fighters involved in a Black Pit fight. Let’s say I’m smart and I have a Fighter interface that spells out such things that Pit combatants can do, like attack(). Let’s say that my PitFighter class that is used most everywhere is the type of object that will represent my police. So both the fighters and the police are the same type of object.

Now let’s say down the line I decide I want to spice things up a bit and change the police normal fighter types to be ravenous bloodthirsty animals. I create a PitAnimalFighter class which implements the Fighter interface, maybe this prints out “GRRR!” in it’s attack() method.

Now that I have the new class, the hard way would be for me to go and change over to using that class everywhere in my code that I want to use the animal to represent the policing entity. The easiest way would be, if I had this all set up ahead of time, would be if I had a configuration file (in XML) that mapped the type of class that I wanted to use for the policing entity interface. So all I’d have to do would be to change it over to my new PitAnimalFighter. Spring would do the rest by injecting a class of that type in where it was needed.  It would also be simple to change back if I needed to.

I don’t know if this rambling would make any sense to anybody, but I understand it, which is the point of this. One thing Spring can suffer from is XML hell. You have all this wiring that you do in XML files for what injecting these class types and other dependencies that it’s not always readily apparent. It can get a little confusing. The hardest part for me is all the secret little hidden things (that I’m sure are in the documentation) that I would need to use during the tutorial. I don’t know if I’d be able to make a Spring MVC application from scratch without heavily looking back at examples.

Oh yeah, Spring MVC.  MVC stands for model/view/controller architecture.  It’s just getting big in the .NET world but has been in the Java space for a while.  It aims to separate the dependencies within your code on each other.  So for example you create a web application.  If you have the code that deals with displaying it on a web page tied too closely to how you get your data, it would be difficult for you to create a desktop version of the app.  By using MVC correctly, it should be easy to change your front end or back end, since they aren’t tied together.  Spring does all the tying together with its injection mechanism.

Today I added an extra step to the tutorial I ran through by adding Hibernate as my persistence framework in place of the Spring JDBC persistence.  This nicely illustrates how easy it is to switch this sort of mechanism when you code to interfaces and use dependency injection.  I plan to document this in my next installment.

I’m guessing once I do part 6 of this series I’m planning to work on my own application using Spring and Hibernate together.  While I’d like to move on to the next technology in my list, I need to delve more into these two main technologies since my having a good understanding of these is essential.

The Part Time Developer 4: Hibernate reverse engineering and JUnit4

Sunday, February 3rd, 2008

I was under the weather toward the end of the week, but I was still able to find some time for some professional development. I’m basically done with all the Hibernate tutorials that I have. I also looked into the reverse engineering offerings in Hibernate. Not that I’m going to need this sort of thing in the near future, but it’s good to know these things exist. It basically let’s you take a legacy (read existing) database and reverse engineer your Hibernate mapping files out of it. It seems like the basic mappings it comes up with wouldn’t be what you’d want to use, but you can set up a reverse engineering file to tell it how you want things. But if you’re going into that much depth, it almost seems like you should just build the mappings yourself. You can further help your legacy cause by then generating your Java entity classes from the mapping files. Pretty cool. It tempts me to come up with my DB schema, work on my mappings, and then generate my code from them. It wouldn’t be exactly the way I’d want them probably, but should be close. Though most of the time, I tend to come up with the data I need from the code I right.

I created a basic project template that I plan on using for new projects that I start. I can just copy the set of files in and modify them to suit what I’m doing. Basically, it’s just the folder structure, Ant build file, and some config files. But it should speed me along.

I don’t know what started me down the path, but I upgraded my project to JUnit4. They switched from making you inherit from JUnit classes to using annotations which allows you to indicate which functions are what. That part was pretty easy to figure out, but I couldn’t find a nice example on how you run the tests of multiple classes in a suite() like fashion. I finally pieced it together from a variety of sources and here’s how the JUnit4 suite type class would look.

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({ Test1.class, Test2.class, Test3.class })
public class AllTestSuite {
}

Within Eclipse, you can run the any of the classes as a JUnit test or run the suite to run them all that you’ve wired up. Eventually, I’ll get this added into Ant to automate things with a build.

So what’s left with Hibernate? Well, I feel I’ve done enough in the way of tutorials and reading. I’ve still got the documentation to read when I’m not at the laptop, and the Caveat Emptor application to dig through. But what I really need to do is to get some hands on and perform some of my own mappings, so I need to start my own project. Coming up with a meaningful project idea is always a problem for me. I need something that will enable to stretch the boundaries of the what I’m using to enable me to really get a practical understanding of it. I also need something that will hold my attention, something that I want to do. So that usually falls into some kind of gamey type development. Not any whiz-bang graphical masterpiece, but probably something more akin to the PBEM game that I’ve been running for the past 7 years for my friends. So I think my first stab at this will maybe be a space exploration/conquest game. As always, I dream of having it hosted on the web and allowing players to interact with the site to enter their orders for the turn, but most likely the first iteration or twelve would have turns emailed to me. Not that this may ever see the light of day, but who knows. If anybody knows of an internet host that you can run Tomcat hosted Java applications on, let me know.

Once I get comfortable wiring my classes up to my tables, it will definitely be time to move on to Spring. I’m hoping when I look back a couple weeks from now, that’s what I’m digging into.

The Part Time Developer 3: Hibernation Mode

Monday, January 28th, 2008

I got probably a good 3-5 hours in this weekend concentrating on working through another Hibernate tutorial, experimenting with the tutorials further, and looking through the documentation. I feel I already have a better understanding of the way things work than I did the last time around. This lazy loading stuff is pretty wild the way it works. For instance, say you’ve got a class that has a collection of objects that is stored in another table. Until you actually attempt to access, it hasn’t actually done a database lookup for that data yet. This is some pretty slick stuff, I may have to dwell into the source to see how it works. Gotta watch out for your session scope though. It took me some messing before I starting getting the whole detached stuff and reconnecting them back to a persistent state. I’m very happy that I’m figuring this stuff out on my own.

One thing that I haven’t found anywhere is what the best practice is for returning a list from a query (ex. .list() ) in Java 1.5+ in regards to generics. For instance if I do
List list = session.createQuery("from Person").list();
I get a warning that I should use a parameterized list. So if I switch it to this, which is how I’d prefer it
List<Person> list = session.createQuery("from Person").list();
it warns me that this is an unchecked conversion. Looking through the Caveat Emptor application, they suppress the unchecked warnings. So I’m guessing that’s the suggested practice. I may go hunting for an open source project that makes use of it to see what someone else does.

My plans from here are to continue looking through the core documentation, start exploring the Caveat Emptor app, and start coming up with my own mapping files for different situations.

The Part Time Developer 2: The Beginning

Thursday, January 24th, 2008

So here’s a recap of my first week of renewing my developer vows, so to speak.

The newest Java version for the Mac is version 1.5. It’s already present. From the little I’ve heard, 1.6 is available to developers through the developer preview. I think I have a developer account but 1.5 will be sufficient for the time being. I also heard something about the 1.6 only being a 64 bit version but I’ll have to look into that at some point.

Next up was getting the latest Eclipse version. Eclipse is free open source programming editor, mainly for Java I think but there’s plugins for other languages as well. I downloaded the 3.3 Europa EE version. Not that I plan on making use of J2EE (complicated enterprise stuff), it just comes with pretty much everything already under the hood. Watched a couple nice little training videos from the web site, and followed along with a Test Driven Development example. I’m really intrigued by TDD and JUnit. It seems like it would be quite a liberating thing to have all your stuff verified with tests you’ve written in a way that would allow you to rework/refactor the way you did things and still have faith that your end result is still the way it should be. My problem is sticking with writing the tests and also I inevitably come upon a situation where I struggle with how something should be tested. Also since most of what I write is just for tinkering around, sticking to writing tests first just doesn’t happen.

Next I grabbed Hibernate and started going through the nice little tutorial they have on the site. Hibernate is what is called an object relational mapper (ORM). It basically handles the mapping (saving and retrieving) of data to and from some sort of persistence layer (usually a database) to business object within the code. In Java, you create classes that have traits to describe the class and also methods that make the class do something. For example, if I make a Dog class, it could have certain traits (size, breed, tail length) and methods (wag tail). Hibernate aids in sending the traits (or member variables in programming-speak) to and from the database.

Back in my beginning days, we just wrote a class for each database table that we used and you just used that to save and retrieve data. These ORM’s are now the trendy way of doing things. This is my second time going through Hibernate and I’m still realizing things I hadn’t before. It changes the way you need to think about things.

I find myself switching between terms for an audience that knows nothing about programming and one that does. I don’t know if any non-programmers would really care about any of this, but I’d be happy to elaborate if needed.

So I went through the simple tutorial which created a simple console app and then a webapp. That involved installing Tomcat. Tomcat is an application server that allows the hosting of web applications with a Java backend. It’s all about servlets baby! Getting Tomcat set up on the Mac was a breeze! Pretty much all this stuff was a breeze. Seemed a lot smoother than when I did it on my Windows laptop in the past.

I found a sample chapter to Java Persistence with Hibernate and have been working through that while also perusing the Hibernate documentation. I’d like to really get a deeper understanding of Hibernate than I had in the past. I strayed off the tutorial path to try some things and ran into some issues. I want to figure out what’s going on with that. I downloaded a big shopping cart demo webapp using hibernate to dig into also. So I figure I could be in Hibernate for a while.

Oh, a pretty cool little thing that the tutorials used that I played with in the past but still think is the coolest thing is HSQLDB. This is a little database that you can use in projects that’s light as can be. You just throw a jar file in your project, tell Hibernate that you’re using it, start it up in a directory of your choice from the command line, and presto! you’ve got a nice little database to use. No elaborate install, just a jar file. Pretty cool! I haven’t done anything super intense with it, so I can’t vouch for robustness and those type of concerns, but it’s a handy little thing. Be great to use for small applications.

That’s about it for now. I don’t know what I’ll really be able to report on next week, as I said I’m probably going to be staying with Hibernate for a while. I will say that my productivity has waned over the last 2-3 days. I haven’t had much time to sit and concentrate on the sample chapter as much as I’d like. I need to schedule an hour here and there over this weekend to get back at it. I have tried to continue looking over the manual that i printed out to keep at least something happening. Plus I wanted to get this post written so I could move on also.

So that’s all I know for now.

The Part Time Developer 1: Explanation

Monday, January 21st, 2008

I apologize for the incoherence of my last post. I should no better than write one when there’s no one home.

I seem to be recovered now, so we’ll try not to ramble and be so boring from now on. Holy crap has it been cold! I’ve seen dollar bills sneaking through the cracks.

So I’ve been a bit preoccupied of late. My professional direction has been turning on a dime a bit lately. I had started to tinker around with VB.net, just to learn about what was different from the old VB6. I find it’s very easy to figure out and isn’t all that much of a jump from VB6. It also follows the .Net paradigm, so it’s pretty easy to go into from the C# side of the house also. I didn’t really find that it really gave me anything, or taught me anything that helps me grow as a developer. Now the disclaimer here is my observations are only based on a couple weeks of playing with it, but I feel that if needed I could do some relatively productive work in VB.net. The good is that it still allows you to put things together quickly which would be good for prototyping or simple projects. The bad for me was it’s so damn verbose. Defining a function or an object just seems like I’m typing so much. The function declarations are good in that they pretty much explicitly tell you what it overrides and things like that, but I guess it just seems like a lot of extra typing. I really think that’s good though. It’s so easy for future programmers looking at code to misinterpret it’s intent, so any extra help like that I give kudos to. For me though, coming from C++/Java/C# it seemed like I was slowed down having to make sure I had everything right. Don’t take this a bashing VB.net. I think it’s a good language, not my first choice, but I’d use it if I felt it was the best tool for the job.

So last Wednesday night I had a conversation with one my mentors that has helped mold me in my professional career.  He was telling me about a possible future opportunity and the technologies that would be involved.  A lot of them were ones that I had used in the past and was somewhat still familiar with, though definitely in need of a refresher.  So the new plan is to drop all the other hobbies that take so much of my time and reacquaint myself with these cool things.  Then hopefully, down the road I will have the opportunity to have a technical interview and get the chance to be a part of the opportunity.  It’s very exciting and also quite scary at the same time.

So the plan now is to make myself accountable to this blog that I’m staying focused and actually doing something.  I’m going to be using this “Part Time Developer” series of posts to chronicle what I’ve been looking into or planning to look into, problems I’ve run into, or really cool stuff that I’ve come across.  I’ll try to post something to this series at least once a week so you know that I’m still sticking with it.  That’s where I’m also asking you to help me remain accountable.  If you don’t see something for a while, please post a comment or send me an email calling me out to get my butt back in gear.  The way life is and just the way that I’m am, I’m sure things will pop up to divert me from this, but I’d really like to stick with this.  I’ve probably got a few months that I’ll be able to cram things in my head, so it’s important to stay focused.

I wanted to come up with a catchy name for this series, but all the cool ones were already taken in blogs.  For instance, I really liked The Shade Tree Developer, but then I realized I was already reading a blog called that.  So I dug deep for a name with meaning.  I haven’t really felt that I’ve been a full time developer since my first job out of college.  My second job was pretty much pure maintenance coding.  I didn’t really feel like I was developing anything really creative or new.  There were the few little projects here or there, but it was and would have always been maintenance in an ancient programming language.  In my current position, I’m pretty much the “Pointy Haired Manager” who is slowly losing touch with reality.  I was pitched to that I would have ample development opportunities in the newer things that I was interested in, but in reality, most of my time is tied into the management crap and another old system with ancient technologies.  Once again, a Part Time Developer at best.

So there you have it.  Hopefully, someday I’ll be able to start a series of posts called the Full Time Developer.  But until that time, it’s nose to the grind stone to continue to improve my skills and knowledge base on my own time.  I need to put out another post detailing what I’ve been working on since last Wednesday fateful conversation, but I think I’ve wasted enough time writing this up.  I also still want to post at least one unrelated post each week.  I’ve tried of late to use Six’s advice and go with smaller posts, but part of my soul is a writer, so it’s hard to just post little tidbits that I find interesting, other than just showing a link to some other blog that I’ve found interesting.

Well, that’s it.  I’m outta here.  One final note: let’s remember what today is.  It’s still amazing how many people are still annoying bigots and racists.