Thursday, 3 April 2008

nHibernate - Filter and Criteria for applying dynamic where clause

Over the last few days I've been getting my hands dirty trying to get dynamic filters working with nHibernate. As a future reference I've decided to post my notes.

The final solution makes use of Filters and SpringFramework, IMHO both tools that you cannot do without when working in Java or .Net.

Requirement
The system has complex WebServices exposed which provide data intensive processing based upon parameters provided in complex XML. The .Net framework deals with serialization of the XML into objects, the requirement is to apply filter conditions only when a parameter is supplied in the XML. It is essential that maximum reuse of code is maintained.

Options



  1. Write a data access object with lots of if statements. The code would need to generate a string that forms the where clause of the select statement.

  2. Use nHibernate ICriteria or IFilter objects to apply the conditions to the SQL.

Option 2 was the method of choice with little thought for option 1. It was felt that option 2 would provide a more modular approach. Now to the point of this blog entry, there are subtle differences between ICriteria and IFilter, and I would recommend using IFilter which I feel is much more powerful mechanism for controlling the data returned in the object model.

ICriteria
produced cartesian joins so did not truly reflect the object model. For example if you have a Order object that can contain many OrderLines you expect the ORM to produce one Order object that contains many OrderLines. Using Criteria in nHibernate produced many Order's (1 per OrderLine) and each Order contained the correct number of OrderLines. The more Criteria applied to the query the bigger the result set became. Also, objects returned using Criteria that contain Bags, Sets or Maps had the collection object populated without applying any filtering.

It was at this point that I decided to focus my attention on the Filter functionality provided by nHibernate and it worked perfectly.

IFilter requires a little more effort in terms of code and producing the hibernate mapping documents but it is well worth the effort. The filter ensures that only the required objects are returned and that Bags, Maps, and Sets are correctly populated with filtered objects. A filter is applied to the session and the same filter defition can be used on many objects. Individual filters can be enabled or disabled as necessary.

Solution
The solution was to implement each filter condition in a object that determined if the filter should be applied. The filter class retrieved the parameter value originally passed in the XML and applies the filter condition, nHibernate dealt with correct SQL syntax for the where clause. Each possible filter condition is put into its own class and the chained together in a IList object which is iterated over by a control class. The configuration of control class and filter classes is done in SpringFramework so as to provide maximum flexibility.



SpringFramework provides a flexible means to add or remove filters from a control class.

foreach (AbstractParamFilter paramFilter in commonFilterList)
{
paramFilter.ApplyFilter(accountingParams, session);
}

The filter classes implement either a Interface or Abstract class thus providing the polymorphism.

Each implemented filter class is implemented to decide if the filter should be enabled or disabled based upon the content of the object passed to the filter.

The NHibernate configuration needs to have a filter definition provided for properties or collection objects as shown below.

Finally a filter defintion and the parameter for the filter need to be defined in the hibernate mapping files.
NHibernate chapter 14 provides the documented detail of what to do, I personally do not believe the chapter describes the full benefits.

Wednesday, 26 March 2008

Why use AJAX in the enterprise?

It appears that Forrester Research Inc may have upset a few AJAX people out there by claiming that power users are less than impressed with AJAX in the enterprise (see "AJAX-powered Web apps disappoint power users, Forrester says"). That's not really news at Altio., for a long time we have been aware that the Enterprise power user can be extremely demanding.

Creating a Enterprise application for the browser requires the following at a minimum
  • Responsive user interface

  • Ability to work with large volumes of data

  • Provide all the features expected from a desktop application, which probably means interacting with other desktop applications.

The computerworld article quotes:

" most AJAX frameworks tend to keep all real business logic on the server as opposed to local systems, user interactions may require a roundtrip communication between the browser and server for each input field"

I'm not sure how true this is, I guess JavaScript would need to do this to ensure it maintains performance. Altio does not have this issue and allows for client side validation without any additional performance overhead associated with server roundtrips.
"Some large applications could easily have 50 fields on a single screen."
This statement seems to have caused quite a stir, resulting in a number of strongly worded comments. I would agree that 50 fields does seem like an extreme GUI and probably breaks a lot of usability and GUI design rules but I have seen a number of Call Centre application both in the UK and Far East which have a lot of complex screens with many input fields, including editable lists on one screen (maybe not 50). Sometimes the nature of the business domain requires this. So technical purists who maybe have little business knowledge probably needed to tame their comments a little. It is the business that drives IT demand, it is down to people working in technology to meet the business demands, not enforce technical constraints on business users.

"As a result, AJAX developers told Forrester that they had to reduce real-time input validation compared with traditional rich clients to meet performance requirements. Real time input validation is a top priority for power users, the report said."
Well why not consider Applet based technologies. Applets provide a rich user experience all within a browser, the best of both worlds. I was surprised that the report summary only discussed Adobe and Microsoft Technologies. This shows a lack of knowledge of what Sun are doing in Java 6 with the new Java plugin and Java FX.


Altio and AJAX are similar in that they both interpret the business logic - Altio has it's own XML meta language that defines the logic while AJAX uses Javascript. Altio does provide a flexible means to manipulate data and interact with screens, in addition to this it comes with its own integration layer enabling rapid application development.

It could be argued that Applets have restricted memory because of the Java sandbox, but this will no longer be the case with Java 6 where it will be possible to request more memory from the operating system.

Overall I feel a lot of Analysts and the developer community are ignoring Applets as a technology due to its poor history. I feel that Applets should be used in Rich Enterprise Web Applications, and Sun need to advertise the power of Applets with the new support of Java 6. There are enough Java developers and using a tool like Altio abstracts away the complexity of understanding Swing and AWT.

Tuesday, 18 March 2008

How to setup a HP C4380 with an Orange Livebox

In my previous entry I mentioned my experience printers and setting up a HP C4380 with an Orange Livebox.

The one thing you need to make sure you do is press the number "1" button above the USB port. This enables the discovery mode of the Livebox which adds the printer to the MAC address list. By default the Livebox stores registered equipments MAC address and so printers or laptops etc cannot connect without an entry in the MAC address list.

So if you setup the printer using the HP software, it will say that the installation was successfully but may not allow you to print. I resolved this by pressing the "1" button on the Livebox, turned off the C4380 and turned it back on and I could then print wirelessly as the printer could then get a IP address.

A new printer for home

I've just had a very interesting weekend purchasing printers.

My requirements were
  1. Cheap to run
  2. Capable of printing photos
  3. Worked remotely (bluetooth or WiFi)
  4. Would work with Apple Mac and Windows (XP and Vista)
I personally didn't think these requirements were too demanding.

My first mistake was to go out and buy something without researching (I was in a bit of a hurry, which is my excuse), normally I would research quite a bit before buying computer hardware.

I'd previously read several articles in photography magazines about all in one photo printers, and felt that was a good option as it would save desk space (scanner, printer, copier all rolled in one). So I bought a Kodak 5300 , my reasoning for this was that it was advertised as being 50% cheaper than all its competitors, great the kids can print and print without me breaking out in a cold sweat. I would need a bluetooth dongle to go wire free but I had one lying around somewhere so that shouldn't be a problem.

So I get home and begin the installation on my Apple Mac and the problems begin:
  1. Says compatible with OSX 10.4.8 and above - well I'm on 10.4.11 and the installation software flatly refused to accept that 10.4.11 is newer than 10.4.8. So off I go to the Kodak web site and download a newer installer, problem resolved. The software installs fine, and I can print using the USB port.
  2. Next problem, as with all new things I like to test them. So I try the scanner and it actually locks up my Apple Mac ( and I mean really locks it up, I had to turn the Mac off). Back to the Kodak site and download and install firmware. At this stage I'm wondering if I have made a mistake here.
  3. Third problem. I plug the bluetooth adapter in thinking surely no more problems. Oh how wrong I am. Nothing can see the printer, I even tried my mobile phone. So I go back to google to see what I can find out, and guess what the only bluetooth dongle supported is the Kodak one, which you can't buy from the shops and have to order (I wish it had been more specific on the box).
At this stage I gave up and go back the PCWorld to request an alternative printer, expecting to have a fight on my hands I make sure I have my list of reasons why they should exchange. I was gob smacked the tech support guy just turned around and said no problems the printer doesn't do what is says on the box so all I can do is recommend a HP printer, that will work. Wow and big thumbs up to PCWorld for a hassle free exchange.

So I get a recommendation of a HP C4380 and I start the process all over again.

Install the software on a Mac using the USB port, prints and scans fine.

Disconnect the USB port and connect the printer to the Wirless Router, and try to print from the Apple Mac that worked but also I can scan images remotely as well (bit daft because I have to walk from one room to another to do it, but it's still a neat trick to impress the kids). I'm well impressed so far, well done HP for a superb product. Not so well done Kodak, I think you need to sort out you design specs. I can live with slightly more expensive ink cartridges if everything else works.

By the way my next blog will be about getting a HP C4380 working with an Orange Livebox

Saturday, 8 March 2008

Last FM Altio graph demo




Tom Martin one of the Altio development team put together a LastFM demo using the Altio Graph control, you can see Tom's blog entry here Altio Last FM demo

Monday, 3 March 2008

February Roundup

Better late than never..... one day I will have time to do the summary of the month when the month ends.

IDE's Microsoft Visual Studio 2005 vs Eclipse
So I'm now well into .Net web services, although I have to say I do think Eclipse wins the best IDE competition. My distant past when using Visual Studio was my staple diet for cutting code must of blurred into happy memories.... reality has hit home - the autocompletion doesn't quite cut it when compared to Eclipse.

Other things that have come on the IDE scene is a new AJAX designer if there are anymore AJAX tools out there I can't see how people will decide where to look, why not try AltioLive it's not AJAX, it's not silverlight it's a full on Enterprise RIA, the IDE is written in Altio "so we live by what we preach" :-)

Visual Studio 2005 and Webservices
While I may not be impressed with the VS 2005 IDE I have to say getting a new web service up and running was impressive. I'm pushing the idea of Web Service Contract First (WSCF) and came across WSCF by Thinktecture. It does just what it says on the box, point at a XSD create the code and the WSDL. Although I didn't use the WSDL generator and depended upon the code generated by VS.

Enterprise RIA
Talking of Enterprise RIA Curl have a good article on the power of Applet based technology over AJAX and Macromedia Flash, just replace Curl with Altio and you get the same thing plus a lot more (IMHO our IDE and user interfaces are better - that's my view and not my employers, just in case there's legal issues here)


Google social graph
http://code.google.com/apis/socialgraph/
http://code.google.com/apis/socialgraph/terms.html
I'd like to see what AltioLive can achieve with the new graph control to display social networks.

Into March
March is ramping up to be manic..... the developers on Altio 5.2 are pushing hard to have a Beta release in March, it's that 95% complete syndrome.... the odd horrible bug that just doesn't want to go away.

Oh and by the way if anyone does read my rants come visit me at JavaOne in San Franciso this year.... a few of us from Altio have decided to setup a stall and shout about how great Altio is.

Sunday, 10 February 2008

End of January beginning of February

Boy, how time flies, I can't believe it's the middle of February already and the year is moving fast. The team working on Altio have released Altio 5.1.4 which is probably the last release of Altio 5.1 before we release Altio 5.2. Just to make me even busier I spent the first week of February in Boston initiating our latest project for Paragon using PRINCE project management and building a system using Altio with a SOA architecture.


The project kick off in Boston went really well with the documentation being received extremely well so now all involved in the project know about:
  • the vision
  • the objectives
  • delivery gateways
  • quality plans
  • project tolerances
  • staff involved
All because we have a Project Initiation Document (PID), which while it was hard work to produce I hope will provide value through the project lifecycle by ensuring the project is delivered on budget and on time.

Some in the teams are horrified at the amount of documentation we are producing to start our new projects, while we're all keen to do PRINCE project management now it is understood I feel I have a lot of pressure for it to succedd as it's my idea.

Why is the organization adopting a formal project management technique? Well it's because we want to provide effective communication to all stockholders in projects and to remove as much ambiguity and as many assumptions as possible that are typically made at the beginning of the project.

For the people doing the clever work of writing code and delivery functionality there will be little change, we will continue to use Agile methodologies.

In the end it means people in the company can continue laugh about my Burndown charts as well as now laughing about delivery Gateways. Ultimately the quality of our software is improving along with the ability to better predict the delivery dates of our projects and if testers and developers morale is kept high by laughing at me I can't complain :-) .

While the project will be a major challenge everyone
is keen to see it succeed as it brings together everything Altio is about, a graphically rich and interactive front end with a Service Oriented Architecture (SOA) at the back-end. When Altio 5.2 is released (due May) users will have the ability to make use of Altio's data mashups as well as screen mashups - we aim to really challenge the idea of what makes a RIA and set the benchmark high.

So Altio 5.2 is well on it's way to being delivered in May and will bring a whole new designer and set of controls... I will add more on this in a later entry.