Fork me on Github s

Posts Tagged spring

Spring Roo Database Reverse Engineer with Oracle

So you are trying to reverse engineer an Oracle database with roo?

Unfortunately, due to licensing restrictions with the Oracle JDBC Drivers, this is a little difficult. There are a few blog posts and forum threads that address the problem but I figured I would post what worked for me here.

First, you need to download the appropriate Oracle Drivers from Oracle. The required login, stringent password requirements, nosy registration form, and general system instability made this a pretty painful step for me. I’d also like to say that companies that have password requirements that don’t allow symbols (or any other non-standard requirement) have a special place in my heart. Having to recover my password every time I go to your site virtually guarantees I will only go there when I absolutely have to (not often). Anyways, once you have it downloaded you need to install is with maven:

mvn install:install-file -Dfile=~/Downloads/ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -DgeneratePom=true

Here comes the fun part. You need to create an osgi wrapper for the driver to install it in roo. Otherwise, roo cannot see the driver. Create a new folder and put the contents of the oracle roo addon pom gist I created. Now build it with maven. You may want to change some of the artifact ids and dependencies for your particular situation.

mvn package

No open a roo shell and execute the following command:

osgi install --url file:///Users/me/my-osgi-project/target/the-jar-it-built.jar

Now run (in roo):

jpa setup --provider HIBERNATE --database ORACLE 
dependency remove --groupId com.oracle --artifactId ojdbc14 --version 10.2.0.2
dependency add --groupId com.oracle --artifactId ojdbc6 --version 11.2.0.3
database properties set --key database.driverClassName --value oracle.jdbc.OracleDriver
database properties set --key database.url --value jdbc:oracle:thin:@%YOUR_CONNECTION_INFO%
database properties set --key database.username --value %YOUR_USERNAME%
database properties set --key database.password --value %YOUR_PASSWORD%
database reverse engineer --schema %YOUR_SCHEMA% --package ~.domain

If you have any package loading exceptions when running the reverse engineer command you can uninstall the osgi bundle, set the package to optional in the osgi pom in the IncludedPackages tag (javax.some.package.*;resolution:=optional) rebuild, then reinstall in roo.

Tags: , , ,

6 Comments

What are the downsides to using dependency injection?

I recently came across an interesting question on stack overflow with some interesting reponses.  I like this post for three reasons. First, I am a big fan of dependency injection, it forces you to decouple your code, create cohesive interfaces, and should result in testable classes. Second, the author took the approach I usually do when trying to evaluate a technique or technology; suspend personal feelings and try to find some compelling arguments against it. Third, it proved that it is very difficult to come up with a compelling argument against dependency injection.

What are the downsides to using dependency injection?

Tags: , , , , ,

No Comments

Spring MVC Gotcha: Passing Response into Controller Method

I have a confession to make. I created this blog to not only help people out, or opine about industry topics, but as a personal scratch pad for me to help remember stuff. So with that in mind, I am going to take a personal note of a problem I had been dealing with.

Most of us using Spring MVC are familiar with the following:

   class SomeController {
      
     @RequestMapping("/action")
     public void action(HttpServletRequest request) {
       // do something
     }
   }

Simple, right? Annotation-mapped controller which will use the RequestMapping annotation to determine the viewName. Confused? Check this out. But, what happens when you decide to set a cookie in the action method? For this we will need access to the HttpServletResponse object. No problem, since Spring will automagically inject it into our method.

Observe the following:

   class SomeController {
        
     @RequestMapping("/action")
     public void action(HttpServletRequest request, HttpServletResponse response) {
       // add cookie using response.setCookie(Cookie) method
     }
   }

Looks good to me. Only problem is, it will not work (a small problem). Apparently, the Spring Framework assumes you are handling the response if it passes it into a method with a return type of void. This is because there is no good way for it to know if you did or didn’t.

No big deal, we can use a string to prevent this behavior:

   class SomeController {
        
     @RequestMapping("/action")
     public String action(HttpServletRequest request, HttpServletResponse response) {
       // add cookie using response.setCookie(Cookie) method
       return "action";
     }
   }

This will fix the problem. Consult the documentation here for more information.

Tags: , , ,

4 Comments