Posts by Josh Swan
April 20, 2009 · by Josh Swan
Last week I showed how I setup for tools for behavior driven development on my MacBook Pro, Behavior Driven Development Environment. In this article I am going to go over how I setup a Rails application for behavior driven development.
Filed in: Team Member Blog
April 14, 2009 · by Josh Swan
I have had the opportunity this week to start working on an in house Ruby on Rails project. I am thrilled to doing more agile development that I can enjoy more. The last couple of years I have been doing a lot of Java work for companies that don’t practice a lot of agile techniques. I’m looking forward to the productivity of Rails again. While I am working on this project I plan on posting useful information that I learn or relearn along the way. Today I am going to explain how I setup my local BDD environment on my MacBook Pro OS X (Leopard) using Cucumber, RSpec, RCov, and “ZenTest”:http://www.zenspider.com/ZSS/Products/ZenTest/.
Filed in: Team Member Blog
March 22, 2009 · by Josh Swan
Today we deployed an application to our QA server and found we were getting an unusual error with hibernate. The error was:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
After debugging it for a while, I figured out it was occurring when the Drools rules engine was trying to access a lazily loaded hibernate field on one of the hibernate objects that was passed into it. At first I thought maybe it was some kind of multi-threading problem since that might cause the session to be unavailable in a separate thread from the main thread. After a bit a googling I found that answer. It turns out Drools uses shadow facts that results in the hibernate objects being copied in memory. Well the hibernate session for the objects cannot be copied so when the copies are used it appears the session is not set or has been closed. To fix the problem I disabled the shadow proxies with the following code:
RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setShadowProxy(false);
RuleBase ruleBase = RuleBaseFactory.newRuleBase(conf);
…
Shadow facts should only be disabled, however, if you follow the following rules.
- Your fact classes are immutable.
- Fact changes in the rules are done only in modify() blocks.
- Fact changes in your application are only done in modifyRetract() or modifyInsert.
You can find more information about shadow facts at this site: http://blog.athico.com/2008/02/shadow-facts-what-you-always-wanted-to.html.
Filed in: Team Member Blog
February 27, 2009 · by Josh Swan
This past year I have been doing a lot of database design work. One of the things we had to decide was how to handle look-up codes for things like states. I was told that we would be breaking out each type of code into its own table. Each look-up table has approximately these columns: code, name, description, enabled, created_date, and updated_date. At first I was indifferent to the design since it seemed fairly clean. I noticed it was using the code as the primary key instead of a surrogate key but I let it go.
We have been using these tables for months now and we have grown to have around 100 look-up tables. I’ve decided that maybe this design wasn’t the best way to go. Here is how I came to this conclusion:
1) When querying our main table we often have to retrieve the associated look-up tables as well. This has resulted in queries that have 20 – 50 table joins in them causing a noticeable decrease in database performance.
2) Creating an application to edit the data for a code was more complicated since we had to search across 100 tables instead of only a couple tables or even just one.
3) Given that we used the code as the primary key we had several situations where the code changed and we had to update the references across the database. I was talked into this one with “that code should never change” from the business. If a surrogate key had been used these code changes would not have been as painful as they were.
4) Since we are using hibernate for all our database tables we also had to create an additional 100 hibernate models for these tables. This added some significant development time to the project.
5) Another thing that bothered me is that we kept creating these tables and they all looked exactly the same. Kind of felt like copy and pasting the same bit of code over and over again.
For these reasons, I have decided to use a single table in the future for look-up codes similar to the structure above except adding a discriminator column called code_type or type. This type column can be used for grouping related codes together in the table and returning a specific code set. Couple of notes about this new design:
- If a system so many codes that the table actually gets so large that it starts to perform poorly it may be necessary to create a couple of tables. For most systems, however, this is an unlikely problem since most databases can handle millions of records in a table effectively and codes tables don’t tend to grow much.
- Queries may get a little interesting when you have to join multiple code groups in the same query. Just remember to use table and/or column aliases to help keep the joins clear.
Filed in: Team Member Blog
January 31, 2009 · by Josh Swan
Well I have been absent from my blog now for almost 2 years now. Almost since the day I started it. It just seems like there is always something more important I have to tackle first. I guess I am more developer than I thought. :-) Anyway, I will be making a second effort to blog about my technical interests and things I have learned.
Filed in: Team Member Blog
As I stated in my first post, I attended RailsConf for the first time this year. The conference was presented with the help of O’Reilly Media and Ruby Central. I thought they did a really nice job of keeping everything running smoothly. I thought the keynotes were the best part of RailsConf. There were keynotes by David Heinemeier Hansson, Avi Bryant, Ze Frank, Tim Bray, Jamis Buck and Michael Koziarski, and Dave Thomas. I found it interesting that many of the keynotes were not on the technical aspects of Rails but more on community and the evolution of software development.
Ze Frank’s keynote wasn’t even related directly to the software development field. It was more about how technology is now allowing people to express their creativity in new ways, such as through internet websites and tools. He talked about how anyone can now be an author and how that has created a huge influx of new creative material to the internet. He said people basically have three options when it comes to the authors of this new content.
1. You can ignore them.
2. You can try to control them.
3. You can shut them down.
I probably enjoyed his keynote the most because it was very, very funny and entertaining but also because it was really deep.
David Heinemeier Hansson’s keynote summerized what has happened over the last couple of years with Rails and then discussed where Rails is going with Rails 2.0. He said Rails 2.0 would focus onRESTful principles but would not be hugely different from what we have now. He also mentioned the following items that would be in 2.0 as well.
- Breakpoints will once again be working in Rails and will have some additional features such as the ability to step up and down in the strack.
- HTTP Performance will be improved using caching techniques for static files such as Javascript and CSS files.
- Query caching will be improved behind the scenes.
- There will be a mime type render that can be used in actions to render different view formats including custom ones.
- The environment.rb file will be split up and better organized.
- Migrations will be improved so the type information is not repeated over and over again in a migration.
- HTTP Authentications will be used more for computer API interactions.
- Rails will generate projects assuming they are going to use the MIT license. If you don’t want to use the MIT license for your project you will need to manually change it.
- Some functionality of Rails will be moved out to plugins based on how well it fits in with the Rails 2.0 core. Also, currently deprecated functionality will be removed.
Many of the speakers such as Dave Thomas talked about the importance of creating a great community presence around Rails and improving the image of the Rails community in the eyes of the world. Throughout the conference people were encouraged to donate money to charity, for example. This started with the Charity Tutorial put on by Pragmatic Studio(which I attended and was a great overview of Ruby and Rails). People interaction was reenforced by the speakers and through the Bird of a Feather sessions at the end of each day. People also gathered during the provided lunches for discussions and short coding sessions.
All in all the conference was really interesting and I came away from it with more motivation to take part in the community. I also learned some interesting stuff through the sessions, although I think this is an area that could be improved upon next year. I often found myself in sessions that had content that I already new or was much simpliar than I expected. It would have been nice if the sessions were organized more by level of expertise or a similar rating next year. However, it was still incredible informative and I would highly recommend for others to attend next year. I would also highly recommend for novice Railers to take the Pragmatic Studio’s tutorial if they get the opportunity. It is a great way to quickly get up to speed with the basics of Ruby and Rails.
Filed in: Team Member Blog ruby
I think the title of this blog posting is more than appropriate. It summarizes quite clearly that something new is on its way or has recently arrived. For me this week has been full of beginnings and firsts. One you may have guessed is the creation of my blog here at QWANtify. It is something I have been meaning to do for ohhhhh… about 6 months that just has not seemed to materialize. So what is different now, why create my blog now. Well, I have had an opportunity to go to an event that gave me something to write about. I went to RailsConf 2007. In fact it ended only 5 hours ago (it took that long to get the wireless in my room again :) ) and it was great. Since this is my first posting, however, I am not going to go into the details of the conference now. I will leave that for my following posts. Instead I will give you a little bit of an intro to me.
My name is Josh Swan and I am a software developer for a company in Madison, WI called QWANtify (that bit may be a bit obvious from my blogs name and url). I have been working in Java for around 5 years professionally but have a wider array of skills than just Java. For example, right now I am functioning more as a web service architect at work and outside of work I am building Ruby on Rails projects. Interests I have include agile development and project management practices, Ruby on Rails, Test First Development, Behavior Driven Development, application integration technologies, and problem solving in general. I’m the kind of person that if I’m trying to solve something I will have a hard time going to bed at night if I can’t figure out a solution. I also tend to be a bit of a jokester too, just to warn you. :-) I like to answer questions and help people when I can, so feel free to email me at josh.swan@qwantify.com or post comments to this blog.
Filed in: Team Member Blog