Java Mailing List Archive

http://www.gg3721.com/

Home » the NHibernate development list »

Re: [NHibernate-development] Mapping rewrite

Ayende Rahien

2008-06-29

Replies: Find Java Web Hosting

Author LoginPost Reply
Runtime in this context means _before_ we call BuildSessionFactory, but without touching the source XML files.
Ideally, I want to be able to run this at some point at the config build lifetime:

PersistentClass classMapping = cfg.GetClassMapping(userType);
foreach (PersistentClass persistentClass in cfg.ClassMappings)
{
    //ignore non Rhino Security entities
    if (persistentClass.MappedClass.Assembly != typeof(IUser).Assembly)
        continue;

    foreach (Property property in persistentClass.PropertyIterator)
    {
        ManyToOne manyToOne = property.Value as ManyToOne;
        if (manyToOne == null || manyToOne.ReferencedEntityName != typeof(IUser).FullName)
            continue;
        ManyToOne value = new ManyToOne(classMapping.Table);
        value.ReferencedEntityName = userType.FullName;
        foreach (ISelectable selectable in manyToOne.ColumnIterator)
        {
            Column col = selectable as Column;
            if (col != null)
            {
                value.AddColumn(col);
            }
        }
        property.Value = value;

        Collection collection = property.Value as Collection;
        if (collection == null || collection.IsOneToMany ||
            collection.GenericArguments.Length != 1 ||
            collection.GenericArguments[0] != typeof(IUser))
            continue;
        IValue element = collection.Element;
    }

    foreach (ForeignKey key in persistentClass.Table.ForeignKeyIterator)
    {
        if (key.ReferencedEntityName != typeof(IUser).FullName)
            continue;

        key.ReferencedEntityName = userType.FullName;
        key.ReferencedTable = classMapping.Table;
    }
}

On Sun, Jun 29, 2008 at 5:09 PM, Fabio Maulo <fabiomaulo@gmail.com> wrote:
2008/6/29 Ayende Rahien <ayende@ayende.com>:
I am _not_ interested in changing the XML. I am interested in selecting, at runtime, what is the class of the many-to-many association.

There is a difference between them


At run-time ok; but when ?
You know, NH do the hard work of mapping at build-session-factory-time.
So far only using <any> you can have an association really resolved at run-time.

I need to understand what you are looking for to study the situation.
--
Fabio Maulo
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Nhibernate-development mailing list
Nhibernate-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nhibernate-development


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Nhibernate-development mailing list
Nhibernate-development@(protected)
https://lists.sourceforge.net/lists/listinfo/nhibernate-development
©2008 gg3721.com - Jax Systems, LLC, U.S.A.