Chariot Training Classes

Training Courses

I run Chariot's training and mentoring services. We provide training in AngularJS, HTML5, Spring, Hibernate, Maven, Scala, and more.

Chariot Education Services

Technology

Chariot Emerging Tech

Learn about upcoming technologies and trends from my colleagues at Chariot Solutions.

Resources

Chariot Conferences

Podcasts

Entries in chariot-news (45)

Friday
Mar262010

Calling PostgreSQL Stored Procedures from Grails - Part 2 - Spring's StoredProcedure class

In this part of my "Calling PostgreSQL procedures" series, I'm going to use the Spring StoredProcedure class to initiate the call.

What is the StoredProcedure class?

The Spring JDBC API has a class, StoredProcedure, that wraps calls to a stored procedure, providing access to both input and output parameters. The general strategy for using this class is:

  1. Define your StoredProcedure subclass, listing parameters, and compiling the procedure (binding it to a Callable Statement)
  2. Call the stored procedure using the execute() method, passing a Map of parameters

My sample code follows:

The Stored Procedure class

package org.playball.db

import org.springframework.jdbc.core.SqlParameter
import javax.sql.DataSource
import org.springframework.jdbc.object.StoredProcedure

class StoredProcSubclass extends StoredProcedure {
    public StoredProcSubclass(DataSource ds) {
      super(ds, "salesByBookId")
      setFunction true
      declareParameter(
         new SqlParameter("book_id", 
                  java.sql.Types.INTEGER))
      compile()
    }

    public Map execute(Integer bookId) {
      Map inputs = new HashMap()
      inputs.put("book_id", bookId)
      return super.execute(inputs)
    }
}

I've placed this class in src/groovy/org/playball/db. Now, to call it from our service from the last post, here is a snippet in the StoredProcedureRunnerService class:

  def sumBookSalesByBookIdWithSPSubclass(int bookId) {
    def spcaller = new StoredProcSubclass(dataSource)
    def map = spcaller.execute(bookId)
    // result is in entry '#result-set-1, 
    // with field 'result' which is a list, taking entry 0
    map['#result-set-1']['result'][0]
  }

Wasn't that fun? The strangest thing is the result output. Apparently, the return of the StoredProcedure call is a map of result sets, (#result-set-1), with each result being a map of fields w/values. Figure that out in a unit test! I actually hacked this with the Groovy Console, and it worked great for figuring that stuff out.

Please note - you should set up your StoredProcedure subclass in a Service or Spring Bean, not at the instance level, or you have to compile it each time. Rather inefficient... Will clean up later as this was just a demo of technology, not efficiency!
Thursday
Mar252010

PostgreSQL East Conference - link to Grails Presentation materials

Brent Baxter and I presented a 90 minute Grails session, with a focus on GORM and PostGreSQL.  I put the PDF of the slides, along with one of the sample projects (just a starter but with targeted example), on a GitHub site - there you can download a zipfile or .gz file of the whole archive.

I will post a few blog entries about calling Stored Procedures from Grails.  I hope they prove useful.

URL for the GitHub site 

Thursday
Jan212010

Venkat Subramaniam on Groovy, DSL adoption, other dynamic languages - TechCast

I have been absolutely thrilled with the roster of speakers on the TechCast. This show is with one of my favorite speakers, Venkat Subramaniam. Venkat is a long-time Groovy proponent, but is quick to point out that he uses other languages, and always strives to use the right tool for the job.

Here is the link to the show notes page : Episode #49 - Venkat Subramanaim

In this interview we talk about the adoption of languages such as Groovy, Ruby and Scala, and hear a few good stories along the way.

Venkat is speaking this year at our Emerging Technologies for the Enterprise conference (April 8-9) on Domain Specific Languages.

Up next we will feature Jeremy Grelle from SpringSource on thier web and RIA initiatives, and just afterward Brian Sletten on the Semantic Web. I hope you are enjoying listening to these interviews as much as I am recording them.

Saturday
Dec052009

Java EE, Seam, Weld and JSF

Very interesting article from Gavin King. Essentially my original opinion on Seam, based on interviews this Spring with a number of JBoss developers, is that it would be cannibalized to help the Java EE 6 spec.

Gavin says that EJBs are now needed less (only for exposing web services) and that Weld - the maybe 4th name for JSR-299 would take the injection technology.

Also he goes on to say that JSF 2 really took it's major shift in simplicity from Seam (no more page beans config file) and that the Seam programming model will be the JavaEE programming model.

The full article here:

http://www.infoq.com/news/2009/11/weld10

Monday
Nov232009

SpringSource Core Spring training @ Fort Washington - 12/8 - 12/11 2009 

On December 8, 2009, Chariot Solutions will be holding official Core Spring training at our Fort Washington, PA training center, just outside Philadelphia. This is the SPR-001 Core Spring Framework course, which provides an in-depth look at the core container, AOP, JDBC, ORM, JMS, MVC and more.  

Upon course completion, each attendee gets a free voucher to test for the Core Spring certification test. 

To register, visit SpringSource's training site at http://www.springsource.com/training/spr001/phi-20091208.