Exemple #1
0
        private void Load(XDoc doc)
        {
            Assertion.AreEqual("ormap", doc.Node.Name, "Root element should be [ormap].");
            foreach (XAccessor x in doc.Attributes)
            {
                Assertion.AreEqual("xmlns", x.Prefix, "Only xmlns attributes allowed in root element.");
                string tag = x.LocalName;
                string target = x.GetStringValue();

                if (target.StartsWith(DbPath.DB_SCHEMA))
                {
                    DbPath dbPath = target.RemoveBegin(DbPath.DB_SCHEMA);
                    Assertion.IsTrue(ORMConfig.ORMConfiguration.ExistDatabase(dbPath.DatabaseId), "Database [{0}] is not defined.", dbPath.DatabaseId);

                    _dbDict.Add(tag, dbPath);
                }
                else if (target.StartsWith(ClrClassPath.CLR_SCHEME))
                {
                    ClrClassPath path = target.RemoveBegin(ClrClassPath.CLR_SCHEME);
                    _clrDict.Add(tag, path);
                }
                else
                {
                    Assertion.Fail("Unknown schema of uri [{0}].", target);
                }
            }

            var mapList = doc.NavigateToList("object-table-map");
            foreach (var xMap in mapList)
            {
                PrefixedName c = new PrefixedName(xMap.GetStringValue("@class"));
                PrefixedName t = new PrefixedName(xMap.GetStringValue("@table"));
                string primaryKey = xMap.GetStringValue("@primaryKey");
                string pkGenerate = xMap.GetStringValue("@primaryKeyGenerate");

                Assertion.IsTrue(_clrDict.ContainsKey(c.Prefix), "Prefix [{0}] is not defined.", c.Prefix);
                Type entityType = _clrDict[c.Prefix].MakeType(c.LocalName);

                if (entityType == null)
                    MappingInfoExceptionHelper.ThrowLoadEntityTypeFail(c.Prefix, c.LocalName);

                var fields = xMap.NavigateToList("field");
                List<IPropertyMapInfo> list = new List<IPropertyMapInfo>();
                foreach (var xField in fields)
                {
                    string property = xField.GetStringValue("@property");
                    string column = xField.GetStringValue("@column");

                    int length = xField.GetValue<int>("@length") ?? 0;
                    bool nullable = xField.GetValue<bool>("@nullable") ?? true;

                    IPropertyMapInfo pInfo = new PropertyMapInfo(property, column, length, nullable);
                    list.Add(pInfo);
                }

                IObjectMapInfo info = new ObjectMapInfo(t, entityType, primaryKey, pkGenerate, list);
                _cache.SetMapInfo(entityType, info);
            }
        }
Exemple #2
0
        public ObjectMapInfo(PrefixedName table, Type entityType, string primaryKey, string primaryKeyGenerate, IEnumerable<IPropertyMapInfo> fieldList)
        {
            _table = table;
            _entityType = entityType;
            _primaryKeyGenerate = primaryKeyGenerate;

            string[] pkList = primaryKey.Split(Composite_PK_Delimiter, StringSplitOptions.RemoveEmptyEntries);
            _pkList = new List<string>();
            foreach (string pk in pkList)
                _pkList.Add(pk.Trim());

            _fieldList = fieldList;
        }
Exemple #3
0
        public ObjectMapInfo(PrefixedName table, Type entityType, string primaryKey, string primaryKeyGenerate, IEnumerable <IPropertyMapInfo> fieldList)
        {
            _table              = table;
            _entityType         = entityType;
            _primaryKeyGenerate = primaryKeyGenerate;

            string[] pkList = primaryKey.Split(Composite_PK_Delimiter, StringSplitOptions.RemoveEmptyEntries);
            _pkList = new List <string>();
            foreach (string pk in pkList)
            {
                _pkList.Add(pk.Trim());
            }

            _fieldList = fieldList;
        }
Exemple #4
0
 public TableAttribute(string prefixedName)
 {
     _pName = new PrefixedName(prefixedName);
     _primaryKeyGenerate = RexToy.ORM.MappingInfo.PrimaryKeyGenerate.Auto.ToString();
 }
Exemple #5
0
        private void Load(XDoc doc)
        {
            Assertion.AreEqual("ormap", doc.Node.Name, "Root element should be [ormap].");
            foreach (XAccessor x in doc.Attributes)
            {
                Assertion.AreEqual("xmlns", x.Prefix, "Only xmlns attributes allowed in root element.");
                string tag    = x.LocalName;
                string target = x.GetStringValue();

                if (target.StartsWith(DbPath.DB_SCHEMA))
                {
                    DbPath dbPath = target.RemoveBegin(DbPath.DB_SCHEMA);
                    Assertion.IsTrue(ORMConfig.ORMConfiguration.ExistDatabase(dbPath.DatabaseId), "Database [{0}] is not defined.", dbPath.DatabaseId);

                    _dbDict.Add(tag, dbPath);
                }
                else if (target.StartsWith(ClrClassPath.CLR_SCHEME))
                {
                    ClrClassPath path = target.RemoveBegin(ClrClassPath.CLR_SCHEME);
                    _clrDict.Add(tag, path);
                }
                else
                {
                    Assertion.Fail("Unknown schema of uri [{0}].", target);
                }
            }

            var mapList = doc.NavigateToList("object-table-map");

            foreach (var xMap in mapList)
            {
                PrefixedName c          = new PrefixedName(xMap.GetStringValue("@class"));
                PrefixedName t          = new PrefixedName(xMap.GetStringValue("@table"));
                string       primaryKey = xMap.GetStringValue("@primaryKey");
                string       pkGenerate = xMap.GetStringValue("@primaryKeyGenerate");

                Assertion.IsTrue(_clrDict.ContainsKey(c.Prefix), "Prefix [{0}] is not defined.", c.Prefix);
                Type entityType = _clrDict[c.Prefix].MakeType(c.LocalName);

                if (entityType == null)
                {
                    MappingInfoExceptionHelper.ThrowLoadEntityTypeFail(c.Prefix, c.LocalName);
                }

                var fields = xMap.NavigateToList("field");
                List <IPropertyMapInfo> list = new List <IPropertyMapInfo>();
                foreach (var xField in fields)
                {
                    string property = xField.GetStringValue("@property");
                    string column   = xField.GetStringValue("@column");

                    int  length   = xField.GetValue <int>("@length") ?? 0;
                    bool nullable = xField.GetValue <bool>("@nullable") ?? true;

                    IPropertyMapInfo pInfo = new PropertyMapInfo(property, column, length, nullable);
                    list.Add(pInfo);
                }

                IObjectMapInfo info = new ObjectMapInfo(t, entityType, primaryKey, pkGenerate, list);
                _cache.SetMapInfo(entityType, info);
            }
        }
Exemple #6
0
 public TableAttribute(string prefixedName)
 {
     _pName = new PrefixedName(prefixedName);
     _primaryKeyGenerate = RexToy.ORM.MappingInfo.PrimaryKeyGenerate.Auto.ToString();
 }