Programming
Grails boolean saved as BIT
by steve on Dec.30, 2009, under Programming
Depending on the Grails version booleans are stored differently; either as INT or BIT. BIT(1) is a special datatype made just for booleans. However old dogs prefer storing booleans as small int. In order to do this, you have to create a customized Hibernate dialect.
MySQL Example: foo.bar.brewsoftcorp.CustomMySQL5InnoDBDialect.groovy
package foo.bar.brewsoftcorp
import org.hibernate.dialect.MySQL5InnoDBDialect
import java.sql.Types
class CustomMySQL5InnoDBDialect extends MySQL5InnoDBDialect {
CustomMySQL5InnoDBDialect() {
registerColumnType(Types.BIT, ‘boolean’)
}
}
SQL2000/2005 Example: foo.bar.brewsoftcorp.CustomSQLServerDBDialect.groovy
package foo.bar.brewsoftcorp
import org.hibernate.dialect.SQLServerDialect
import java.sql.Types
public class CustomSQLServerDBDialect extends SQLServerDialect {
public CustomSQLServerDBDialect() {
registerColumnType(Types.BIT, ‘boolean’)
}
}
Then add this line to your DataSource.groovy
dialect = util.CustomMySQL5InnoDBDialect //for MySQL
##############################
dataSource {
pooled = true
driverClassName = “com.mysql.jdbc.Driver”
username = “username”
password = “password”
dialect = util.CustomMySQL5InnoDBDialect
}
##############################
Grails 1.2-M3 to 1.2-M4 Upgrade Quirks
by admin on Nov.17, 2009, under Programming
Yes quirk would be the right word.
For the past weeks I have been building an ERP system from scratch using Grails 1.2-M3 using the following plugins;
- Grails Security
- GrailsUI
- ImageToolkit
- Jasper
So when I heard about Grails 1.2’s 4th milestone, I eagerly downloaded it, made the usual changes to my dev PC’s configuration as well as in eclipse and ran grails upgrade via command line. As expected everything works except that my datatable does not work anymore and I could not run grails from eclipse.
After a few hours of digging through the error messages and new M4 configuration, I was able to solve my problem. Here is what I did;
- The grails upgrade command does not modify your project’s ivy.xml. Simple change rev=”1.2-M3” to rev=”1.2-M4”
- It seems that tomcat does not know where to place the javascript folders in the right place, causing grails-ui to misbehave. Go to <HOME>\.grails\1.2-M4\plugins and extract the grails-grails-ui-1.1.1.zip\webapp\js\grailsui folder to your <GRAILS_PROJECT>\webapp\plugins\
- Delete your old project directory <HOME>\.grails\1.2-M4\projects\<PROJECT_NAME>
- Delete all jars under <GRAILS_PROJECT>\lib\build
- Run Clean
To AMF or not to AMF that is the JSON
by steve on Oct.06, 2009, under Programming
Ok I admit the title is corny.
All of the Flex applications that we have written in the past years have been using XML. I mean why not? It is simpler to use, easier to understand and teach to new developers, easy integration with our existing Grails apps via REST/webservice, and most importantly it’s open! What actually scares me is the nature of AMF being a native serialized object built and written for the Flash Player.
But why must this guy post his performance test between XML and AMF (http://www.jamesward.com/census/) and pulls me out of dreamland? Now I am having second thoughts of moving to AMF. Though I am not sure if there are even stable opensource java-amf projects (stable being > 1.x release). The building directory kiosks that we have right now are wirelessly connected to the data server which shares the same bandwidth with the streaming video from the ads server. Performance is a priority in the kiosk as users expect it to perform like a desktop application. Using XML does not only waste a lot of bandwidth, much work is shoved thru the machine to parse the XML file. That was the reason why much study was made whether or not Atom processors were good enough for the kiosks.
There are actually two ways to cross the dark side; out of the XML light. One would be Grails-BlazeDS via Flex plugin. The plugin pretty much does the configuration for you. Just don’t expect flex views! Another way would be to use JSON which has been hanging around with Grails core since < 1.x. This could be a better alternative as JSON is supported by most web programming languages. Though AMF performs better than JSON, as most tests suggest, but the difference is negligible. I guess the deciding factor here is maintenance and which language is easier for developers. I believe it is safe to say that more developers are familiar with JSON than AMF. Hiring devs with Flex-AMF-Java experience might be more difficult for our clients for post production support.
Upgrades are not always good… even for Grails
by steve on Oct.06, 2009, under Programming
I have had numerous Grails projects all written using 1.0. I have been itching to upgrade to 1.1. But as I do a project upgrade, a few of my plugins refuse to work with the new distribution.
Finally two new Grails projects! So I cleaned up my old desktop and downloaded the latest Grails release (Grails 1.1.1). I spent 3 hours digging through the new Grails website for plugins that I can use. I listed down a few promising ones (stark, export, grails UI, tomcat, etc)
So I gave it a test run! I made a sort of online reservation form with export to excel and pdf capability. Out of Grails 1.0 habit I did an upgrade command and to my surprised it failed! Nice! Some hibernate plugins can’t be deleted. Grails clean seems to work perfectly though.
Since my second and third try also failed, I manually deleted the project plugins @ .grails folder. The upgrade command worked this time. But I have to manually delete the plugins for the command to work. Ok no beggie!
So I spent a day testing some plugins. I love the Stark and Jasper plugins. Though you have to use IReport 2.x as the new IReport version does not work with the current jasper plugin. It seems that the jasper engine that grails uses only supports DTD. I did several workaround like adding the old doctype that the engine expects. So to avoid the same hair pulling misery that I had encountered stick with the old, ugly, dtd based IReport designer. Anyway as my journey continues, my small app was working nicely on my dev environment.
After downloading tomcat xampp add-on, we use xampp because we are lazy, I was ready to build my first Grails 1.1.1 war. I did a grails clean command this time via eclipse (ant task target:clean) which finished without a glitch. I wish I could say the same thing with war. Running the ant task gives me a java.lang.reflect.InvocationTargetException build error which usually occurs when the compiler sees 2 different classes with the same name. So again I deleted the plugins at .grails folder ran grails war this time via commandline and it worked! So again I tried running the ant task via IDE same error! Now call me crazy I did this several times and it gives me the same result.
No happy ending with this one. I am not sure if these are known issues and developers are doing workarounds. I have never experience these issues with the old Grails. Maven issues or perhaps plugin developers putting grails jar in their distributions? I don’t know… I am just a programmer.
Perversion and Programming
by steve on Sep.15, 2009, under Fun Stuff, Programming
Sex == Programming
1. Better success with Peer Collaboration
2. Inversion of Control
3. Performance is key
4. After sex/programming support is never fun
5. Best done indoors; in a dark room
6. Everyone wants it to be free and open
7. Experience is your best teacher
8. Bugs are always unwanted
9. Never forget to upgrade!
10. Men are more into it than women