Wednesday, January 27, 2010

Business Primitives in Software Development

Great introduction to Business Primitives when designing your applications:

The basic premise is to not only get you speaking the language of the business, but to make your method signatures easier to understand. For example, in a financial application that has a pricing class you might see a method signature similar to the following:
double getPrice(String)

Without diving into the source or docs, it's not immediately clear what the parameter represents. It could be a ticker, it could be a CUSIP. By creating a single value primitive such as Ticker, the method signature becomes:
double getPrice(Ticker)

Wednesday, January 13, 2010

SQL Server 2008 on Windows 7 - Restart Required

An install of SQL Server 2008 on my new Windows 7 64-bit Pro setup was going great until I went to install SP1. The update check failed kept failing with Restart Required even I rebooted several times.

I decided to uninstall the 64-bit version of SQL Server and try the 32-bit version to see if the same issue is present. It may be but I couldn't even uninstall. Same error. Here how to fix:

Open Regedit.
Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
Rename PendingFileRenameOperations to PendingFileRenameOperations2

Don't restart. Proceed with the SP1 install or uninstall.

Thursday, January 07, 2010

Solving Errors with Netbeans Faces 2.0 CRUD Tutorial

Finally had some time to sit and go through what's new in Java EE 6. I opted for the latest Netbeans version 6.8 with the bundled Glassfish v3 app server. The quickest way to get started.

There is a lot of good documentation available on-line as well as several tutorials exploring various feature of the new platform. The first that caught my eye was Generating a JavaServer Faces 2.0 CRUD Application from a Database

The tutorial runs you through how to generate a lot of boilerplate code for a standard crud app in Netbeans that I was really excited to see, having been spoiled from what's available in VS in the .Net world. I came across a few minor issues preventing the sample app from fully working. If these errors look familiar, here's how to fix them.

The first results from trying to create or edit a Client:

An Error Occurred:

clientPK.clientName

- Stack Trace

java.lang.IllegalArgumentException: clientPK.clientName
...
This results from the string "clientPK.clientName being used in the id fields if h:inputText

h:inputtext id="clientPK.clientName" value="#{clientController.selected.clientPK.clientName}" title="#{bundle.EditClientTitle_clientPK_clientName}" required="true" requiredMessage="#{bundle.EditClientRequiredMessage_clientPK_clientName}"/>


Change this id to clientName. Also change it in the line above in the h:outputLabel. Make similar changes for ClientDepartmentNumber in the same file. There is a similiar change required in project/Edit.xhtml and project/Create.xhtml for projectName

This got me to the client create screen, but when trying to save, I was greeted with

An Error Occurred:

/client/Create.xhtml @19,256 value="#{clientController.selected.clientPK.clientName}": Target Unreachable, 'null' returned null
The 'null' here is clientPK within the selected client entity in the client controller. The prepareCreate in the clientController creates a new Client but the contained clientPK remains null. I would typically check for this condition in the accessor and create the object if null, and actually still do. Looking at the generated code I found a constructor that takes a clientPK as a parameter, so simply changing the instantiation in clientController.prepareCreate to:
current = new Client(new ClientPK());
took care of it.

Here is an excellent 3 part overview of what's new in Java EE 6: