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.



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:

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.


Another Post on Automatic Getters and Setters

Recently I was looking at the Groovy section on DZone, and there was an article called Evil: Getters and Setters Where They’re Not Required (original here). He reiterates a lot of what I have been saying in my posts about why I am making the Groovy Validators.

I doubt that he and I are the only two that have noticed this issue. I have heard/read a lot of people complain about the verbosity of getters and setters (like we can get in Eclipse), and how much cleaner it is to use a language that will generate them for you (like Groovy and Ruby). Yet it is odd that so many times people gloss over the fact that these blind, automatic getters and setters essentially leave your variables wide open for just about anything. It seems like people hate verbosity more than they like data integrity.

Granted, I am a bit out of practice with Ruby, so it is possible that there is some sort of validation in the non-Rails Ruby space. And this is purely anecdotal. I just thought it was interesting.

UPDATE: I am making some progress on using the validation annotations with immutable objects. Hopefully Mr LaForge hasn’t closed that bug yet, and announcing my validators will bring me fame and fortune.

Standard For Entering Defects and Tickets

Lately I have spent a lot of time at my job building and supporting benefits systems for a few different states. This has involved (amongst other things) fixing defects and handling support tickets. I think we should encourage a standard for filing defects and tickets.

A good standard would be to do something iike this:


I encouraged this on a few projects, and I only saw it happen a few times. Usually, the ticket would say something like, “The mother on this case is not getting any benefits”. I would look at the data for the case, and I would see that the mother should not get benefits. I would have to contact whoever filed the ticket/defect and ask them what they were expecting and why.

Recently I got tripped up on this myself. I had a defect, and the filer attached an  email thread. The penultimate message listed the expected outcome, pretty close to the way I did it above: “Expected Results: G, H, I”. So I started seeing how I could make that happen. But later I read the last message, which said something to the effect that, “There are really two defects here, let’s just focus on the first one.”

So they were getting State A and the actual state, they said they were expecting State B, then finally said they were expecting State C. I zeroed into the “Expected Results” and went with that. I think if they were expecting something different, they should have created a new “Expected Results” paragraph.

It has been said that software development is not only about technical skills, but also about thinking skills. In the recent case above, I was trying to be methodical, and I got tripped up by people being less methodical.

So I think there should be a standard for tickets and defects. State the actual output clearly (at least the parts that are wrong). State clearly what you are expecting, and if possible why you are expecting it. This should be in the main body of the defect/ticket, not buried somewhere.


More Git Notes

Neo4J and Github trainer Peter Bell was at the Austin Groovy and Grails User Group a couple of weeks ago. He gave some git tips and tricks. I took notes. The guys at AGGUG said they would have something online. So far I have not seen anything, so I am posting my notes.

These are unedited, so you have to mentally parse it yourself. But there were a few things I did not know about.

start gitconfig
You can use the properties as setters and getters
git config –global
git config –global “Daffy Duck”
True for Windows
git config –global core.autocrlf true input
Colors for different status in git
git config –global color.ui true
Can be global, local
global is for every repo
local is the default, for a repo
system is not used too often. This is for all the users of that system.
It is in ~/.gitignore

To create a repo:
git init webgg1
cd webgg1
You might touch a file just to make a file
touch slslsls
git add .
git commit -m “Hello”
Status in silent mode: reduces the output
git status -s
git config –global alias.s “status -s”
Now you can type
git s
git log has bad default output
git log –oneline
git log –oneline –decorate
HEAD is the commit branch you currently have checked out
git log –oneline –decorate –all –graph
git config –global alias.lg “log –online –all –decorate –graph”
The alias is after the alias.
You want to commit to a different branch than master.
git checkout -b about_us
Any untracked files from master come with you
For a modified file (will not work for new files):
git commit -am “djdj”
git merge sjsjs
That is a fast forward merge.
He does not like that.
First he must undo the merge:
git reset –keep master@{1}
Go back one step in the ref log

git merge –no-ff $BRANCH -m “Hello”

git branch -d about_us
He likes to delete a branch when he commits
Merge other branches into master
I always thought you do the opposite: Never mess with master

TO remove a commit:
git reset –hard head~1

rebasing: a branch has a starting point from which it grew
Could we move the base to somewhere else
git rebase master
You might get a merge conflict.
git rebase –continue
If you delete branches and do not do fast forward commits, you still see the commits from those other branches

git reset will undo commits
–soft affects history
–mixed affects staging area as well
–hard affects working directory

We want the two new files, but undo the commits. This will undo 2 commits
git reset HEAD~2
git commit -m “jjs”

Make the last two commits into one commit
git reset –soft HEAD~2
git commit -m “hddh”

Once you push to a server, reset will be bad news
git revert $SHA_CODE

git reset –hard HEAD~2
That will delete history and the files

git ref log will track everything, it is local to each machine.
You can still reset

git commit -m “Logic stuff adofhdofh”
git commit –amend
that only affects the last commit

git rebase interactive will take commits and reorder them or concatenate them
git rebase -i HEAD~4
r = reword
f = fix up
Squash will add all the commit message. You just want to reword the first, fix the rest.

Adding Another Domain Class To Grails User App

First, create the domain class:

Next, add some fields and the SecUser class:

LInk it to SecUser:

Link SecUser to our new domain (we already had a Book class):

Add some constraints to our new domain:

Next, generate the controller and the views:

Add some imports in the MagazineController

Add the Spring Security Service:

Add the following annotation to the index and show methods:

Add the following annotation to everything else:

Change the save method to ensure the user ID is the logged in user:

Next, let’s change the views.

In index.gsp, wrap the link for the create action in a block to see if the user is logged in and has a “USER” role:

In show.gsp, we should put an if block around the links to delete and edit a magazine

There is no change at this time to create.gsp or edit.gsp.



Mouse Tapping Is Stupid

I use a laptop running Ubuntu.

For the most part it is pretty good. But there is an issue with the mouse/touchpad.

When I am at home I use a mouse attached via a USB table. When I take my laptop somewhere, I usually bring another, smaller mouse that also connects via USB. But sometimes I have to use the touchpad. I really do not like the touchpad.

There is no way to disable the tapping “feature”. It is not a feature, it is a bug. Pretty often one of my thumbs or a finger will touch the touchpad unintentionally, and there will be unexpected behavior. I suddenly find myself typing on another part of the screen. I really wish there was a way to disable it. I have looked online, and I have not gotten any of the proposed solutions to work.

I do not know why this stupid feature even exists. I cannot think what action you would do with an actual mouse that it emulates. I have never done anything by grabbing the mouse, lifting it up and putting it back down. This seems like the sort of really stupid idea that someone at Microsoft would have come up with. If I want to put the focus on another part of the screen, I will use the mouse buttons. Just like I do with a desktop mouse.

I really wish Linux turned this off by default.

Git Cheat Sheet

It is a good idea to work on a branch other than master. You can create your own branch like this:

The “-b” will create a new branch. If you want to switch back and forth between branches, use the checkout command without the “-b” option:

To get a list of all your branches:

When you want to push, you pull the latest code from the master branch, check out your branch, merge your branch with master, fix any conflicts, check out master, and merge it with your branch.


If you move or delete a file, you will need to make that information known to git. You do this by entering

for deleting a file, and

to move a file.

Passphrase Generators

Since passphrases are more secure than passwords, I have started using them for different sites when I can. Here is a list of passphrase generators that I use, and some that I have come across: