Example #1
0
        public NrdoTable GetTable(string name)
        {
            if (!TablesByLookup.ContainsKey(lookup))
            {
                TablesByLookup[lookup] = new Dictionary <string, NrdoTable>();
            }
            Dictionary <string, NrdoTable> tables = TablesByLookup[lookup];

            if (!tables.ContainsKey(name))
            {
                NrdoTable table = null;
                foreach (AssemblyName asmName in lookup.GetPossibleAssemblies(name))
                {
                    Assembly assembly = Assembly.Load(asmName);
                    if (assembly == null)
                    {
                        throw new ArgumentException("Failed to load assembly " + asmName.FullName + "; Codebase=" + asmName.CodeBase);
                    }
                    table = getTableInternal(assembly, name);
                    if (table != null)
                    {
                        break;
                    }
                }
                tables[name] = table;
            }
            return(tables[name]);
        }
Example #2
0
        // Cannot be subclassed outside this assembly
        internal NrdoGetBase(NrdoTable table, MethodInfo method, NrdoGetBaseAttribute gattr)
        {
            this.attr    = gattr;
            this.table   = table;
            this.method  = method;
            this.name    = gattr.Name;
            this.hasCode = gattr.HasCode;
            this.where   = gattr.Where;

            tables = new List <NrdoTableRef>();
            foreach (var tattr in method.GetAttributes <NrdoByTableAttribute>())
            {
                if (tattr.Param)
                {
                    // FIXME: add to ParamTables
                }
                else
                {
                    tables.Add(new NrdoTableRef(tattr));
                }
            }
            tables.Sort();

            fields = (from fattr in method.GetAttributes <NrdoByFieldAttribute>()
                      orderby fattr.Index
                      select new NrdoFieldRef(this, fattr)).ToList();

            joins = (from jattr in method.GetAttributes <NrdoJoinAttribute>()
                     orderby jattr.Index
                     select new NrdoJoin(this, jattr)).ToList();

            @params = (from pattr in method.GetAttributes <NrdoParamAttribute>()
                       orderby pattr.Index
                       select new NrdoParam(pattr)).ToList();

            orderby = new List <NrdoOrderByClause>();
            foreach (var oattr in method.GetAttributes <NrdoOrderByAttribute>())
            {
                if (oattr.Field != null)
                {
                    orderby.Add(new NrdoOrderByField(this, oattr));
                }
                else
                {
                    orderby.Add(new NrdoOrderBySql(this, oattr));
                }
            }
            orderby.Sort();
        }
Example #3
0
        /// <summary>
        /// Gets a NrdoTable object corresponding to the given type.
        /// </summary>
        /// <param name="type">The type corresponding to the table to get</param>
        /// <returns>A NrdoTable object corresponding to the given type</returns>
        public static NrdoTable GetTable(Type type)
        {
            Assembly assembly = type.Assembly;
            string   name     = NrdoCodeBase.getTableNameFromType(type);

            if (name == null || NrdoReflection.MangleName(assembly, name) != type.FullName)
            {
                throw new ArgumentException(type.FullName + " is not a valid nrdo database table class: " + name + " mangles to " + NrdoReflection.MangleName(assembly, name));
            }
            NrdoTable result = NrdoCodeBase.getTableInternal(assembly, name, type);

            if (result == null)
            {
                throw new ArgumentException(type.FullName + " is not a valid nrdo database table class");
            }
            return(result);
        }
Example #4
0
        // Cannot be subclassed outside this assembly
        internal NrdoReference(NrdoTable table, MethodInfo method, NrdoRefAttribute rattr)
            : base(table, method, rattr)
        {
            this.index           = rattr.Index;
            this.isFkey          = rattr.Fkey;
            this.fkeyName        = rattr.FkeyName;
            this.isCascadingFkey = rattr.Cascade;
            MethodInfo meth = targetTable.Type.GetMethod(rattr.Get, rattr.GetParams);

            foreach (NrdoGet get in targetTable.Gets)
            {
                if (get.Method.Equals(meth))
                {
                    associatedGet = get;
                }
            }
            if (associatedGet == null)
            {
                throw new ArgumentException("Associated get for reference not found");
            }
        }
Example #5
0
 internal NrdoMultiGet(NrdoTable table, MethodInfo method, NrdoGetAttribute gattr)
     : base(table, method, gattr)
 {
 }
Example #6
0
 // Cannot be subclassed outside this assembly
 internal NrdoGet(NrdoTable table, MethodInfo method, NrdoGetAttribute gattr)
     : base(table, method, gattr)
 {
     this.index    = gattr.Index;
     this.hasIndex = gattr.HasIndex;
 }
Example #7
0
 internal NrdoMultiReference(NrdoTable table, MethodInfo method, NrdoRefAttribute rattr)
     : base(table, method, rattr)
 {
 }
Example #8
0
 internal NrdoTableRef(NrdoTable table)
 {
     this.table = table;
     this.alias = "self";
 }
Example #9
0
 // Cannot be subclassed outside this assembly
 internal NrdoTableRef(NrdoByTableAttribute attr)
 {
     this.table = NrdoTable.GetTable(attr.Table);
     this.alias = attr.Alias;
     this.index = attr.Index;
 }