2014-08-11 Tweets

Grails and PostgreSQL

In addition to the Austin Groovy and Grails User Group, I also go to the  Austin Postgres Users Group.

At the last APUG meeting there was no set agenda or presentation. They just had a Q&A with whoever wanted to answer. The company that hosts the APUG is a heavy Postgres user.

I had a few questions. The basic thrust was: What are some things DBAs wish developers knew about databases or did differently?

One answer was that developers should learn to think in sets. If you need to change a bunch of records in the database, just run a query that will update them all at once. A lot of developers would get a query (with an ORM) that would put the objects into a list, then iterate through the list and update them one at a time. This would be a much heavier load on the database. Just run a query.

In GORM, you can call .withSession on your domain classes to get the Hibernate session, and use that to run queries.

Another suggestion was to deal with views instead of tables. I really do not have any knowledge about that WRT Grails.

The last thing that I remember is that you should not think that you are the only person who touches the database. Someone else will want to run queries, and perhaps add data to it. Many web frameworks (like Grails and Rails) have database constraints if you access the database through the web app. But outside the app, you are on your own.

One small project I will start is I will go through the Grails constraints (see here and here) and see how to create them in Postgres. I might do MySQL as well. There are a few that Grails will put in the database when it is generated by Grails, like uniqueness, foreign keys, and whether or not a field can be null. But for most of them, they only exist in Grails.

 

 

Back From Gr8Conf

I went to Gr8Conf last week.

I really cannot think of a whole lot to say at the moment. I am excited that there is a lot going in the Groovy and Grails space.

Right now I will have to go through all my Grails apps and change the controllers so the create, edit and delete actions in the controllers send their work to Grails services.

I have been working on using the Grails Shiro plugin. I asked for help with it from the guy who used to maintain it, Peter Ledbrook. I was not able to get examples from other apps to work. He was not able to get things running for me either. It turns out the app I was working with was also using the Shiro-UI plugin. There were two “Auth” controllers, and that was messing things up.

I have tried working with the Grails Spring Security Core plugin. It is easy to get up and running, but writing tests for an app that uses it is pretty hard. I got it working myself, but it took a lot of Googling (and as many  of you know, you Google after you have driven yourself crazy trying to figure it out on your own). The way I got it to work was a bit of a jumble in my opinion, with some Spock mocking mixed in with some core Groovy mocking. I realized why it was so hard when one of the presenters said that services should only be called from controllers. Spring Security Core requires you to run the plugin as a service from your User domain classes.

I will try to write some tests for an application using the Shiro plugin. Hopefully it will be easier.

I think the reason I had so much grief with the Spring Security tests is because a lot of tutorials do not really cover services too much. Since they are not covered, I guess people don’t think about them too much. One person I talked to said that one reason for that might be that the controller generators do not put edit, save and delete in services, so people think they can get by without them.

I might post my notes online later.

2014-07-28 Tweets

Error With ForkedTomcatServer in Grails

Recently I had an issue with just about all of the Grails apps on my machine.

When I tried to run them, I was getting this error:

| Packaging Grails application.....
| Error Tomcat plugin classes JAR grails-plugin-tomcat-7.0.42.jar not found
| Running Grails application
Error: Could not find or load main class org.grails.plugins.tomcat.fork.For­kedTomcatServer
| Error Forked Grails VM exited with error

The number for the jar file would be different for different versions of Grails.

What I finally did to get rid of the error was:

  1. Run “grails clean; grails compile; grails list-plugins”
  2. Comment out the line for the Tomcat plugin in BuildConfig.groovy
  3. Run “grails clean; grails compile; grails list-plugins” again
  4. Uncomment the line for the Tomcat plugin
  5. Run “grails clean; grails compile; grails list-plugins” again

Maybe the first “grails clean; grails compile” is unnecessary. But this seemed to work.

I have no idea what caused it. It happened with various versions of Grails. I had no problem with new Grails apps, or with apps downloaded from Github.

You’re welcome.

 

2014-07-14 Tweets