Sunday, December 19, 2010

Using Cisco VPN on Snow Leopard

This is a great blog on setting up your VPN (Cisco IPsec only) on your Snow Leopard machine. Crazy, but neither Mac OS nor Cisco appear to have a supported standalone client.

Thursday, November 4, 2010

Synchronizing Tables in a MySQL Cluster

I created a table in a MySQL cluster but did not fully understand the way a Master-Master configuration operates.  I still don't.  However, it didn't take long to determine that I needed to create the table in each node of the cluster only to find out that data doesn't get synchronized automatically.  Grr.

A friendly DBA informed me that I needed to do this when creating the table:
create table tbl_name (i INT) ENGINE=NDBCLUSTER;
which specifies that this table is to be managed by the cluster. If the table has already been created (as was my case), this can be added after-the-fact:
ALTER TABLE tbl_name  ENGINE=NDBCLUSTER; FLUSH TABLES; 

Monday, May 10, 2010

Snow Leopard and VMWare Fusion 3

This past weekend I installed both, thinking, "hey, upgrades are better, right?"  I did, however, find two crippling problems.  The first pertains to Fusion 3.  When you start it up, it is slower than molasses, and the reason is that Spotlight is told to search your virtual machines.  In theory, it should do this once then be happy but reports have it that it reoccurs each time you start Fusion.  The solution is nicely stated in this post.

The second is that the Cisco VPN client doesn't work anymore.  This is because the current version of the client (4.9.x?...) is not 64-bit capable and it dies upon startup.  The solution is to use the built-in VPN client in Snow Leopard but I've heard the connection can be flaky.

Thursday, January 21, 2010

Configuring Eclipse to use GWT within a Grails project

One nice thing about Eclipse is that it sets up your environments, compile macros and build paths for you when you do, say, File > New > Grails Project. GWT has a similar setup that works just as well and in exactly the same way. However, I'm merging Grails and GWT functionality and want the benefits of code completion, etc.

As mentioned in a previous blog entry, however, the merging of GWT and Grails is not very straightforward and is subject to some idiosyncrasies, including the need to execute Grails commands from a terminal and not from within Eclipse.  For some reason, installing GWT plugins from within Eclipse does not work (my theory has to do with environment variables but I just gave up on it and went with the sure-fire way).

The net effect is that GWT auto-suggest doesn't work.  Nor does auto-creation of import statements.  Bleh.  I found that you can get the former to work fine by right-clicking on the Project name in Package Explorer, then Google > Web Toolkit Settings...  You get the following screen:



Check "Use Google Web Toolkit" then auto-complete (at least) will work.

Tuesday, January 19, 2010

GWT vs. Grails

Both Google Web Toolkit (GWT) and Grails have been in the public domain for about two years now. I admit that my knowledge of, and experience with, both is very recent. When I started to investigate each technology I was very excited about the possibilities, namely:
  • Groovy and Grails provides the rapid-prototyping inherent with "convention-over-configuration"
  • Grails, being a Java framework, fits perfectly with legacy or yet-to-be-introduced Java technologies
  • GWT provides the tools for developing Rich Internet [client] Applications (RIA)
  • GWT, being based on Java, is Google's version of "write-once-run-on-any-browser"
After having spent merely a week on each technology, what follows in this entry is my interpretation and reaction of the above claims and discovery of the "buts..." hidden in the cracks.
First, I found all of the above claims to be true. Second, while both have client-side and server-side capabilities, Grails is the clear winner on the server side while GWT is a marginal winner on the client side. Third, if you want to use GWT and Grails together, the process can be cumbersome but it does work. Let me explain.
Grails:
  • The Object-Relational Mapping, which is based on Hibernate, is absolutely fantastic.
  • Scaffolding is even better than Ruby on Rails IMO because you can combine scaffolding with custom code. If anyone reading this can tell me otherwise about RoR, please feel free to comment politely.
  • Many operations, such as returning a list of objects in JSON format are one or two lines of code.
  • The generated controllers and views are still heavy on the "client-request/server-response" paradigm. A developer wanting to employ AJAX to develop a RIA still needs to install third-party JavaScript libraries and write framework code.
  • The suggested MVC structure doesn't [easily] encourage digressing from the Domain Class structure. For example, you're encouraged to edit a Task on the Task/edit page. However, RIA's are trending towards multi-faceted documents (think iGoogle home page) where a user interacts with diverse information on a single page.
GWT:
  • Creating Web pages by writing Java and compiling for all supported browsers brings RIA GUI creation to the Java purist and reduces testing overhead.
  • Developing a simple, self-contained (i.e., client-only) UI is easy and fun.
  • The Same Origin Policy (SOP) makes rapid development virtually impossible unless you try any of these methods:

    1. Compile your GWT application then copy to the Application server running your database services. If you do a lot of write-test-write-test, this simply is not a solution.
    2. Go through a complex procedure to "get around" the SOP, which only works for GETs. If you want to test UPDATE or INSERT you still need to find a better way.
    3. Develop a complete set of servlets to mimic your backend services.
    4. Use the GWT plug-in for Grails

  • While very powerful indeed, writing AJAX calls using GWT is far more complex than simply writing them in JavaScript.
You can probably sense the theme: Grails is easier to get up and running, but lacks sophisticated UI tools. GWT can do really neat things on the client side if you're willing to invest the time. Mixing the two is possible using the "official" way to integrate the two.

The caveat is that the GWT plug-in for Grails appears to be buggy if you compile and invoke from within Eclipse.  That means you should keep a terminal open for "grails run-app", a terminal for "grails run-gwt-client", and Eclipse.

Any other method doesn't really work very well.

Monday, January 18, 2010

Grails unable to create or alter a SQL table

To get to the point, the lesson learned here is, "be careful how you name your fields". When Grails updates the table schema due to changes you make in the Domain class, Grails returns this cryptic message:

Running Grails application..
2010-01-18 11:19:59,779 [main] ERROR hbm2ddl.SchemaExport - Unsuccessful: create table stock (id bigint not null auto_increment, version bigint not null, change float not null, price float not null, symbol varchar(255) not null, primary key (id))
2010-01-18 11:19:59,780 [main] ERROR hbm2ddl.SchemaExport - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'change float not null, price float not null, symbol varchar(255) not null, prima' at line 1

Obtaining the exact SQL can be tricky, but the cause was in how I named the table columns. When I changed "change" to "changePerc" and "price" to "priceDollars" everything worked.

Tuesday, January 12, 2010

Get MIME types to work in Grails

A powerful aspect of Grails is that you can instruct the server to return data in any number of formats declaratively. For example, when implementing AJAX, you might choose to return XML or JSON to the JavaScript callback function.

This would work fine except Grails, by default, disables this feature, always returning HTML. To fix this, edit: grails-app/conf/Config.groovy and change the "grails.mime.use.accept.header" value to "true".

Tuesday, January 5, 2010

Grails Cheat Sheet

Happy New Year! After a couple weeks of over-doing eating and vegetating, I dropped my mother off at the airport this morning and am jumping back into Grails. Unfortunately, um... I forgot most of what I picked up in December. To help me out, I'm creating a cheat sheet. So I will probably be editing this post to keep the information in one place.

Keystrokes (case sensitive):
  • ctrl-alt-G => open the Grails command line from within Eclipse
  • ctrl-space => auto-suggest
Commands
  • compile => (re)compiles the Grails Application
  • run-app => compiles then executes the current Grails project (development)
  • create-domain-class [class] => create a domain object (lower-case, singular)
  • create-controller [controller] => create a controller (lower-case, singular)
  • generate-all [Class] => generate default controller and view for the domain object
  • install-templates => generates the scaffolding templates for customization
  • install-plugin gwt => readies your application for use with GWT (or any other plugin like Hibernate)
  • create-service [class] => creates a service for the class (lower-case)
  • create-gwt-module => creates a GWT EntryPoint application
  • create-get-page => creates an HTML/GSP page to associate with the module EntryPoint
  • run-gwt-client => opens the GWT client manager and starts the Hosted Mode browser
  • compile-gwt-modules => (re)compiles GWT code. Required if you want to refresh the browser with new GWT functionality
Tutorials