1

Closed

Inherited PersistentObjects not written to Dao.xml with SpringDaoGen

description

Hi,
 
First I would like to congratulate you on a world class framework. Thank you.
 
I hit a stumbling block with the SpringDaoGen.
I have a Person class that inherits from PersistentObject.
I then have a Contact class that inherits from Person.
SpringDaoGen only checks the immediate base type for PersistentObject.
 
My fix is shown below.
It involves a helper method that recursively checks the Base types for PersistentObject.
This method call then forms part of the linq query in GetPersistentObjectsFrom
 
 
    private static bool isPersistentObject(Type t) 
    {
        if ((t.BaseType.FullName == typeof(PersistentObject).FullName) ||
                (t.BaseType.IsGenericType
                && t.BaseType.GetGenericTypeDefinition().FullName == typeof(PersistentObjectWithTypedId<>).FullName))
        {
            return true;
        }
 
        else
        {
            if (t.BaseType != typeof(Object))
            {
                return isPersistentObject(t.BaseType);
            }
            return false;
        }
    }
 
    private static IEnumerable<Type> GetPersistentObjectsFrom(string assemblyPath) {
        currentAssemblyPath = assemblyPath;
 
        // fetch assembly with classes that derive from PersistentObject<>
        AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve +=
            new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
        Assembly a = System.Reflection.Assembly.ReflectionOnlyLoadFrom(assemblyPath);
 
        // fetch all types from specified assembly that inherit from PersistentObject or Persistobject<>
        var types = from t in a.GetTypes()
                    where t.IsClass
                        && isPersistentObject(t)
                    select t;
Closed Jul 11, 2008 at 10:34 PM by wmccafferty
This is no longer applicable in version 0.7 which has dropped Spring.NET.

comments

wmccafferty wrote Jul 8, 2008 at 6:35 PM

Thanks very much for this submission...I'll be adding it to the codebase.

wrote Jul 11, 2008 at 10:34 PM

wrote Feb 13, 2013 at 11:39 PM

wrote May 16, 2013 at 5:08 AM