Uncategorized

Bye Bye Noma

No Comments »Written on April 6th, 2008 by
Categories: Uncategorized

As you may have noticed, i've been pretty quiet about Noma lately... I haven't worked on it for weeks (or is it months now?), mostly because the project just doesn't interest me anymore, and also because i haven't had a lot of free time lately. When i do have some free time, i like to spend it on learning new things or just experimenting with different libraries or ideas instead of trying to work on something that no longer interests me, or feeling somewhat guilty about not working on it :)

So, the noma project can pretty much be considered dead from now on...

With that said, one of the things i'm playing around with now is setting up a sample application based on my northwind nhibernate mappings. The idea is basically to just use it as a playground to experiment with new techniques or libraries and come up with good design and architecture ideas. Obviously, i plan on posting about these experiments quite a lot ;) ... depending on how much free time i'll have obviously :)

A picture says a 1000 words

No Comments »Written on March 11th, 2008 by
Categories: Uncategorized

Noma’s First Run

i'm finally spending some time on Noma again, and this is a screenshot of the results of trying it out for the first time.

Noma Checks Preview

No Comments »Written on January 4th, 2008 by
Categories: Uncategorized

This is just a small preview of how to implement Noma checks. The classes you'll see below work, but i still have to write the engine which runs these checks and feeds them the correct data. But i'm pretty happy with how the implementation of checks looks at the moment, so i wanted to post something about it.

First of all, there's the ICheck interface which looks like this:

    public interface ICheck {}

pretty meaningless huh? I'm just using this as a base interface type to identify all different kinds of Noma checks. For instance, here's the interface that you'll need to implement if you want to perform a check on a ClassMapping:

    public interface ICheckClassMappings : ICheck

    {

        ICollection<ClassMapping> Select(ICollection<ClassMapping> classMappings);

        void Check(ClassMapping classToCheck, MetaDataStore store);

    }

The Select method is passed all known ClassMappings, and you'll need to return the ones that your check is interested in. Each one of the selected ClassMappings will then be passed to the Check method along with the entire MetaDataStore which you'll use to look up all the data you need to perform your check.

If you want to write a check for something that belongs to a ClassMapping, you'll need to implement the generic ICheck interface:

    public interface ICheck<T> : ICheck

    {

        ICollection<T> Select(ICollection<T> mappings, ClassMapping parentClassMapping);

        void Check(T mappingToCheck, ClassMapping parentClassmapping, MetaDataStore store);

    }

The type parameter will be the kind of mapping you want to check, like a PropertyMapping for example. The Select method will then receive a collection of all these mappings per ClassMapping, along with a reference to the ClassMapping the mappings belong to. You'll then need to return a collection of all the mappings you want to perform the check on. Each of these will then be passed to the Check method, along with the reference of the ClassMapping it belongs to, and a reference to the MetaDataStore.

To make it more clear, i'll show you two examples. First of all, there is the TableExists check:

using System.Collections.Generic;

using System.Linq;

 

using Noma.NHibernate.Mappings;

 

using NUnit.Framework;

 

namespace Noma.Runner.Checks.MappingToDatabase.Class

{

    public class TableExists : ICheckClassMappings

    {

        public ICollection<ClassMapping> Select(ICollection<ClassMapping> classMappings)

        {

            return classMappings.Where(c => !string.IsNullOrEmpty(c.Table)).ToList();

        }

 

        public void Check(ClassMapping classToCheck, MetaDataStore store)

        {

            Assert.IsNotNull(store.GetTable(classToCheck.Schema, classToCheck.Table),

                "Table [{0}].[{1}] was not found", classToCheck.Schema, classToCheck.Name);

        }

    }

}

Pretty simple right? It selects each ClassMapping that has a Table defined, and then in the Check method we use the familiar NUnit Assert class to verify that the referenced table actually exists in our MetaDataStore.

And this is how the ColumnExists check looks like:

using System.Collections.Generic;

 

using Noma.Database;

using Noma.NHibernate.Mappings;

using Noma.Runner.Checks.MappingToDatabase.Class;

 

using NUnit.Framework;

 

namespace Noma.Runner.Checks.MappingToDatabase.Property

{

    [RequiresMappingToPassCheck(typeof(TableExists))]

    public class ColumnExists : ICheck<PropertyMapping>

    {

        public ICollection<PropertyMapping> Select(ICollection<PropertyMapping> mappings, ClassMapping parentClassMapping)

        {

            // we need to check all property mappings

            return mappings;

        }

 

        public void Check(PropertyMapping mappingToCheck, ClassMapping parentClassmapping, MetaDataStore store)

        {

            string columnName =

                !string.IsNullOrEmpty(mappingToCheck.ColumnName) ? mappingToCheck.ColumnName : mappingToCheck.Name;

 

            Table table = store.GetTable(parentClassmapping.Schema, parentClassmapping.Table);

 

            Assert.IsNotNull(table.GetColumn(columnName),

                            "Class [{0}] refers to column [{1}] in table [{2}].[{3}] but the column was not found",

                            parentClassmapping.Name, columnName, parentClassmapping.Schema, parentClassmapping.Table);

        }

    }

}

Notice the usage of the [RequiresMappingToPassCheck]. You can use this to declare dependencies between checks... if one of the checks referenced with the [RequiresMappingToPassCheck] attribute already failed for a particular mapping or its parent ClassMapping, the check will not be executed for that specific mapping. In this case, we depend upon a check that only checks ClassMappings. So the ColumnExists check will not be executed for each ClassMapping that already failed the TableExists check.

In the Select method, you can see we simply return all the PropertyMappings we've received since we need to check them all. And in the Check method, we look up the table the ClassMapping refers to, and verify that the referenced column is actually there.

I've only just come up with this approach... The checks themselves work already, but as i mentioned earlier, i still need to write the engine to execute these checks, feed them the correct data, and resolve the dependencies between the checks. That should be some pretty interesting code :)

Obviously, you will be able to plug in your own checks which can also have dependencies between them.

YANSU

No Comments »Written on December 12th, 2007 by
Categories: Uncategorized

That's right, Yet Another Noma Status Update... anyway, there's finally some progress to report. The hibernate mapping parsing is finally done so i can now start working on the rules engine.

At the moment, this is what I have in mind: each rule would have to implement a very simple interface which will probably only have 2 methods... the first would allow the rule to register which kind of ClassMappings it's interested in, the other would actually execute the rule on each of the selected ClassMappings.

For instance, if you'd like to write a rule that has to be checked on each class that has one or more many-to-one mappings, you would be able to 'register' the data you want to check with something like: return AvailableClassMappings.Where(c => c.ManyToOneMappings.Count > 0);

The other method of your rule would then be called for each of the ClassMappings your rule has registered. Would be pretty simple and easy i think.

Anyways, the goal is to get an alpha release out the door somewhere in January.

using a default xml namespace with the XElement class

No Comments »Written on December 2nd, 2007 by
Categories: Uncategorized

I just upgraded all of the xml parsing code in Noma to use the new classes in the System.Xml.Linq namespace, which btw are MUCH easier to use than the old-school XmlDocument/XmlElement/... set of classes. Anyway, i have a lot of tests that create xml elements in memory so the parsing can be tested on them. Now, all of those elements should of course use the correct xml namespace.

With the new XElement class, this is already much easier to do than it was with the XmlElement class. But, if you're creating a hell of a lot of XElement instances that all need to use the same namespace, you can very easily extend the XElement class to set the correct namespace by default:

    public class NXElement : XElement

    {

        public NXElement(string name, params object[] objects)

            : base(Constants.XmlNamespace + name, objects) {}

 

        public NXElement(string name, object parameter)

            : base(Constants.XmlNamespace + name, parameter) {}

 

        public NXElement(string name)

            : base(Constants.XmlNamespace + name) {}

    }

And now i can create nested XML elements that use the correct namespace just like this:

            XElement element = new NXElement(Elements.List,

                                            new NXElement(Elements.OneToMany,

                                                           new XAttribute(Attributes.Class, "ClassName")));