Wednesday, March 15, 2006

More Progress On "Vanilla DAL"

Today I added support for transactions and stored procedures to project "Vanilla DAL". This took less time than expected. Transactions are built on top of so called units-of-work (despite the name, no nested transactions here), which follow a simple action pattern. So for the caller, a typical transaction looks like this:

UnitOfWorkList list = new UnitOfWorkList(
    new ExecuteNonQueryUnitOfWork(
        new NonQueryParameter(
            newStatementID("DeleteTestCustomers"))),
    new UpdateUnitOfWork(
        new UpdateParameter(
            northwindDataSet.Customers))
);
accessor.ExecuteTransaction(list);


... where...

public interface IUnitOfWork {
    void Execute(IDBAccessor accessor, IDbTransaction
    trans);
}


So when I think it over it's more a visitor- than only an action-pattern... ;-)

Stored procedures on the other hand caused even less effort thanks to the beauty of the ADO.NET API. Actually I didn't have to change any code at all - all that was necessary was editing the configuration-file like this:

<Statement>
  <StatementType>StoredProcedure</StatementType>
  <ID>CustOrderHist</ID>
  <Code>
    <![CDATA[CustOrderHist]]>
  </Code>
  <Parameters>
    <Parameter>
      <Name>CustomerID</Name>
      <Type>NChar</Type>
    </Parameter>
  </Parameters>
</Statement>


With improved error handling finished as well, I should soon reach a state that allows me to publish a functional prototype on sourceforge.net - enough for people to download and play around with, certainly not ready for real-life projects yet. Anyway, by now Vanilla DAL comes with a SqlServer reference-implementation only - support for other DB vendors will follow later.

So during the next days I have to set up the build process using NAnt, write some documentation and tutorials, and finally downgrade to .NET 1.1. This means giving up generics as well as ADO.NET 2.0 features, but it would be much worse to exclude all developers who still work under .NET 1.1.

By the way, NAnt does not support .NET 2.0 yet either. I also don't intend to learn MSBuild just for the sake of getting this build working.