Wednesday, December 10, 2008

Gateway Groovy Users Recap

We had the first meeting of the Gateway Groovy Users tonight.  We didn't get quite the turnout that Alex Miller got with the Lambda Lounge, but what we lacked in numbers we made up for in left over food!  But seriously, the six of us had a great time.  We had a good discussion followed by a Groovy hacking session.   We also set the date for our next meeting.  Mark your calendars, Thursday, January 15th, we will be have an overview of Grails 1.1 ( which should be released by then) by an as yet undisclosed presenter.  Join the Google Group for updates.  

Also, this just in... The Chicago Groovy Users Group is having their first meeting on Tuesday, January 13th.  See their site www.cgug.org for more details.

Monday, December 8, 2008

GSP Page Without a Controller

Grails uses convention to serve up .gsp views using the name of an action in a controller.  For example, if you have a list action in a BookController Grails will try to load grails-app/views/book/list.gsp when this action is called.  But what if you want to use a .gsp but do not need or want a controller?  How can you call that page in Grails?  Like most things in Grails, there is more than one way to do this and they are all easy.

You can create the .gsp file in /grails-app/views or directly in the web-app directory.  I'd prefer the former since that's where all your other .gsp pages are going to be.  If you do either of these, then you can call the page like this:  myapp/mypage.gsp.  Or, if you nested the .gsp in a sub-directory, like this: myapp/mysubdir/mypage.gsp.  In any case you will have to include the .gsp extension and that's a bit ugly.  You can fix this with URL mapping by adding something like "/mypage"(view:"mypage") to the mappings block of your URLMapping class.  Now you can just call myapp/mypage and all is well.

With any of these approaches you have most of the power of GSP.  You can use the standard Grails GSP tags as well as any custom tags added to your project, you can include Groovy code in your pages (but please keep it to a minimum) and you have access to the objects that Grails makes available to all GSP pages, such as request, session and params.  What you don't have is a way to pass model data to your page or to perform other operations before your page is rendered.

Keep in mind that a controller action does not need to have any code in it.  So, you can always just create a controller with actions named the same as your .gsp file and then Grails will render it by convention.  If  your app includes other pages that are called from controllers then this will keep you app more consistent as well as making it easier to later add more functionality.    Maybe it's 6 of one and a half dozen of the other but at least it's nice to know that whichever way you go, Grails makes it easy.

Groovy User Groups

If you read the Community News in the December issue of GroovyMag, then you already know about the two new US Groovy User Groups.   The Chicago Groovy User Group is holding their first meeting in January and the Gateway Groovy Users will be holding our first meeting this week!  

December 10th at 6:30 pm in downtown St. Louis Contegix will be hosting the first meeting of the Gateway Groovy Users.  If you are in, or can get to, the St. Louis area and are interested in Groovy, Grails, Griffon, etc, please plan on joining us.  You can join the Google group to keep up to date -  http://groups.google.com/group/gateway-groovy   The website should be live soon, and that will be announced on the mailing list.  

This is an exciting time to be working in this fast growing and just plain fun technology.  I think we will be seeing many more Groovy/ Grails user groups in the near future.  If you know of one that is starting up in your area, drop me a line and I'll be happy to help get the word out.

Sunday, November 23, 2008

Final Day of Final No Fluff Just Stuff of 2008

At many conferences the last day is where the less gifted speakers or the less interesting topics get placed.  Not here!  Today was jam-packed with interesting presentations given by such notables as Brian Sletten, Andy Glover, Ken Sipe, David Geary and Stu Halloway.   This was actually the toughest day to choose which talks to go to.  I considered trying to run back and forth to try to catch more than one, but wisdom and laziness prevented that.  

So I started the day out with Andy Glover's "Groovin' builds Gant get any easier".  Andy did a great job of explaining what happens when you combine the utility of a feature-rich build system like Ant with the expressiveness and power of Groovy.  Anyone using Ant can benefit from Gant.  I can't see why anyone would stay with XML based Ant.   One thing that I always appreciate about Mr. Glover's talks is the way he draws even the most recalcitrant audience into his talks.  It's fun to see a master at work.

Speaking of masters, the next session I went to was Brian Sletten's "Restlet for the Weary".  I kept getting this feeling that a Restlet plugin for Grails might be a good thing.  I wonder if anyone has done that yet.  I don't think it's mere coincidence that you can rearrange the letters in Brian's name to spell "Brain".  

After another delicious lunch, we came to my favorite event, the expert panel.  The interaction between the speakers, audience and Jay Zimmerman, the host and moderator, is just hilarious, while being informative at the same time.  Ladies and gentlemen, don't try this at home.   

This might not have been a good idea, but I finished up the day in a two part session by Stu Halloway.  Stu has a series of 4 talks based on his recent blog posts titled Java.next.  The two sessions that he had this weekend were great and Stu is one of the smartest people I've ever met, but it was a bit much for my brain after three days.   In fact, I am still mentally digesting much of what he talked about.  I will have to do a follow up to this post.  But in the meantime, I highly recommend that you check out his blog.  Be sure to do it on an empty brain, so to speak.

Well that's it for No Fluff Just Stuff  2008.  I've said it before and I'll say it again.  These are, by far, the best technical events available.  If you haven't been to one, get to one.  If there isn't one near you that's no excuse.  There is a group of guys from the Netherlands that come to one each year.  Since they have to fly in anyway, they go to a different city each year.  So there's no excuse.  Check the schedule.  If you're in the northern midwest, the Milwaukee NFJS will be Feb. 27 - March 1, 2009.  See you there!

Saturday, November 22, 2008

NFJS Chicago Day Two was packed!

Today the schedule was packed with good sessions.  It was very difficult to choose which session to go to.  Though I found out something- if you wait too long to decide the decision gets easier as some of the rooms fill up! 

After a great breakfast and discussion with Mark Richards and a preview of the material for the 10th anniversary meeting of NEJUG (if you live near Boston don't miss the January meeting), I went to Jared Richardson's Distributed Agile talk.  Jared' s high energy and upbeat outlook are great for getting you going in the morning.  Since I am currently working on a distributed team, this was a very timely session.  

Next I caught Alex Miller's tour of Terracotta.  That's an impressive piece of software!  I am going to have to look into it more.  It seems like something you should have to pay a huge amount of money for but it's free and open source.  Wow!  

After lunch where I unsuccessfully attempted to get a CapJug table together (sorry guys!),  I went to hear Neal Ford's talk all about Regular Expressions, which I told him look to me like cartoon swearing.   As part of the talk he had a quiz where he showed different regex samples and we were supposed to guess what they were.  One of them turned out to not be a regular expression at all but real cartoon swearing!  It was a very good discussion though and I think I'm starting to figure those things out.  Maybe between this talk and Ted Naleid's blog post, I'll finally be able to understand the next time a cartoon character cusses me out.

Next was Jeff Brown's Agile Test Driven Development with Groovy.  This is another that I had been to before but it's still got some good reminders in it and besides it was one of only two talks Jeff was giving and I had to go to one of them.  I was kind of bummed that Jeff didn't do any of his Grails talks this weekend.  In fact the whole show was a bit light on Grails goodness.  I'll have to note that on the conference eval :)  

Finally there was the JVM languages BOF with Scott Davis, Stu Halloway and Jeff Brown.  There was some very good discussion on various languages such as JRuby, Clojure, Scala and, of course, Groovy.  Groovy appeared to be the favorite of the audience here, but Clojure does sound pretty interesting.  Or should I say, Stu Halloway makes Clojure sound pretty interesting. Stu is working on a book on the topic which is in beta now.  I'll have to check it out.

All in all, a great day.  My head is swimming with ideas and starting to get a bit stuffed, but there's still one more day of the last No Fluff of the year. 

Friday, November 21, 2008

NFJS Chicago Day One Wrapup

While Scott Davis went on to blow everyone's mind with Groovy: The Red Pill, I snuck over to catch Neal Ford's Productive Programmer talk.  I have the book but it's tough to ask a book questions.  It was great and I picked up some very helpful tips that I can put to use on my recently acquired MacBook Pro.  (which is just awesome! by the way).  Next, while my son Ben was keeping an eye on Scott during Rapid Web Development with Grails and Ajax, I took in Nathaniel Schutta's talk on Improving Code Quality.  Nate gave a good recap of some of the best stuff out of Pragmatic Programmer with excellent anecdotes to drive the points home.  

Dinner was great as usual at a NoFluff.  No boxed lunches here!  I ran into some more Madisonians including a former co-worker from the State of Wisconsin.  It was great to hear that Grails is still making life better for them there.  But then Grails makes life better wherever it is tried.  :-)  

Unfortunately I missed Neal Ford's keynote due to an abundance of good conversations with some of the smartest people I know.   Time now to rest up.  Tomorrow's a big day.  Joining the speaker lineup is the one and only Stu Halloway as well as David Geary, David Hussman, and rounding out the St. Louis contingent, Jeff Brown and Ken Sipe (Alex Miller is also from St. Louis... must be something in the water over there).

Stay tuned for more from this, the last No Fluff Just Stuff of the year.

Chicago NFJS Day One

The Great Lakes Software Symposium just started.  I am sitting in Scott Davis' Groovy the Blue Pill talk.  I've heard it before but it's still good.  Scott's one of those guys who's just plain fun to listen to.   Also speaking today are Neal Ford, Mark Richards, Nathaniel Schutta, Jared Richardson and Alex Miller.  If only I could split myself into six parts.  I will try to mix it up a bit this time and see some of the sessions I haven't been to before.  We'll see.

Tonight's keynote should be good.  Neal Ford will be presenting his "Ancient Philosophers and Blowhard Jamborees"  

It's great to see several CapJug regulars here as well as many others from Madison.   We here in the northern Mid-West have the privilege of having the first NFJS (Milwaukee) and the last (Chicago) each year.  Although there are rumors that next year the tour will end in Colorado.  I may have to write my congressman about that one!




Tuesday, November 11, 2008

Congratulations to SpringSource!

It looks like SpringSource has their answer to JBoss Seam, and what an answer it is!  There are all kinds of aspects and angles to SpringSource's recently announced acquisition of G2One, the company behind Groovy and Grails, but this one struck me right off the bat.  

While Groovy will give new energy to the entire Spring portfolio, Grails, specifically, will help round out their competitive position vis a vis RedHat.  In recent demos at our Java User Group and at JavaOne, it appears that RedHat is using Seam to draw people into their whole platform.  And until now, SpringSource hasn't had a direct answer to that.   Not only will they have a framework that competes with Seam, but they will have one that blows it out of the water!  Don't get me wrong, Seam is heading in the right direction and with the eventual advent of JSF 2.0 it will get even better, but it is no where near as productive, effective or awesome as Grails.

Over the next several days, we will probably be hearing a lot about what this acquisition means to the future of Groovy and Grails.  I think, overall, it will be a major positive in that regard.  But, I think the real winner is SpringSource.   Congratulations to Rod Johnson and the gang for once again jumping ahead of the curve!

Uber-GenerateAll

With the big news today in the 2G community, this important tidbit might be left behind, but if you're watching the Grails Jira, and who isn't doing that?,  then you will have seen that Marcel Overdijk's Uber-Generate-All script will be included in Grails 1.04 due out later this week! (See GRAILS-2946)

Now, on a new Grails project, after creating a bunch of domain classes, maybe fiddling around with constraints and such with the scaffolding turned on, and generally getting things the way you want them, you can just give this command: grails generate-all "*" and all your controllers and views will be generated in one fell swoop!  How cool is that?  

This can be a timesaver in any project but it is really slick when giving demos of Grails, which is something we should all be doing more of  :)

So, in case this news doesn't make as big a splash in the 2G Community as the SpringSource acquisition, I just want to say "Thanks!" and "Good Job!" to Marcel for coming up with this idea and to Peter Ledbrook for getting it into Grails.  These guys are both Groovy Award winners and here's one more reason why!

Friday, October 31, 2008

Don't you hate blog posts about blogging?

My son, Ben, has been nagging me because I only had one blog post for the month of October. So, I started several different entries with topics ranging from the technical to the comical to the cynical. But none of them ever made it.

So, I started thinking about why I have such a hard time blogging. I was in need of a good excuse. Blogger Eric Burke had an interesting one. He said that Twitter had caused him to blog less. Another notable blogger, Michael Easter of CodeToJoy fame, was also of the opinion that Twitter was causing people to stop blogging. In fact, Michael wouldn't even go on Twitter because he was so sure that it was killing blogging. As a side note, I was thinking that somebody should write a Twitter client that would cross post your tweets to the comment section of a target blog. "Wheels down on your blog..." Where was I - oh yeah, Twitter as an excuse for not blogging. Well, I tried that one on for size but it didn't really fit since I hardly ever post on Twitter and when I do it's usually just to reply to someone else. So, I kept looking...

Then, I figured, well, I just started a new job and I don't have time to blog. That sounded like a reasonable reason, except that I'm currently working from home and avoiding 2 1/2 hours on the road each day. So I actually have more time than I've had for a while.

Then, the interesting thought hit me that I don't have anything interesting to blog about. That one didn't last long. With all that is going on in the 2G community and with the cool stuff I'm working on at Contegix, that was a poor excuse for an excuse. So, I'm still stuck inexcusably underblogged.

I'll keep on looking for that perfect excuse, but in the meantime I'll try to start blogging more. At least this one should get Ben off my back for a while. :)

Tuesday, October 7, 2008

Catching Up

So much has happened since I last put anything here. Where to begin...

Last month Jeff Brown spoke at the Capital Java User Group in Madison, WI. Jeff gave an awesome presentation on metaprogramming with Groovy. Jeff drew our biggest crowd yet and they loved it!

Ok, so this is not a photo of Jeff at CapJug.  It's Jeff at JavaOne 2008.  My picture of Jeff at CapJug didn't turn out.  But still...

Another important note on the September CapJug meeting, during our book give-away, with six excellent titles to choose from, Beginning Groovy and Grails, by Judd, Shingler & Nusairat, was the first choice again!  Second time in a row.  ( and unfortunately last since I don't have any more copies to give away... hey Apress!)

What next... I have been graciously given the opportunity to speak at the upcoming Groovy / Grails Experience which, unfortunately, has been postponed until February of next year.  I guess that gives me more time to work on my slides.  

Our family's newest Grails developer, Joshua Arthur, is doing well, growing fast and bringing lots of fun and excitement to our house.

And following up on the forlorn hope that I mentioned a while back.  The project is over 90% complete and should be "feature complete" by the end of this month.  It has been amazing to see the difference using Grails has made.  Not only are we on track to meet this unrealistic deadline but we were able to replace the existing JSF portion of the application with Grails.  So now we have a 100% Grails web application communicating with an EJB3 server.  If we had another month or so we could replace the EJB server too.  Wouldn't that be nice...


Although I am thrilled with the progress of this project and the statement it makes about Grails' productivity, I am even more thrilled that I will NOT be here to see the end of it.   This is my last week at this job.   After a day off at home and a weekend in Minnepolis for the NFJS conference there, I will be heading down to Saint Louis, MO to start my new job as a Grails Developer with Contegix!!!  (can you tell I'm excited?)   This is a dream job for me.  I've known about Contegix for a while now, as a sponsor of the NFJS series and as the host for the Groovy and Grails projects but then Matthew Porter gave that awesome keynote at the 2GX earlier this year and another at the NFJS / G2One meetup at JavaOne and I was totally impressed with their vision and committment to the 2G community specifically as well as to the broader open source community.   Besides, how cool is it to have a boss who's on Twitter?! 

I guess that's enough of an update for now.  Oh, one last thing.  This was under-reported so I'll post about it here.  My good friend and Groovy guy, Ken Kousen, put up a Grails Plugin Rating site.  It's a great way to see what plugins are there and to let everyone know which ones you like or don't.  Check it out.  

Thursday, September 11, 2008

Introducing Joshua Arthur Klein

On a personal note...  

Our family, which some might think is already a bit large, is growing again!  Joshua Arthur Klein was born on August 27th and has been fought over by his 12 siblings ever since.  It's tough to get his brothers and sisters to put him down long enough for him to get his studying in but we'll keep working on it.  Here's a picture of Joshua doing a little light reading:



We are so thankful to the Lord for this precious gift.  For more details and better pictures of Joshua you can check out our family blog: inkleinations.blogspot.com

Tuesday, August 26, 2008

BGG takes top honors at CapJug Meeting!

Last week at the August meeting of the Capital Java User Group, we had several excellent books to give away. Apress had sent us a copy of Beginning Groovy and Grails: From Novice to Professional, which Shawn Hartsock has dubbed "BGG". The Pragmatic Programmers sent us several of their recent titles (special thanks to Jared Richardson, author of one of my favorites: Ship It!) and we had one left from an earlier supply from O'Reilly.

When we have this many books to give out we like to treat it like a poll. So, I'll describe each of the books and then start drawing names. Each winner can take their pick from the books remaining. I am happy to announce that Beginning Groovy and Grails was the first pick! Congratulations to Christopher, Joseph and James! The CapJug pick of the months is quite an honor. We still have another copy to give away next month so we'll see if they can hold the record for a second month.

It is great to see the growing interest and excitement in Groovy and Grails at our Java User Group and I know that ours is not unique. Java User Groups all over the world are beginning to embrace the next generation of Java!

Thursday, August 14, 2008

Out of the Box

I'm beginning to think that the term "out of the box" has jumped the shark.

Anyone involved in software development has heard, read and probably used this term at one time or another. If you are involved in Groovy and Grails development you probably hear it all the time. I think Scott Davis holds the record for most uses of the term in a single presentation. In the book "Beginning Groovy and Grails: From Novice to Professional" (an excellent book, by the way, which I am almost done poring over and will write a review on soon), this term appears about a dozen times. It's easy to understand why since Grails does come with so many features and so many things that just work right out of... well you know what I mean.

So, you ask, what's the big deal? It's just plain wrong, that's what. It's difficult these days to find software or software development tools that were ever in a box to begin with. This is especially true with open source tools like Groovy and Grails. And I am worried that using this kind of inaccurate term is going to affect the way others look at our profession. I mean, as programmers we're supposed to be at least somewhat intelligent, but what are people going to think when they hear us talking about features and benefits coming out of a box that never existed?

I think this is a serious problem and not an easy one to solve. How else can we express the magic of things like GORM without using so many words that we get jaw cramps. Nonetheless, it's a problem that must be solved. If we do not want people to start lumping us in with the likes of used car salesmen or, even worse, lawyers, we had better get started looking for another, more accurate, term.

I think we can do it if we all work together and if we're willing to think outside the box.

Saturday, August 2, 2008

No Fluff in Green Bay

Well, I guess there might be fluff in Green Bay, but not here at the Radisson Hotel and Conference Center where the Northern Wisconsin Software Symposium is being held. Here there is no fluff just stuff and good stuff at that. There's just a bit less of it than usual. Green Bay is not a big town so the NWSS is not a big conference. It's kind of like a No Fluffette.

But what it lacks in quantity it more than makes up for in quality! The speaker lineup, though limited, is top notch. Yesterday (Fri) Jeff Brown was extolling the goodness that is Groovy and Grails, Venkat Subramaniam was covering Agile development, mocking for unit testing, and testing our Java kung fu, and capping off the lineup was Mark Richards who gave a two-fer on Enterprise messaging with JMS followed by an SOA class.

Then after we'd all finished up our steak dinners Venkat treated us to a brand new keynote that was eye-opening, inspiring and hilarious all at the same time.

So far, so good. Now to head downstairs for day two. Today Jared Richardson, Brian Sletten and, local boy, John Carnell will be joining us. It'll be great as long as my head doesn't explode.

Tuesday, July 15, 2008

Grails and EJB 3 Session Beans

A while back I was working on a Grails project that needed to integrate with an EJB2 application via session beans. So, when my current project had a similar need I thought 'piece of cake!'. As it happens it was a piece of cake that wasn't that easy to get at.

The problem came about because we were working with EJB3 this time. I had heard that it should work the same but it doesn't. I eventually found that it is still extremely easy to do (this is Grails we're talking about after all) it's just different.

For starters the Spring class that we used to connect to an EJB2 session bean, SimpleRemoteStatelessSessionProxyFactoryBean (I wonder if there is a TinyURL! for class names) was not working with EJB3. Several people on the forums said that it should, but our application did not believe them. It turns out that there is a Spring class that does work with EJB3 and it even has a shorter name! The JndiObjectFactoryBean is a general purpose Factory for looking up JNDI objects and making them available to other beans. The JndiObjectFactoryBean will even use the JndiTemplate that I had setup before, though I'll show it again so you don't have to hunt it down.

So now we should be in business. Except that it didn't work. When using the SimpleRemoteStatelessSessionProxyFactoryBean we could just use the Session Bean's simple interface name, which was also its JNDI name. That was not working with the JndiObjectFactoryBean. This critter wanted a fully qualified, certified and USDA approved JNDI name. The bummer here is that this is vendor specific. So the rest of this will work for BEAORACLE WebLogic but it might be completely different for your app server.

First we have to make sure that the EJB3 session bean has the mappedName attribute in the @Stateless annotation. (In our case ...mappedName="CoverageSession") That makes up the first part of the JNDI name. Then we add a # symbol and top it off with the fully qualified name of the Remote Interface. So we ended up with something like this for our JNDI name: CoverageSession#org.blah.app.ejb.session.ICoverageSessionRemote Once we gave it that mouthful it was happy.

Here I'll show a slightly modified version of our resources.groovy file:


beans = {
ejbJndi(org.springframework.jndi.JndiTemplate){
environment = [
"java.naming.factory.initial" : "weblogic.jndi.WLInitialContextFactory",
"java.naming.provider.url" : "t3://some.enterprise.server:7001"
"java.naming.security.principal" : "dave",
"java.naming.security.credentials" : "1234" ]}

coverageSession(org.springframework.jndi.JndiObjectFactoryBean){
jndiName = "CoverageSession#org.blah.app.ejb.session.ICoverageSessionRemote"
jndiTemplate = ref("ejbJndi")
}
}


Now we can inject the session bean into a Grails Service and we can call its methods to retrieve and save EJB3 entities from that portion of the application that was written before we began using Grails and it all just works and I'm happy!

I'm still hoping to be able to convert the entire application to Grails before we go production but in case we can't the ability to integrate Grails with all of our existing Java technologies is a big help.

Wednesday, June 11, 2008

Grails to the Rescue

Everyone in software development knows what a death march is but not as many are familiar with a forlorn hope. The term comes from the time when wars were fought over fortresses or walled cities. Cannons were used to make a breach in the walls big enough to send troops into. Needless to say, the first troops to go into those breaches did not fare well. So, the first unit to be sent in became known as a forlorn hope. It was often a volunteer unit with the promise of fame, glory and military advancement for those that survived.

I've read and heard about death march software projects before but I had never experienced one until recently. About a month ago I was put in charge of a 2 1/2 year JSF/EJB project that had 8 months left and was less than half done. (By the way, that's my excuse for not blogging in a while. It's not as good as Glen Smith's excuse but it's all I've got) At first this was quite disheartening. I assessed the situation and made it clear that there was no way that we could meet the deadline but was told to just "do the best we could". So, I marched on...

Then, as I dug into the project more, I discovered that there were major pieces of the application that were isolated enough that they could be done in a different environment without impacting the overall system. Grails to the rescue. We are now using Grails for most of the remaining development and gaining momentum quickly. Two of the four of us on this team have Grails experience but the other two are coming up to speed very quickly and, I might add, enjoying their jobs more than they have for some time. One of the pleasant side effects of using Groovy and Grails is increased job satisfaction and motivation.

While there's still much to do and it is still unlikely that we will make that deadline, switching from JSF/EJB to Grails has turned this death march into a forlorn hope. In this case the reward won't be fame, glory and promotion but it just might be another IT shop standardizing on Groovy and Grails. Here's hoping!

Saturday, May 17, 2008

Introducing JugList.net

As part of a homeschool project and a way to try out their budding Groovy & Grails development skills, two of my sons, Zak and Ben, have been working on a website. Their creation is now up and running and you can see it at www.juglist.net

JugList.Net is a searchable directory of Java User Groups around the world.


You can search for a JUG (Java User Group) by name, city, state/province or country. If you still can't find a JUG in your area, there is a link to an article, by yours truly, that gives some tips on starting your own group.

Java User Groups are a valuable resource for honing your craft and building your career. They also provide a great way for experienced programmers to give a little back to the community. If you are not involved in a JUG yet, then check out juglist.net and find one near you.

Friday, May 16, 2008

Another way to use Groovy in the Enterprise

Another great way to incorporate Groovy into your enterprise Java projects is Groovy SQL. GSql makes JDBC access so easy and Groovy's seamless Java integration and dynamic nature provides for some interesting ways to take advantage of it.

In this example we'll build a utility class that will use convention to turn an SQL select statement into a List of data transfer objects.

Our goal here is to take an SQL statement and a Class, execute that statement and use the results to populate instances of the Class. We will assume the convention of camel case for object properties and underscores for database fields, so that a field called LAST_NAME would be mapped to a property called lastName. We will also assume that the select statement will only return fields that have a corresponding property in the Class.

So let's see what this might look like:

static Collection getData(String query, Class clazz, Connection con){
def field = ''
def result = []
def sql = new Sql(con)
sql.rows(query).each {row ->
def dto = clazz.newInstance()
row.keySet().each{
field = toCamelCase(it)
dto."${field}" = row."${it}"
}
result << dto
}
result
}


After defining a few variables, we create our groovy.sql.Sql object using the constructor that takes a Connection. This will allow us to use Connections provided by an application server such as WebLogic or WebSphere. We could easily change this method to take advantage of the other constructors.

Next we'll call the rows method of the Sql class, which will execute the SQL statement and return an ArrayList of GroovyRowResults. Now we'll iterate through this ArrayList and create a new instance of our DTO class for each row. GroovyRowResult implements the Map interface so we can loop through its keys with row.keySet().each. This will give us each of the fields in that row and we will turn them into property names with a call to the toCamelCase() method (which we'll look at shortly). Notice how we take advantage of GStrings to dynamically access properties of our DTO as well as keys of the row map. After we assign each of the fields in the row to properties of the DTO instance we add it to the result List. When the loop is done we just return the List. Obviously, more can be done to make this more robust and more flexible, but it's pretty amazing how easy it was to build a Groovy class that can replace tons of repetitive Java code.

Let's take a look at how we could use this class from a Java project:

...
Connection con = getConnectionFromPool();
String query = "SELECT FIRST_NAME, LAST_NAME, EMAIL FROM MEMBER";
Collection members = GroovyData.getData(query, MemberDTO.class, con);
...

That's all there is to it.

Now let's take a quick look at the toCamelCase() method we mentioned above. This doesn't directly have anything to do with the purpose of this post, but I am hoping that someone might see this and offer a groovier way to do the same thing. Basically the goal is to take a database field name such as LAST_NAME and turn it into a camelCase string like lastName. Here's how I did it:

static String toCamelCase(String val){
def sb = new StringBuffer()
Boolean newWord = false
val.toLowerCase().each{
if (it == '_')
newWord = true
else{
if (newWord){
newWord = false
sb << it.toUpperCase()
}
else
sb << it
}
}
sb.toString()
}

I was sure there was a groovier way to do this and, sure enough, Andres Almiray came up with this awesome improvement:

static String toCamelCase(String val){
def result = val.split("_").collect { word ->
word[0].toUpperCase() + word[1..-1].toLowerCase()
}.join("")
result[0].toLowerCase() + result[1..-1]
}

Thanks Andres! And if that wasn't groovy enough, Ted Naleid came up with this cool mix of regular expressions and meta-programming. Good stuff Ted!

def camelCaseConverter(orig) {
orig.toLowerCase().replaceAll(/_(\w)?/) { wholeMatch, firstLetter ->
firstLetter?.toUpperCase() ?: ""
}
}

String.metaClass.toCamelCase = {->
camelCaseConverter(delegate)
}

Thursday, May 1, 2008

Groovy and Grails at JavaOne

It's less than a week until JavaOne 2008! It is going to be an exciting week packed full of brain stretching content. There will be technical sessions, birds of a feather sessions, panels, keynotes, etc. on just about everything having anything to do with Java. But most importantly, there will be a bunch of Groovy and Grails related sessions. Starting with Jeff Brown's Grails presentation at Community One on Monday, followed by the G2One / NoFluffJustStuff gala Monday evening at the W Hotel.

Then for the rest of the week a groovy search in the Content Catalog turned up the following list:

ID

Session Title

Speaker(s)

Date / Time

Room

TS-5771

The Duke and the Elephant: PHP Meets Java™ Technology--the Best of Both Worlds

Rob Nicholson, IBM

Tuesday
05/06/2008
10:50 AM -11:50 AM

Esplanade 301

TS-5764

Grails in Depth

Guillaume Laforge, G2One, Inc., Graeme Rocher, G2One Inc

Tuesday
05/06/2008
6:00 PM -7:00 PM

Esplanade 307-310

BOF-5613

Jersey: RESTful Web Services Made Easy

Jakub Podlesak, Sun Microsystems
Paul Sandoz, Sun Microsystems, Inc.


Tuesday
05/06/2008
8:30 PM -9:20 PM

Esplanade 307-310

PAN-5435

The Script Bowl: A Rapid-Fire Comparison of Scripting Languages

Guillaume Laforge, G2One, Inc., Charles Nutter, Sun Microsystems, Inc., Jorge Ortiz, Stanford, Raghavan Srinivas, Sun Microsystems, Inc.,
Frank Wierzbicki, Sun Microsystems


Wednesday
05/07/2008
9:30 AM -10:30 AM

Gateway 104

TS-5572


Groovy, the Red Pill: Metaprogramming--How to Blow the Mind of Developers on the Java™ Platform

Scott Davis, Davisworld Consulting, Inc.

Wednesday
05/07/2008
9:30 AM -10:30 AM

North Mtg-121/122/124/125

TS-5815

Going Mobile with JavaFX™ Script Technology, Groovy, and Google Android

Mike Mannion, Canoo Engineering AG

Wednesday
05/07/2008
10:50 AM -11:50 AM

Esplanade 301

TS-6050

Comparing JRuby and Groovy

Neal Ford, ThoughtWorks Inc.

Wednesday
05/07/2008
1:30 PM -2:30 PM

North Mtg-121/122/124/125

TS-5274

Groovy on a Cloud: Testing Java™ Platform, Enterprise Edition (Java EE Platform) Applications on Amazon EC2

Chris Richardson, Chris Richardson Consulting, Inc.

Wednesday
05/07/2008
4:10 PM -5:10 PM

Gateway 104

TS-6213

Boldly Go Where the Java™ Programming Language Has Never Gone Before

Geert Bevin, Terracotta

Wednesday
05/07/2008
4:10 PM -5:10 PM

North Mtg-121/122/124/125

BOF-5102

Cooking Your Own Groovy Builder: A Step Forward into Domain-Specific Languages

Andres Almiray, Oracle, Ixchel Ruiz, Clemente Camara y Asociados

Wednesday
05/07/2008
8:30 PM -9:20 PM

Gateway 104

BOF-5110

Extending Groovy’s Swing User Interface in Builder to Build Richer Applications

Danno Ferrin, Intelligent Software Solutions, Inc., James Williams, Spatial Networks

Wednesday
05/07/2008
8:30 PM -9:20 PM

Hall E 133

TS-5793

Groovy and Grails: Changing the Landscape of Java™ Platform, Enterprise Edition (Java EE Platform) Patterns

Guillaume Laforge, G2One, Inc., Graeme Rocher, G2One Inc

Thursday
05/08/2008
9:30 AM -10:30 AM

North Mtg-121/122/124/125

TS-5693

Writing Your Own JSR-Compliant, Domain-Specific Scripting Language

John Colosi, VeriSign, Inc.; David Smith, VeriSign Inc.

Thursday
05/08/2008
1:30 PM -2:30 PM

Esplanade 301

TS-6457


Choosing Your Java™ Technology-Based Web Framework: A Comparison

Richard Pack, Hyperic; Stacey Schneider, Hyperic

Thursday
05/08/2008
2:50 PM -3:50 PM

Esplanade 307-310

TS-6606

Patterns for Integrating Java™ and JavaScript™ Technology: Tales from the Front Lines

David Caldwell, David P. Caldwell, Inc.

Thursday
05/08/2008
2:50 PM -3:50 PM

North Mtg-121/122/124/125

BOF-5101

Boosting Your Testing Productivity with Groovy

Andres Almiray, Oracle;, James Williams, Spatial Networks

Thursday
05/08/2008
7:30 PM -8:20 PM

Gateway 102/103

TS-5098

Building Rich Applications with Groovy's SwingBuilder

Andres Almiray, Oracle;, Danno Ferrin, Intelligent Software Solutions, Inc.

Friday
05/09/2008
12:10 PM -1:10 PM

Esplanade 305

TS-6050

Comparing JRuby and Groovy

Neal Ford, ThoughtWorks Inc.

Friday
05/09/2008
1:30 PM -2:30 PM

Esplanade 303

TS-6039

Jython - Implementing Dynamic Language Features for the Java™ Platform Ecosystem

Jim Baker, Zyasoft, Tobias Ivarsson, Neo Technology

Friday
05/09/2008
2:50 PM -3:50 PM

Esplanade 305



Well, if you read this far and if you happen to be wandering around the Pavillion on Tuesday afternoon at 3:30, I will be giving a mini-talk on Java User Groups at the java.net Community Corner. (That way I can say that I gave a presentation at JavaOne).

Monday, April 14, 2008

NoFluffJustStuff JUG Events

I was just at nofluffjuststuff.com and I noticed this impressive list of Java User Group events coming up:

Apr. 15 - Omaha, NE - Eclipse Plugin Development at OJUG - Omaha Java Users Group
Apr. 21 - Durham, NC - Groovin Builds Gant Get Any Easier at Triangle Java Users Group
Apr. 24 - New York, NY - Give It a REST at New York Java Sig
Apr. 30 - Houston, TX - Design Patterns in Dynamic Languages at Houston Java Users Group
May. 14 - Dallas, TX - 10 Ways to Improve Your Code at JavaMUG
May. 15 - Salt Lake City, UT - Thorough Introduction to Groovy at Utah Java Users Group
Jun. 11 - Calgary, AB - Core Groovy at Calgary Java Users Group
Jun. 11 - Dallas, Texas - Grails - Agile Web 2.0 The Easy Way at JavaMUG

As the leader of a JUG (Capital Java User Group - Madison, WI) I appreciate all the support that the folks at NoFluffJustStuff provide to the Java community. As a Groovy / Grails developer, I also appreciate the way that they are helping to usher in the next generation of Java!

Thursday, April 10, 2008

Google App Engine - Vote for Groovy

If you haven't heard about the Google App Engine then you should check it out: http://code.google.com/appengine. If you have heard about it then you know that it initially only supports apps written in Python. Google does plan to support other languages and one of the first ones requested was Groovy! In fact the first issue on their issue list is "Add Java and Groovy support".

You can add your support by going to their issue list (http://code.google.com/p/googleappengine/issues/list) and giving that issue a star. You can also add a comment but it's the number of stars that moves an issue to the top of the list. Even though the Java/Groovy request is the first one entered (id = 1) it is currently ranking 5th in stars. Slightly behind Ruby and a good deal behind Perl. This is a great opportunity to be a squeaky wheel. So head on over to the list and give Groovy a star!

Tuesday, April 8, 2008

Programming Groovy has shipped!

I just got an email from the Pragmatic Bookstore announcing that my copy of Programming Groovy, by Venkat Subramaniam, has shipped! I have just about finished reading the PDF version but I am still looking forward to having the paper copy in my hands.
I'll try to post a review soon, but I'll give you the short version now:
It's a great book and if you have any interest in Groovy you should buy it right away!

Thursday, April 3, 2008

Groovy and Grails at ApacheCon

If you've been watching the mailing lists you probably already saw this, but if not: A couple of very Groovy guys, Paul King and Andres Almiray, have submitted presentations for ApacheCon US 2008. To support these proposed sessions and help spread some Groovy goodness, register on the ApacheCon website: http://apachecon.com/html/login.html

You can find more info and a list of proposed sessions in this Nabble thread:

http://www.nabble.com/Groovy-at-ApacheCon-US-2008-to16450918.html


Wednesday, April 2, 2008

Searchable Plugin: Just use it!

Warning: If you are one of the clever folks who has already discovered the searchable plugin then there's nothing new for you here. You might want to move along to Glen Smith's latest post about hit highlighting with Searchable. If you haven't looked at Searchable yet, you need to. So, either go directly to grails.org/Searchable+Plugin or read on if you need more convincing.

I've been working with Grails for over a year, all the while hearing great things about the Searchable plugin. So far, I have only had the need for simple searches so I just never bothered to look at Searchable. That was really dumb! Like, "why bother learning how to use a hammer, this rock is working fine".


So, just the other day, I had a search that was going from two potential fields to three or four. So, I decided to take a look at the Searchable plugin and see how "hard" it would be to get it integrated. Well, as with most things in the Groovy / Grails world, I had it up an running almost before I had finished reading the wiki page. It is so easy and so powerful that I can't see myself building any kind of search without it.

Here's a simple scenario for an example: We have a Company class that has half a dozen fields that users might want to search on and they want the search form to be at the top of the list page.

First we install the plugin like so:

> grails install-plugin searchable

Then add the following line to Company.groovy:
    static searchable = true
It doesn't matter where you add this line to your Groovy class, but I like to put all static references at the top.

Next we'll add a search action to our controller:


def search = {
def companyList
if (params.query)
companyList = Company.search(params.query).results
else
companyList = Company.list()
render(view:'list', model:[companyList : companyList])
}
Just like GORM adds list(), find(), save(), etc. to our domain class, Searchable added search(), which takes a query string and optionally a map where you can add options like max, offset, sort, etc. It returns a searchResult which contains a results property which is an ArrayList. So, our companyList can be assigned either our search results or the result of a call to list().
There are other methods added to our domain and many more things that can be done with Searchable. You can read more about it at: grails.org/Searchable+Plugin+-+Searching

Finally we add a search bar to our list.gsp:

< div class="nav">
< g:form action="search" method="post">
Search: < input type="text" name="query">
< input value="Search" type="submit">
< /g:form>
< /div>


Now our users can search for companies by any of the properties using one or more search words and the result will show up in our standard list page. Searchable also supports complex queries which you can read all about at grails.org/Searchable+Plugin+-+Searching#SearchablePlugin-Searching-StringQueries

There's more that we could do here such as pagination, but I'll leave that as an exercise for the reader. How hard could it be?

Friday, March 28, 2008

Did you mean "rails"?

I really like dice.com but this is just wrong:







Ok, so there are 417 Rails jobs on dice and only 12 Grails jobs, but that's no excuse. I'm going to keep an eye on this and I'll report back when it changes.

Wednesday, March 26, 2008

Integrating Grails with EJB 2 applications

When attempting to convince an organization to adopt Grails you may have to demonstrate more than the superior developer productivity it provides. Integrating with legacy systems or even new systems that may continue to be developed in other tools will probably become an important topic. One way to integrate is to use the Grails ORM DSL to hook legacy database tables into a Grails application. Another way is to connect to existing EJB based applications. As you would expect Grails makes this so easy it seems like cheating.

In this example we have an EJB 2 server running in WebLogic. There is a CMP entity bean called Employee, a stateless session bean called EmpSession and a data transfer object called vEmployee. The EJB components and the DTO are in a jar called EmpEjb.jar. The session bean contains methods for retrieving and saving Employee entities via the vEmployee DTOs. We will focus on on how to get access to the EmpSession instance from our Grails application.

First we'll add a couple of beans to our grails-app/conf/spring/resources.groovy file using the SpringBuilder DSL.

beans = {
ejbJndi(org.springframework.jndi.JndiTemplate){
environment = [
"java.naming.factory.initial" : "weblogic.jndi.WLInitialContextFactory",
"java.naming.provider.url" : "t3://some.enterprise.server:7001",
"java.naming.security.principal" : "dave",
"java.naming.security.credentials" : "1234"
]
}
empSession(org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean){
jndiName = "EmpSession"
businessInterface = "com.enterprise.some.ejb.session.EmpSession"
jndiTemplate = ref("ejbJndi")
}
}

Let's look at what this code is doing. We have what looks like a method: ejbJndi. It is really a Spring bean id and its argument is the bean class. The block that follows includes one or more property assignments in the form of properyName = propertyValue. for the ejbJndi bean we only have one property, environment, which in turn contains several entries. The entries take the form of a map of propKey:propBody pairs. This sets up our JNDI Template which Spring will use to lookup our session bean.

Next we declare our remote session bean using Spring's SimpleRemoteStatelessSessionProxyFactoryBean (they said "Simple" not "Short"). We declare this the same way as the ejbJndi bean. This one has three properties, the session bean's jndi name, its remote interface class and a reference to the JNDI Template. For this last property we use the form property = ref("referencedBeanId").

Now we need to copy some jars to our application/lib directory. Since we are using WebLogic all of the EJB and JNDI classes we will need are in weblogic.jar. You may have one or more jars depending on your application server. Our EJB components and our DTO classes are in a single jar, EmpEjb.jar. These may often be in different jars, in which case both would need to be placed in the lib directory.

Beans defined in resources.groovy can be auto-wired by name so we can just place def empSession in any Service or Controller class and start calling session methods.

With this ability to integrate so easily with legacy applications there is just one less reason not to start using Grails in the enterprise.

Thursday, March 20, 2008

Sven and Glen are at it again!

The Groovy Posse, er, I mean the Grails Podcast is back with episode 50. In this episode they've got some big news about some big sites built with Grails. If you've heard the question "are any real sites using Grails?" as many times as I have then you'll want to check this out.

There's more but you'll just have to tune in for yourself. I have to say that I really appreciate the conversational style they have now with Sven and Glen; now if they could only find a Ben ...

Wednesday, March 19, 2008

You learn something new every day... on the Grails Mailing List

The Grails mailing lists are tremendous resources. Not only are they great for getting your questions answered by the helpful experts that never seem to sleep, but you can often learn something from someone else's question/answer.

For example, just the other day, I came across this very helpful post by Chris Chen that describes a simple way to deal with get methods in your domain class that don't have a corresponding set method (ie. calculated properties). If you try to do this without some extra code, you will get a PropertyNotFoundException. In the past I've usually handled this by renaming the method so it doesn't start with get, even though get might make the most sense. The alternative is to use a transients list, but that just doesn't seem right to me for this situation.

What Chris suggested was to dynamically type your get method. So, for example, if you have a Parent class which has a collection of Child and you want to find the oldestChild, you can do this:


class Parent {
...
static hasMany = [children: Child]

def getOldestChild(){
//logic here to get oldest child
}
}

That's all there is to it. Just use def instead of a static type. Now, as far as Grails is concerned you will have a property called oldestChild. It will even show up in the scaffolding. Hibernate, however will remain blissfully ignorant. Now that I've seen this it seems painfully obvious, but if I hadn't read Chris' answer in that post, I would have never thought of it on my own.

This is just one example, there are many others, so if you aren't signed up for the mailing list or at least perusing the archives, I would encourage you to get started today.

Monday, March 17, 2008

Use .each, Save A Puppy.

If you haven’t been listening to the Grails podcast you’re missing out. Sven Haiges has done a great job of bringing interesting news, tips and interviews related to Groovy and Grails. Now Glen Smith (creator of groovyblogs.org) has joined Sven and a good thing has gotten even better. Could we be seeing the beginnings of the Groovy Posse? Any ideas for the theme song?

My favorite line from the last episode was when they were discussing the old Java for loop and Glen was talking about how he couldn’t imagine using a for loop to iterate over a collection and then said that “Every time you do that a puppy dies somewhere”. So next time you find yourself falling back into old habits, think of the puppies and use .each

Be sure to check out the podcast. It’s supposed to be out fortnightly (that’s every two weeks for us Yanks) so the next one should be here soon!

Sunday, March 16, 2008

I Survived SD West

This post is a bit late, since it's over a week since I got back from SD West in Santa Clara, CA. (March 3 - 7).

There was some great technical content and some very interesting people at this conference, but what made the week memorable for me and the family was that I was scheduled to speak at it. My session was during the last slot of the last day (they always save the best for last, right?). Still mulling over the ideas and inspiration gained from the Groovy/Grails Experience last month, I spent most of my spare time in my room working on my slides, which my kids proofed for me from home. (slides and code sample can be downloaded here)

This is the first of the Dr. Dobbs family of conferences to have any Groovy or Grails presentations: it had one of each. First on Monday Andy Glover gave a very interesting and entertaining half day tutorial on Groovy. You could feel the excitement in the room. In fact a guy sitting next to me leaned over at one point and said "This stuff is amazing!"

Later came my session on Agile Web Development with Grails .... I thought I had my nerves under control, and the audience was involved and had many good questions. It was obvious that these folks were thinking about how and if they could start using Grails. After it was over, it was great to have several people stay and offer nice comments, or ask additional questions. However, one kind lady made the comment that it was "very brave of you to get up there in front of all these people". Perhaps my nerves weren't quite as controlled as I thought.

While the Groovy and Grails aspects were a high point for me, there was some other good stuff at SD West. The Beautiful Code panel was a lot of fun and contained some good insights. The Developer Bowl was a hoot and a half and, James McLurkin of MIT gave a very interesting presentation on robotics and how to save the world by being a geek. Then there was Uncle Bob. Robert Martin has always been one of my favorite speakers and although I only caught one of his talks this time, Clean Code was terrific. We all know shorter methods are better but Uncle Bob gave some very practical suggestions and examples of how to do it.

It was all good, but I'm glad to be home.

PS: The kids didn't really have to carry me on a stretcher, but its good to know that if I ever need this type of assistance, they are up for it.

Saturday, March 15, 2008

Grails' ORM DSL Rules!

Probably my favorite feature in Grails is GORM, the Grails Object Relational Mapping. GORM gives you a host of time saving and powerful tools. Early on I was wowed by the GORM methods that were dynamically added to my domain classes: save(), delete(), list(), get(), findByProp1AndProp2, and the list goes on. I still appreciate these features, but a more recent addition to GORM has moved to the head of the class with me. The ORM DSL introduced in Grails 1.0 makes it trivially easy to map your domain classes onto legacy database schemas. It was already possible to do this in Grails and Jason Rudolph has given us some helpful tutorials, but the ORM DSL makes it so easy even I could do it. And that's important because it enabled me to get Grails into a production project with my current client. They were impressed with the productivity promise of Grails and were quite ready to look into something beyond the JSF/EJB stack they had been fighting with, but having anything or anyone besides the DBA creating the database schemas was out of the question.

Let's take a look at just how easy it is to use the Grails ORM DSL. For our example we will work with the tried and true Book and Publisher classes, but with legacy tables in an Oracle 10g database.

Here's our domain classes in Grails:

class Publisher {
String name
String city
static hasMany = [books : Book]
}

class Book {
String title
String author
Integer pages
Publisher publisher
static belongsTo = Publisher
}

And here's the legacy tables we have to work with:

TABLE PUB01
Column Name Data Type
ID_PUB_PK NUMBER
PUB_NM VARCHAR(100)
PUB_CTY VARCHAR(100)
SEQUENCE ID_PUB_PK_SEQ

TABLE BK01
Column Name Date Type
ID_BK_PK NUMBER
BK_TITLE VARCHAR2(100)
BK_AUTHOR VARCHAR2(100)
BK_PGS NUMBER
ID_PUB_FK NUMBER
SEQUENCE ID_BK_PK_SEQ

Now let's map our Publisher class to the PUB01 table:

class Publisher {
String name
String city
static hasMany = [books : Book]
static mapping = {
table 'PUB01'
columns{
id column: 'ID_PUB_PK'
name column: 'PUB_NM'
city column: 'PUB_CTY'
}
id generator:'sequence', params:[sequence:'ID_PUB_PK_SEQ']
}
}

Let's look at what we did here. We created a static block called 'mapping'. Inside the mapping block, we first define the table for this class (note that the table name and all column names are in quotes), and then we create a nested block called columns. In the columns block we list each property, a space, and then column: 'column name'. Using the word 'column' on each line might seem redundant, but there are other attributes of a property that can be set in the columns block, so when you are setting the column you have to be specific. After the columns block we have the id generation scheme, which we'll discuss in a bit.

Now we'll modify our Book class and discuss one interesting thing there:

class Book {
String title
String author
Integer pages
Publisher publisher
static belongsTo = Publisher
static mapping = {
table 'BK01'
columns{
id column: 'ID_BK_PK'
title column: 'BK_TITLE'
author column: 'BK_AUTHOR'
pages column: 'BK_PGS'
publisher column: 'ID_PUB_FK'
}
id generator: 'sequence', params:[sequence:'ID_BK_PK_SEQ']
}
}

You'll notice that this was pretty much the same thing we did with Publisher. The one difference is the way that we mapped the relationship. The publisher property, which is of type Publisher, is mapped using the foreign key for the Publisher table, 'ID_PUB_FK'

Now let's talk about id generators. In Grails you can use any id generation scheme supported by Hibernate. To do this with the ORM DSL, you basically call an id method and pass it a Map. The first key in the Map is the word generator, and the first value is the name of the generator class, such as 'hilo', 'seqhilo', 'identity' or 'sequence'. The Hibernate docs list the possible classes and their params. The next key is the word params and the value is another Map. The keys for this Map are name attributes of each of the param tags taken by this generator class. The values are the bodies of the param tags. In the case of the sequence generator we only have one param tag, with a name attribute of sequence, and the body would be the name of the sequence in the database, in our example 'ID_PUB_PK_SEQ' or 'ID_BK_PK_SEQ'.

One more note: We were able to talk our DBA into adding a number field called version to each of our legacy tables, so we left versioning on. If you cannot add a version field to your tables (and don't already have one), then you can turn off versioning by adding the line version false after the line where you declare your table. If you do this you will lose the optimistic concurrency that Grails / Hibernate give you and will have to provide some other method of handling concurrency.

There is a great deal more that you can do with the Grails ORM DSL, but I only wanted to discuss features that I've actually worked with. As I dig into this more I may add more details, but in the meantime you can read all about it in the Grails online docs.

Monday, March 3, 2008

Good Stuff In Milwaukee

This past weekend I attended the Greater Wisconsin Software Symposium in Milwaukee. This might seem strange considering I just went to the Groovy / Grails Experience (2GX) last weekend, but it's all part of my master plan. You see, at the 2GX there were 5 concurrent tracks and it was quite difficult to decide which sessions to miss. However, six of the 2GX speakers were also scheduled to speak at the GWSS, I knew that I could safely skip the sessions that would be repeated there. Most notable among those were Scott Davis' pair of talks entitled "Groovy: The Blue Pill" and "Groovy The Red Pill" which I caught on Friday afternoon. These sessions were worth the wait! In the first one Scott focuses on the smooth integration between Groovy and Java; using examples such as creating an interface in Groovy and then creating a Java class that implements that interface. Since, once it's compiled, a Groovy class is a Java class, there's really no limit to the ways you can intermingle Java and Groovy classes. One of my favorite lines in this talk was when asked the question 'will Groovy replace Java?' Scott answers 'No more than icing will replace cake.' That's classic!

The Red Pill talk dug into some the really cool stuff you can do with Groovy once you're ready to take it to the next level. He covered things like method pointers, closures, named arg/var arg constructors and operator overloading. Then he got into meta-programming and,well I don't want to give too much away. You'll just have to catch an NFJS event near you and see for yourself.

Next up was Scott Davis again with “Grails for (recovering) Struts Developers”. This was basically an introductory Grails talk (and a good one), but targeted at developers who were used to the Struts way of doing things.

The next day I can't report on because I went, with my family to the Milwaukee zoo. Well I guess I could report on it but it probably wouldn't be very interesting for someone reading a Groovy/Grails blog. Except that they did have some very groovy apes there.

Sunday morning Venkat Subramaniam gave a presentation on TDD/BDD that was very motivating. He showcased FIT, FitNesse and easyb, by the oh so hip, Andy Glover.

Then on to more testing stuff, Jeff Brown gave a talk on TDD in Groovy and Grails. Testing is another great showcase for the power of Groovy and Jeff did an excellent job of highlighting that.

Then came a hearty lunch, visits with a bunch of fellow Madisonians and the speaker panel. The speaker panel is always a high point of a NFJS event and this one was no exception. Brian Sletten continues to improve his ability to turn almost any question into a discussion of the Semantic Web. (go Brian!). There were two more sessions in the afternoon but I had to catch a flight out to California for SD West, where I will be presenting on “Agile Web Development with Grails” this Friday. Speaking of which, I better get back to work on my slides. But firs I want to mention how great it was to see so many members of the Capital Java User Group at the Milwaukee conference. We could have held a meeting there and it might have been one of our best turnouts. Also I have to give a big Thank You to the good folks at Smart Solutions who offered to send all of their Java developers to this conference. Now that's a forward thinking consulting firm. As well as a great company to work for.

Wednesday, February 27, 2008

Groovy/Grails Experience... The name says it all

Well, I didn’t get a chance to post during the rest of the Groovy Grails Experience. There was just too much to do. This was a very full conference with quality content until after 10PM each night.

Now that I’m caught up on my sleep, I will give a few impressions. But first let me say that several more prolific writers than myself have already written about the event. You can see a bunch of them at the GroovyZone: http://groovy.dzone.com/news/2gx-impressions

This was the best conference that I have ever attended period. Literally. I think the best way to explain why I say this is the name of the conference. The Groovy / Grails Experience.

Groovy is so refreshing! It is NOT a replacement for Java. As Scott Davis said so eloquently “Groovy IS Java and Groovy is NOT Java” How do you argue with logic like that. But seriously. It wouldn’t be that hard to claim that Groovy isn’t really a different language. One could say “It’s just a jar that you add to your classpath that gives you some new APIs and some new syntactical sugar”. Think about things like JSTL and JSP expression language. But when you look at the APIs and syntax goodness that Groovy gives you, you just don’t want to go back. To see more about Groovy take a look at the tutorials and articles on the Groovy website: http://groovy.codehaus.org/Articles

Grails is like a web framework on steroids! With tools like Spring, Hibernate, Ant, SiteMesh, Jetty and so many more built into it, Grails would be great even without Groovy but when you add in the power and flexibility (not to mention sheer joy) of Groovy, this web application development system is almost too good to be true. I have been using Grails for about a year now but at this conference I learned several more things that can be done with Grails. Things like integration with UI tools like YUI, Script.aculo.us that is so easy it should be illegal! Glen Smith's talks were worth the price of admission on their own. Then there was the deep dive into GORM the Grails Object Relational Mapper by Graeme Rocher that was mind-blowing. The more I see of what Grails does for me the happier I am that I get to use it full time. You can do (almost) everything you can do with Grails with Spring and Hibernate by themselves, but it would be so much more work and so much more complexity.

Experience is what set’s all the NFJS conferences apart and this one was no exception. Every detail was taken care of, all the slides were on a 1 gig USB drive that was also very handy for grabbing code samples from speakers after a session. The room sizes and layouts were good, the food was great and refreshments were available throughout the day. This is not a big deal but it’s a very telling point about the difference between NFJS events and other big name conferences. At many other conferences I’ve been at, on the last break of the last day, you’d be lucky to find some cold coffee left over but at the 2GX the last break had plenty of coffee, soft drinks and an ice box full of a variety of ice cream bars. These “little” things really make it easier for you to concentrate on the sessions and the networking opportunities, which were also awesome. The Groovy / Grails community has some of the sharpest developers I’ve met anywhere. With half hour breaks between each 90 minute session and hour to hour and half lunch and dinner breaks, there were many opportunities for those side discussions that make conferences like this so special.

If you weren’t able to make it, don’t worry. They are already planning another one on the west coast in October.

Wednesday, February 20, 2008

In Reston, VA for 2GX

The Groovy/Grails Experience starts tomorrow! I arrived in Reston, VA this evening since I couldn't get a flight in early enough tomorrow. I am very excited about this conference and very grateful to be able to attend. I have been working with Groovy and Grails for about a year now and have been enjoying it immensely but there is still so much more to learn. So, that's what I will be doing for the next three days. I just hope my brain doesn't explode. It's not quite as expandable as it was in my younger days.

Apart from the excellent learning opportunity, I am also excited about the people that are going to be here. So many of the developers and power users of Groovy and Grails are going to be here. I've read their books, I read their blogs, I read their messages as they help people on the mailing lists, I have even heard some of them on pod casts, but it will be great to actually meet them.

I will try to post throughout the weekend with any interesting tidbits I pickup at the conference.