Wilson.ORMapper gets a few small updates

I’ve finally gotten around to updating the public open source version of Wilson.ORMapper to match the release formerly known as Subscriber Preview Revision 10 in the SVN repository matches the original, but includes the non-restrictive open source license.

I then went one step further — adding a patch which fixes a known bug in WORM. This patch also fixes unit test failures in WilsonORWrapper, which has also been updated to reference version of WORM — the first truly official public release that has some code not provided directly from the original creator, Paul Wilson.

Check out the Google Code project at http://code.google.com/p/wilsonormapper/, or discuss on the WilsonORMapper Google group.

Castle Project has gone RC3

So much has changed since RC2, it makes RC2 look like a beta. 🙂

I’m happy to say that I’m not just a user of Castle projects, but also a contributor (having sent in a few patches related to the Castle Validator).

With RC3’s features and stability, and a nice easy Windows installer available on SourceForge, there’s no excuse for you not to start exploring the power that the Castle Project libraries can bring you.

The NHibernate optimization debate: partial object queries

Aaron (Eleutian) and Oren (Ayende) have a little backandforth going about optimizing NHibernate. I’m no expert on NHibernate, but I do have experience with O/R mappers and even more experience with raw databases and SQL, and on techniques for improving performance on both, so I feel I could chime in at least in one area of their debate…

Partial object queries

Let me bring you up to date:

  • Aaron wants to run an NHibernate query of select u(Username, Email) from User u and get a User object with only those two fileds filled in.
  • Oren says you can do it: select new UserSummaryDetails(u.Username, u.Email) from User u.
  • Aaron disputes that as a solution, since it returns a UserSummaryDetails object and not a User object, which would require him to rewrite methods that work on a User object but only use a subset of fields (he mentions a SendMailTo method which uses only the username and email).

There’s a solution that perhaps can perhaps make both happy. You specify an interface (IEmailInfo) that exposes the Username and Email properties, implement that interface in your User and UserSummaryDetails classes, and use the interface on your SendMailTo method? At least, this seems plausible considering my limited (but growing) NHibernate exposure, and would work in other O/R mappers (like Paul Wilson’s).

Either way, keeping up with the aforementioned blog debate is a good way to understand the inner workings of NHibernate.

ComputerSims Baseball: Powered by MonoRail and ActiveRecord

For the past seven years, I’ve been maintaining an online baseball game, CSFBL (Computer Simulated Fantasy Baseball League). It’s gone through many changes over the years, but its core is in many ways unchanged since 2002 — and therein lies a problem.

Back in 2002, CSFBL was getting about 50,000 to 100,000 page views per month. By the end of 2003, we were simulating about 1,500 games per day. Today, we get about 4 million page views per month, simulate up to 10,000 games per day, and have over 80GB of historical data (roughly 6 million games spanning 2,700 seasons). That’s significant growth — and the game is suffering as a result. It wasn’t built to scale this far – a victim of its own success and my own limitations as a programmer circa 2002.

I realized long ago that a rewrite from the ground-up was necessary. I’ve done extensive work rewriting the database schema to maximize efficiency, but that’s only part of it — I need to rewrite the web site and simulation engine as well. (They currently run on classic ASP and Visual Basic, respectively.)

Originally, the rewrite was going to use WebForms — but that changed when I found MonoRail. Up until two weeks ago, data access relied on Paul Wilson’s O/R Mapper (WORM) and WilsonORWrapper (WORW) — but I just completed the switch to ActiveRecord.

Why abandon WORM/WORW? Three reasons:

  1. I was concerned that I’d run into situations where I needed more power than WORM could provide.
  2. NHibernate and ActiveRecord have incredibly robust communities that dwarf those of the alternatives.
  3. I needed to pick my first ActiveRecord project. 🙂

I still think WORM/WORW are valid choices, but the scope of CSBB is potentially huge, and I knew I needed to follow the leader.

Converting to ActiveRecord was straightforward (one O/R mapper to another), but I did run into one frustrating problem. I had a problem persisting one ActiveRecord classes. Attempting to save it didn’t throw an exception; rather, it just sat there, as if in an endless loop. I traced the call to an NHibernate method call by ActiveRecord, but couldn’t figure out why it wouldn’t do anything. Turning on logging, I recognized the problem: one of my fields (a not null field in the database) wasn’t marked with the [Property] attribute, so it wasn’t included in the INSERT statement. Running the SQL code in MySQL Query Browser threw an error, but not in NHibernate. Frustrating, and possibly an issue with the MySQL provider for NHibernate, but at least I know what to look out for if I see a similar problem in the future.

Still, it feels good to be in the hands of MonoRail + ActiveRecord for the most significant independent, most rewarding, and most unpaid development project of my life. 🙂

A repository that works with multiple O/R mappers — is it possible?

A recent post on the WilsonORWrapper Google group talked about making WORW multi-database aware by removing static classes and singletons. Well, I’ve kind of been thinking of something similar lately…

For some time I have been toying with the idea of rewriting WORW to support a generic repository service that would work with any O/R mapper, much
like the logger and cache services work over different underlying libraries. By removing the static classes and singletons and adding a provider model for the O/R wrapper element, you would be able to instantiate multiple instances of a “Registry” class, a class which provides a set of services (Repository, Cache, Logger, etc.) based on a given configuration criteira.

As a test I wrote up a simple project (with unit tests!) as a proof-of-concept, using WORM and NPersist as underlying O/R mappers. The WORM part worked fine. The NPersist part almost worked — however, I believe the errors are related to using NPersist’s not-too-well-documented XML provider, not errors with the O/R mapper provider itself (NPersist does initializes properly, which indicates at least something is working right).

If you’re interested in seeing this little stub of a project, download the source (27.5kb). I’ve dubbed it NRepository right now, not for any reason except it’s the first thing that came to mind. Let me know what you think, and whether you think it’s worth pursuing such a project.

Performance tweaks and bug fixes to WilsonORWrapper

A minor update today (with one breaking change) to WilsonORWrapper:

  • BREAKING CHANGE: Renamed RetrieveTotalRecordCount() to GetObjectCount().
  • Implemented SQL2005 paging support by passing dummy where clause when none specified (they are required with SQL2005 paging); this is a hack, not a fix; you should always specify a sort clause when using any paging operation!
  • Cached value of EntityBase.IsReadOnly on first load; allowed dummy set operator to permit ObjectDataSource usage.
  • Improved IdentityBase.GetHashCode performance with single column keys.
  • Refactored to ensure mapping file stream is disposed.

Thanks to Michael Mepham for help in identifying and resolving these issues. The latest source code is available in ZIP format; no compiled binaries yet.

Wilson.ORMapper subscriber source code repository

Many users of Paul Wilson’s O/R mapper (“WORM”) know that there are a number of community-provided patches which are out there but not incorporated in any official release. Personally, I have maintained a copy of the source code in a private Subversion repository and incorporated a number of these patches for my own use. (Access to the full source code of WORM require you to pay a very reasonable $50 “subscriber fee” to Paul Wilson.)

I contacted Paul Wilson yesterday, asking him if he’d let me grant access to this repository to people who are WORM subscribers. Fortunately for all involved, he said yes!

What does this mean for you? If you are a subscriber to WORM, you can send me your full name and email address and request access to this private repository. I will confirm your subscription with Paul and grant you access.

The following changes have been incorporated into the aforementioned WORM instance:

The purpose of opening up this Subversion repository to subscribers is to give us all a place to share and contribute to a central copy of WORM that includes all the improvements and patches we maintain individually.

If you want to participate, send me your full name and email address.

First community patch applied to WilsonORWrapper

Hot on the heals of yesterday’s update, I just received and applied the first community patch to WilsonORWrapper.

The patch, from Wayde Gilliam, adds the following:

  • Added MemberPrefix option to mappings generator, allowing member prefix (private field) customization
  • Added SetProperties method allowing dictionary-based changes
  • Added IncludeList option to mappings generator, allowing selective table inclusion (combines functionality with IgnoreList)

Hats off to Wayde for a well-written patch!

Release 43 (download source code) has the aforementioned changes, as well as an update to the readme file which gives kudos to Wayde and to Gunter Spranz, an early-adopter of this project whose insight and input was invaluable in the development of the product as we see it today.

Thanks to both — and don’t forget to go ahead and send in your own patch!