Nov 25 2009

NHibernate 2.1.2 released

Category: Uncategorizedzvolkov @ 11:26 am

Silently, the NH community released version 2.1.2 of NHibernate and its side-kick projects.

The NHibernate and NHibernate LINQ binaries are available on Source Forge and NHContrib 2.1.2 can be downloaded from NHContrib section.

The changes since 2.1.1 seem very minor, however, if you missed version 2.1.1 now may be a good time to upgrade, as 2.1.1 fixed many important bugs. See release notes for more details and complete list of changes. I did not check all the side-kick projects for changes, only the ones I use. What I see is one bug fixed in NH Linq in 2.1.2 (plus ~20 fixed in 2.1.1) and one change to SysCache2 provider adding support for defining a command timeout.

UPDATE: There’s also a matching version of NHibernate Lambda Extensions for Criteria API released.

Please note that if you use any third party libraries referencing NH 2.1.0 (e.g. Spring.NET 1.3) they may start failing during assembly binding resolution. If that happens, you can use the binding redirect like so:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NHibernate"
                          publicKeyToken="aa95f207798dfdb4"
                          culture="neutral" />
        <bindingRedirect oldVersion="2.1.0.4000"
                         newVersion="2.1.2.4000" />
      </dependentAssembly>
    </assemblyBinding>
</runtime>


Nov 10 2009

Back to the future: return of Norton Commander

Category: Uncategorizedzvolkov @ 10:19 am

While I used Norton Commander 3.0 and 4.0 a lot, by the time of 5.x I was off NC and on its clones: Volkov Commander (VC) and DOS Navigator (DN). I think it was DN that first showed me how productive an integrated environment can be. Although late NC and its clones supported mouse (which was a funny name back then) the screen resolution in text mode was too low to support rich point-and-click UI. Keyboard shortcuts were the name of the game, shortcuts and context-sensitive shortcut-activated plugins (right-click menus were not yet invented)

When Windows 3.1 came out its mouse-based interface was still too cumbersome, and I remember occasionally switching back to NC for a super fast session of file management. It was Netscape Navigator that forced the permanent switch to point-and-click mentality. Even though I hated Windows Explorer, for some reason I blindly trusted Microsoft’s vision of desktop productivity. It was not until yesterday that last remnants of that early hypnosis fell away. I realized I don’t like using the mouse. For web browsing — yes. For graphic editing — perhaps. For desktop productivity — not anymore.

The comeback started with Resharper (a plugin for Visual Studio) and Find and Run Robot (aka FARR)  (a keyboard-based program launcher). After a few months of using these, and learning a few Windows shortcuts along the way (Win+E, Ctrl+Shift+Esc) switching to mouse felt increasingly painful. I realized the point-and-click mentality is by definition lazy and leads to passive way of thinking. Instead of making the computer do what I want, I have to go through a series of approximations: Minimize all windows, click on My Computer, what was I going to do?

Not so with Norton Commander. My hands still remember the shortcuts. Alt+F1-C to open the C drive. Press * to select all files. F8 followed by Enter to delete. Now we’re talking!

  • While there are many NC clones out there, the most actively supported one is FAR Manager – get yourself version 1.75 in 32-bit flavor (64-bit is not compatible with many plugins, specifically the 7-zip plugin I will talk about next. Note that 32-bit version of FAR works perfectly fine on 64-bit Windows). Extract into Program Files (x86)\Far and create windows shortcuts as needed (I use FARR launcher for ultimate mouseless experience).
  • Next you will need 7-zip plugin, it will let you Enter into .RAR and .ZIP files (and many others). Go to 7-zip.org and get 32-bit version. Also get the plugin for FAR Manager (a separate download on the same page). Follow instructions in far7z.txt for native 7-Zip FAR Plugin (don’t bother with MultiArc). Do copy 7z.dll from where you installed 7-zip over to the plugin folder.
  • Although the default color theme brings back good memories, you may find it too bright comparing to most modern programs. If that is the case, FAR comes with a choice of alternative schemes, the one I like is this greyish scheme; copy the .reg file to Far\Addons\Colors\Custom Highlighting\ and import it using import_colors.bat (Far should not be running)
  • Go to console window properties (Alt+Space -> Properties and Alt+Space -> Defaults) and change the font to 10×18
  • In FAR, go to Menu (F9) -> Options -> Panel Settings and uncheck “Show hidden and system files”.
    • Also, check “Select Folders” — now you can invert file selection using * button on the numerical keyboard.
    • Also, check Show Scrollbar.
    • Now, go to Menu -> Options -> Interface Settings and check “Show total copy progress indicator”.
    • Go to Menu -> Options -> Confirmations and uncheck “Delete non-empty folders” to disable second confirmation for folder deletion; also uncheck “Exit” confirmation as well.
    • Another one: goto Menu -> Options -> Viewer Settings and check “Show Scrollbar”, do the same for Editor Settings.
    • Finally, do Menu -> Options -> Save Setup to save the changes (or you can turn Options -> System Settings -> Auto Save Setup).

Now, Norton Commander is something you either know how to use or you don’t, so I will not go into details except the ones specific to using it in the Windows environment:

Press Ctrl+1,2,3,4,etc to switch the columns displayed on each pannel (use Tab to jump between the planels). I settled on Ctrl+2 which displays 2 columns instead of three. Press Alt+F9 to maximize the window to fill entire screen, press again for the normal size. Most other commands can be seen in the bottom bar (hold Ctrl, Alt or Shift to see them) or in the menu.


Nov 02 2009

NHibernate parameter sizes controversy: trust but verify

Category: Uncategorizedzvolkov @ 7:56 pm

After my first correction of the original post, on 11/2, Naz replied to the NH thread. He clarified that prepare_sql is in fact NOT defaulted to true in NH 2.1, and so the users will still have to make this configuration change by hand.

The same day, Trent Niemeyer in a comment to my blog post corrected another Carsten Hess’s statement and informed me that (at least in v2.1) NHibernate does NOT ignore length attribute in the mappings and that undocumented type=”String(100)” syntax is no longer the only way to effectively specify the length of query parameters.

I just verified both news and found them to be correct (and their original counterparts, correspondingly, wrong). As V.I. Lenin once said: “Trust, but verify!”

To summarize, all we need to do is:

  1. set prepare_sql to true
  2. (optional) add type=”AnsiString” and length=”LENGTH” to mappings of string properties to make NH use varchar(LENGTH) instead of nvarchar(4000) for most basic queries
  3. Keep an eye on more complex queries and be ready to use the overload of SetParameter that takes TypeFactory.GetAnsiStringType(LENGTH)

The reason prepare_sql is an opt-in feature is because it may change behavior of existing applications. Still, it is highly recommended that users of MS SQL Server set it to true, to avoid the query cache pollution. The alternative solution — the SqlDriverOverride hack — can be employed to keep the NH-generated SQL queries visible in SQL Profiler every time they are executed, and not once per connection, which is what happens when prepare_sql is set to true.


Nov 01 2009

NHibernate parameter sizes controversy: happy ending

Category: Uncategorizedzvolkov @ 6:22 pm

This post is a follow up to my previous post, digesting the facts and opinions on the infamous NHibernate parameter sizes controversy. I have also updated the ending of the original post, for those archeologists of the future who will research this topic.

Only two days after my original post, and four days after Daniel Auger’s new thread on NH user group, on 10/30, Carsten Hess came back with a statement that turned the story on its head. According to his findings, execution plans generated by sp_prepexec ARE actually global and not per connection (unlike he said before), so having prepare_sql=true does not cause query cache pollution, at least not in NH 2.1 (apparently NH 2.0 may still have some issues since some parametrization defects were not fixed until 2.1). Among other things this means we no longer have to override GenerateCommand in SqlClientDriver to always call SetParameterSizes, as that’s what NH 2.1 does by default, with prepare_sql set to true. This also means Fabio and Ayende were right in their downplaying of the issue, even though I still think they did a bad job communicating their position to the public (something I can’t help but attribute to cultural differences).

That said, if your DBA requires your app to be SQL Profiler-compliant (and he has every right to demand that) you may have no other choice but set prepare_sql=false. In that case the following hack will make NH use fixed parameter sizes while keeping NH queries visible in SQL Profiler:

  1. set prepare_sql=false in NH settings
  2. Create you own class inheriting from SqlClientDriver and override GenerateCommand to always call SetParameterSizes:
    using System.Data;
    using NHibernate.Driver;
    using NHibernate.SqlCommand;
    using NHibernate.SqlTypes;
    
    namespace XXX.YYY.ZZZ
    {
        public class CustomSqlClientDriver : SqlClientDriver
        {
            public override IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
            {
                var command = base.GenerateCommand(type, sqlString, parameterTypes);
                SetParameterSizes(command.Parameters, parameterTypes);
                return command;
            }
        }
    }
  3. set connection.driver_class to assembly-qualified name of your custom driver implementation
  4. (optional) add type=”AnsiString(LENGTH)” to mappings of string properties to make NH use varchar(LENGTH) instead of nvarchar(4000) for most basic queries
  5. Keep an eye on more complex queries and be ready to use the overload of SetParameter that takes TypeFactory.GetAnsiStringType(LENGTH)

To conclude the post, here are the lessons I learned from this story:

  • If you think you’ve found NH 2.1 does something stupid that will kill your production server you’re most likely wrong. NHibernate 2.1 is a mature enterprise-ready ORM with most major wrinkles already ironed out.
  • If your customer community thinks your product has a bug and you know it does not, they will do their best to fix it anyway, unless you take time to explain there is no bug.
  • In serious organizations the DBAs are a big power, better have them as your friends.
  • Blogging about programming controversies is not the best way to drive traffic to your website. Breaking news work better and are much easier to make.