HaterAide ORM updated to 1.6

I've been quite for a while. The reason for this is two fold. First, I've been on vacation for a while with minimal access to the internet. The second reason is I've been working a lot on HaterAide ORM. For those that never read the series, HaterAide was a learning project for me. I wanted to see how difficult it was to create a basic ORM, what the "magic" was behind them, etc. I find that recreating the wheel is the best way for me to learn something and I've definitely learned a lot thus far from working on it. Since the initial postings and release it has added a number of features that put it up to the level of half way decent (we're even using it at my work now). This release added a number of features including:

1) Added transaction support
2) Added paging support
3) Added ability to override the default table and column names
4) Added ability to mark the database read only or write only
5) Added ability to do batch saving (calling Save when sending in a list of objects will save the entire list in one transaction).
6) Speed increases for all IEnumerables.
7) General speed increases for saving items.
8) Non int/GUID primary keys now work.
9) Size of DLLs reduced considerably.
10) Added the ability to save an object as a sub type.
11) Solution is now Visual Studio 2010
12) Separated database config data so that in the future multiple databases can be supported
13) Added switch so you can auto update the database or manually update the structure of the database.
14) DotCache, Aspectus, and Gestalt are integrated to make the system more modular.
15) Added better checks for null values/non existant objects in the database

Plus a number of fixes. I still need to add features like multiple databases, composite keys, etc. but it's coming along. So give it a look, try it out (usage documentation is included in this release), and happy coding.

Edit: It helps if I put a link to the new download...

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 8/17/2010 at 5:16 PM
Tags: , ,
Categories: General
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Creating an AOP Library in .Net - Part 1

I've been hearing for a while now the talk in the .Net community about AOP. For those of you curious, AOP stands for Aspect Oriented Programming. The general concept is that in OO design you usually have classes/functions that span everything called cross-cutting concerns (caching, logging, security, etc.). AOP's goal is to separate those items from the main code, creating little modular bits of code to accomplish a task. At some point in time (run time or compile time), it weaves those bits of code back into the main code. Thus you never have to worry about adding in the logging, caching, etc. directly to the function/class as the AOP library does it for you which makes things easier to read and maintain.

Anyway, I used AOP back when I was a Java developer (AspectJ), however I never really bothered to look at the code under the hood. I built my aspects and went about my business. As of late I've been much more interested in "reinventing the wheel", which explains the ORM. So I felt why not create a small little library to do AOP? And as always, I decided to post about it here. I realize that over the past couple of months I've come out with 5 different libraries, Gestalt.Net, Blammo.Net, Echo.Net, DotCache, and DotExtension. Now Echo.Net was actually for a work related purpose that I developed on my own time because I thought it might be useful in other projects, but the other four were to help me with this series of posts. So I'm not just coming out with code for the sake of code, I have a plan... OK, not a plan but a general idea... OK, not a general idea, maybe a vague idea that may shape up at some point in time if I squint really hard.

Before I demotavate myself any more, let's move on to the various approaches to AOP. As far as I'm aware I've only seen about 6 approaches implemented, however Ayende Rahien mentions 7 approaches here. I have yet to see Runtime IL-weaving in action but then again I've never used Post Sharp. The other approaches are:

  • Remoting Proxies
  • Deriving from ContextBoundObject
  • Compile-time subclassing
  • Runtime subclassing
  • Hooking into the profiler API
  • Compile time IL-weaving
So let's go over each one and see why I didn't pick it. The first is Remoting Proxies are built into .Net and if you're interested in them, just look into the System.Runtime.Remoting.Proxies namespace. They're not exactly the most useful as they can only deal with interfaces and MarshalByRefObjects. That kills it right there as it limits its usefulness. The second approach is using ContextBoundObject. This approach is actually really simple. Any class that you wish to intercept calls to, just have it inherit from ContextBoundObject. So you can do things like this:


    public class Temp2:ContextBoundObject
    {
        [MyAttribute]
        public string TempFunc()
        {
            return "A";
        }
    }


Note not exactly like that, but basically you do that and any calls to TempFunc get intercepted, allowing the MyAttribute to do work for you. Of course then you have to implement MyAttribute, set up an IMessageSink, IContextProperty, etc. which isn't too difficult. There are a couple major downsides to this approach though:
  1. You have to inherit from ContextBoundObject and C# doesn't allow for multiple inheritance
  2. It's slow. I mean REALLY slow.
  3. Say goodbye to generics (throws an error).
  4. It doesn't catch calls using this (or at least I couldn't get it to recognize the calls).
To me that's not worth it. The next is compile time subclassing. Basically that means we're doing code gen that creates a class that inherits from our initial class that we then use. It's not a bad approach actually. The main downside is that it only works with interfaces and virtual methods. The next approach is Runtime subclassing. With that approach it's IL gen instead of straight code gen which is then compiled. Once again, not that bad of an approach, same limitations as compile time, but it's usually a bit more flexible.

The next approach is hooking into the profiler API. To be honest, this approach is little more than compile time IL-weaving. Basically you're just inserting the code at compile time using the profiler API. As such it and Compile time IL-weaving have the same issues. Namely it's complex. The next approach is Runtime IL-weaving. Basically this is taking the byte code of the DLL/EXE and rewriting them so that your bits of code are added in. However unlike the profiler API/compile time approaches which simply rewrite the code on the disk, you're doing it at run time. That's it really, but personally I have no idea how you go about doing that in any sort of decent/non hack fashion.

So looking at each of these approaches, the one that seems the easiest to implement and still give me enough power to do what I want is the runtime subclassing. I mean I could do compile-time subclassing but since I've done some IL gen in the past for HaterAide ORM, it just seems easier to me. So if you're more interested in one of the other approaches, there are tons of other resources out there on them (well for some of them there are a lot of resources, not so much on others). That being said, in later posts I will be showing you my implementation using runtime subclassing. That's it for this post, so leave feedback and happing coding.

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 6/28/2010 at 8:40 AM
Tags: , ,
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

HaterAide ORM Updated to 1.5

I've been silent for a while now, mainly because of this update. I've been working day and most nights (when I'm not replaying Dragon Age) to get this done. Basically during development of a project at work, I became annoyed with my ORM. Specifically I was annoyed at the fact that it didn't automatically update my database structure like I wanted when I made a change to my object mappings. So I spent time making it do just that. And while I was at it I decided to add a couple other things that would be nice, such as:

  • Foreign keys are now added to the tables to ensure referential integrity.
  • Automatic updates to the database based on changes in the object mappings (only adds columns, foreign keys, etc. The only items that are dropped and recreated are stored procedures, functions, views, and triggers that the ORM creates).
  • Added support for more CLR data types (all IEnumerables, etc. should map now but I'm still being tesing that out).
  • Better naming conventions for tables, columns, stored procedures, etc.
  • Optimized compared to earlier builds.
  • Audit tables and triggers are now automatically generated (tracks changes to each table and whether the item was an insert, update, or delete).
  • Stored procedures are automatically generated to allow you to search on a foreign key.
  • Code is no longer dependent on ASP.Net and can be used in a windows app.

I'm still working on composite keys, primary keys that are not ints or GUIDs (although this is pretty close to working at this point), multiple databases (both in terms of different database types and allowing more than one database connection at a time), other sources that are not databases (Active Directory, XML, etc.), and a number of other things. Anyway, take a look at the code here, leave feedback, and happy coding.

kick it on DotNetKicks.com   Shout it
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkListEmail

Posted by: James Craig
Posted on: 3/25/2010 at 10:14 AM
Tags: , , ,
Categories: C#
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed