예제 #1
0
        private DataType GetTableType(PersistentModel model, string clsname, PersistentClass _cls)
        {
            var cls = clsname == "this" ? _cls: model[clsname];

            if (null == cls)
            {
                model.RegisterError(new BSharpError {
                    Message = "Не могу найти класса для табличного типа " + clsname
                });
            }
            var result = new DataType();

            result.IsTable    = true;
            result.TargetType = cls;
            return(result);
        }
예제 #2
0
        /// <summary>
        ///     Загружает поле из XML
        /// </summary>
        /// <param name="c"></param>
        /// <param name="e"></param>
        /// <param name="cls"></param>
        /// <returns></returns>
        public Field Setup(IBSharpClass c, XElement e, PersistentClass cls)
        {
            Table      = cls;
            Definition = e;
            SetupCommon(c, e);
            if (ImplicitRef || e.Name.LocalName == "ref")
            {
                SetupReference(c, e);
            }
            else
            {
                SetupUsualField(c, e);
            }
            SetupDefaultValue(c, e);

            return(this);
        }
예제 #3
0
        /// <summary>
        ///     Конфигурирует модель из B#
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public PersistentModel Setup(IBSharpContext context)
        {
            Context = context;
            IEnumerable <IBSharpClass> tables = Context.ResolveAll(TablePrototype + ";attr:" + TableAttribute).ToArray();

            foreach (IBSharpClass table in tables)
            {
                var pclass = new PersistentClass();
                pclass.Setup(table);
                pclass.Model = this;
                Classes[pclass.FullSqlName.ToLowerInvariant()] = pclass;
            }
            SetupDefaultScripts();
            foreach (SqlObject obj in SqlObject.CreateDatabaseWide(this))
            {
                DatabaseSqlObjects.Add(obj);
            }
            BuildModel();
            ReadScripts();
            return(this);
        }
예제 #4
0
 private void ReadAdvancedDataObjects(PersistentClass cls, XElement xml)
 {
     foreach (SqlObject obj in SqlObject.CreateDefaults(cls))
     {
         obj.Table = cls;
         cls.SqlObjects.Add(obj);
     }
     foreach (XElement e in xml.Elements())
     {
         string name = e.Name.LocalName;
         if (name == "ref")
         {
             continue;
         }
         if (cls.DataTypeMap.ContainsKey(name) && string.IsNullOrWhiteSpace(e.Value))
         {
             continue;
         }
         foreach (SqlObject obj in SqlObject.Create(cls, e))
         {
             cls.SqlObjects.Add(obj);
         }
     }
 }
예제 #5
0
        /// <summary>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="cls"></param>
        /// <param name="bscls"></param>
        /// <param name="xml"></param>
        /// <returns></returns>
        public override SqlObject Setup(PersistentModel model, PersistentClass cls, IBSharpClass bscls,
                                        XElement xml)
        {
            model = model ?? cls.Model;
            base.Setup(model, cls, bscls, xml);

            string xname = xml.Name.LocalName;

            IsProcedure = xname == "void" || (xname == "function" && string.IsNullOrWhiteSpace(xml.Attr("returns")));
            if (!IsProcedure)
            {
                if (xname.EndsWith("__STAR__"))
                {
                    var tp = xname.Substring(0, xname.Length - 8);
                    ReturnType = GetTableType(model, tp, cls);
                }
                else
                {
                    string dtype = xname;
                    if (dtype == "function")
                    {
                        dtype = xml.Attr("returns");
                    }
                    if (Table.DataTypeMap.ContainsKey(dtype))
                    {
                        ReturnType = Table.DataTypeMap[dtype];
                    }
                    else
                    {
                        ReturnType = new DataType {
                            IsNative = true, SqlText = dtype
                        };
                    }
                }
            }
            if (xml.GetSmartValue("sql-method").ToBool())
            {
                var sqlm = SqlMethodOptions.IsMethod;
                var opts = xml.GetSmartValue("sql-method");
                if (!string.IsNullOrWhiteSpace(opts))
                {
                    sqlm |= opts.To <SqlMethodOptions>();
                }
                SqlMethod = sqlm;
            }
            int i = 0;

            foreach (XAttribute a in xml.Attributes())
            {
                string name = a.Name.LocalName.Unescape(EscapingType.XmlName);
                string val  = a.Value;
                if (name.StartsWith("@"))
                {
                    string[]            namepair = name.Substring(1).Split('-');
                    string              argname  = namepair[0];
                    SqlFunctionArgument arg;
                    if (!Arguments.ContainsKey(argname))
                    {
                        Arguments[argname] = new SqlFunctionArgument {
                            Name = argname, DataType = Table.DataTypeMap["string"], Index = i++
                        };
                    }
                    arg = Arguments[argname];
                    if (namepair.Length == 1)
                    {
//only type determine
                        if (Table.DataTypeMap.ContainsKey(val))
                        {
                            arg.DataType = Table.DataTypeMap[val];
                        }
                        else
                        {
                            arg.DataType = GetIdRefType(model, val, argname, cls);
                        }
                    }
                    else
                    {
                        bool hastype    = false;
                        bool hasdefault = false;
                        for (int j = 1; j < namepair.Length; j++)
                        {
                            string part = namepair[j];
                            if (part == "default")
                            {
                                hasdefault = true;
                            }
                            else if (part == "out")
                            {
                                arg.IsOutput = true;
                            }
                            else if (Table.DataTypeMap.ContainsKey(part))
                            {
                                arg.DataType = Table.DataTypeMap[part];
                                hastype      = true;
                            }
                            else
                            {
                                Model.RegisterError(new BSharpError {
                                    Message = "unknown arg part " + part, Xml = xml, Class = Table.TargetClass
                                });
                            }
                        }
                        if ((hastype || hasdefault) && !string.IsNullOrWhiteSpace(val))
                        {
                            arg.DefaultValue = new DefaultValue {
                                DefaultValueType = DbDefaultValueType.Native, Value = val
                            };
                        }
                    }
                }
            }
            return(this);
        }
예제 #6
0
        private DataType GetIdRefType(PersistentModel model, string clsname, string argname, PersistentClass _cls)
        {
            var cls = clsname == "this"?_cls: model[clsname];

            if (null == cls)
            {
                model.RegisterError(new BSharpError {
                    Message = "Не могу найти класса для ссылочного типа " + clsname
                });
                return(null);
            }
            var result = cls[argname].DataType.Copy();

            result.IsIdRef    = true;
            result.TargetType = cls;
            return(result);
        }