Monday, February 15, 2010

Grails and MS-SQL Server

When using Microsoft SQL Server as the back-end database for a Grails project, the default hibernate mappings create primary key id columns of type numeric (which can be annoying).

This is because the MSSQL server Dialect is designed to support MSSQL Server versions older than 2000. MSSQL Server 2000 and later has support for BIGINTs, and therefor doesn't need to store it's primary keys in numeric columns.

The fix for this is to create a new SQL Server Dialect for SQL Server 2000 and later. We do this by creating the following file in our Grails project

src/java/org/hibernate/dialect/SQLServer2000Dialect.java


Containing the following code
package org.hibernate.dialect;
import java.sql.Types;

public class SQLServer2000Dialect extends SQLServerDialect {
public SQLServer2000Dialect() {
super();
registerColumnType(Types.BIGINT, "bigint");
registerColumnType(Types.BIT, "bit");
}
}


Then we edit our DataSource.groovy that's located under grails-app/conf so that it uses our new dialect.
dialect = "org.hibernate.dialect.SQLServer2000Dialect"


And wala! Our primary keys are bigints!

What this also means is that grails will also set the primary key to be identity columns rather than the not quite as useful hilo algorithm.

Thursday, February 4, 2010

Grails and Date Inputs

I've been rather frustrated with the datePicker input tag for grails lately. For anyone who writes software for people who do data entry 8 hours a day, 5 days a week, you know that picking a date from pull-down menus, or via a calendar navigation such as the calendar plugin for grails is a huge waste of time and very slow.


To resolve this I've taken the approach of using textInput tags for the dates

<g:textfield name="birthDate" size="12" maxlength="10" value="${personInstance?.birthDate?.format('MM/dd/yyyy')}" class="datePicker" />


And using jQuery UI to add a calendar control to the inputs so that if the user wanted to, they can use a datePicker

// Turn all textFields of class 'datePicker' into jQuery.UI.calendar controls
jQuery(document).ready(function(){
jQuery('.datePicker').datepicker({
showOn: 'button',
buttonImage: '/myapp/images/calendar.gif',
buttonImageOnly: true });
});

Then, because the default date format for text inputs in grails is yyyy-mm-dd hh:mm:ss, which is not the most common format entered for dates in my demographic (US), I added a customPropertyEditorRegistrar in grails-app/conf/spring/resources.groovy

beans = {
customPropertyEditorRegistrar(util.CustomPropertyEditorRegistrar)
}

and then in src/groovy/util/CustomPropertyEditorRegistrar.groovy

package util

import java.util.Date
import java.text.SimpleDateFormat
import org.springframework.beans.propertyeditors.CustomDateEditor
import org.springframework.beans.PropertyEditorRegistrar
import org.springframework.beans.PropertyEditorRegistry

public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Date.class,
new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true));
}
}



And then I'm happier, and the data entry staff that need to use my applications are happy.

Dell's OptiPlex 160 - Not that great for linux

The idea of a silent, dual-core, 64 bit solid state workstation seemed brilliant to me at first. I ordered up one of these little machines along with a 16 GB solid state drive and two 2GB DIMMS. I install Ubuntu Workstation 8.10 on it, and away I went.

These one drawback of this machine, which is why I'm not recommending it for use as a Linux workstation, is the video chipset. It comes with a proprietary SiS AVG 771 chipset that has very poor linux support. I've only been able to get basic 2D working at 1600x1200, and only through the VGA port. The DVI port refuses to run at anything higher than 800x600. 3D and 2D acceleration refuse to work.

I have since upgraded the machine to Ubuntu 9.10, but the graphics chip shortcomings still apply.

Next time I go looking for a solid state machine such as this, I'll ensure it has an Intel GPU in it, or at the very least an nVidia or ATI chip.