コード例 #1
0
ファイル: Class.cs プロジェクト: mirkomaty/NDO
        /// <summary>
        /// Constructs a Class object according the information in the mapping file.
        /// </summary>
        /// <param name="classNode"></param>
        /// <param name="parent"></param>
        internal Class(XmlNode classNode, NDOMapping parent)
            : base(classNode, parent)
        {
            assemblyName  = classNode.Attributes["AssemblyName"].Value;
            fullName      = classNode.Attributes["FullName"].Value;
            tableName     = classNode.Attributes["TableName"].Value;
            connectionId  = classNode.Attributes["ConnectionId"].Value;
            this.typeCode = 0;  // undefined
            XmlAttribute attr = classNode.Attributes["TypeCode"];

            if (attr != null)
            {
                int.TryParse(attr.Value, out this.typeCode);
            }
            attr = classNode.Attributes["TimeStampColumn"];
            if (attr != null)
            {
                this.timeStampColumn = attr.Value;
            }

            XmlNodeList nl = classNode.SelectNodes(Parent.selectRelation, Parent.nsmgr);

            foreach (XmlNode relNode in nl)
            {
                Relation r = new Relation(relNode, this);
                relations.Add(r);
            }
            nl = classNode.SelectNodes(Parent.selectField, Parent.nsmgr);
            foreach (XmlNode fieldNode in nl)
            {
                fields.Add(new Field(fieldNode, this));
            }
            XmlNode oidNode = classNode.SelectSingleNode(Parent.selectOid, Parent.nsmgr);

            if (null != oidNode)
            {
                this.oid = new ClassOid(oidNode, this);
            }

            XmlNode typeColumnNode = classNode.SelectSingleNode(Parent.selectTypeNameColumn, Parent.nsmgr);

            if (null != typeColumnNode)
            {
                this.typeNameColumn = new Column(typeColumnNode, this);
            }
        }
コード例 #2
0
ファイル: OidColumn.cs プロジェクト: mirkomaty/NDO
        internal OidColumn(XmlNode columnNode, ClassOid parent)
            : base(columnNode, parent)
        {
            if (null != columnNode.Attributes["FieldName"])
            {
                this.fieldName = columnNode.Attributes["FieldName"].Value;
            }
            else
            {
                this.fieldName = null;
            }
            if (null != columnNode.Attributes["RelationName"])
            {
                this.relationName = columnNode.Attributes["RelationName"].Value;
            }
            else
            {
                this.relationName = null;
            }

            if (null != columnNode.Attributes["AutoIncremented"])
            {
                this.autoIncremented = bool.Parse(columnNode.Attributes["AutoIncremented"].Value);
            }
            else
            {
                this.autoIncremented = false;
            }

            if (this.autoIncremented)
            {
                if (null != columnNode.Attributes["AutoIncrementStart"])
                {
                    this.autoIncrementStart = int.Parse(columnNode.Attributes["AutoincrementStart"].Value);
                }
                //else // the value is defaulted to 1
                //    this.autoIncrementStart = 1;

                if (null != columnNode.Attributes["AutoIncrementStep"])
                {
                    this.autoIncrementStep = int.Parse(columnNode.Attributes["AutoincrementStep"].Value);
                }
                //else // the value is defaulted to 1
                //    this.autoIncrementStep = 1;
            }
        }
コード例 #3
0
ファイル: NDOMapping.cs プロジェクト: mirkomaty/NDO
 private bool OidsAreDifferent(ClassOid oid1, ClassOid oid2)
 {
     if (oid1.OidColumns.Count != oid2.OidColumns.Count)
     {
         return(true);
     }
     for (int i = 0; i < oid1.OidColumns.Count; i++)
     {
         OidColumn oidc1 = (OidColumn)oid1.OidColumns[i];
         OidColumn oidc2 = (OidColumn)oid2.OidColumns[i];
         if (OidColumnsAreDifferent(oidc1, oidc2))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
ファイル: OidColumn.cs プロジェクト: mirkomaty/NDO
 /// <summary>
 /// Constructs a Column element and assigns it to the given parent.
 /// </summary>
 /// <param name="parent">The parent object.</param>
 public OidColumn(ClassOid parent)
     : base(parent)
 {
     base.AllowDbNull = false;
 }
コード例 #5
0
 /// <summary>
 /// Constructs the OidColumnIterator for a given oid mapping.
 /// </summary>
 /// <param name="oid"></param>
 public OidColumnIterator(ClassOid oid)
 {
     this.columns = oid.OidColumns.ToList();
 }
コード例 #6
0
ファイル: Class.cs プロジェクト: mirkomaty/NDO
 /// <summary>
 /// Factory method for constructing an ClassOid object.
 /// </summary>
 /// <returns>The ClasOid object.</returns>
 public ClassOid NewOid()
 {
     this.Oid = new ClassOid(this);
     return(this.oid);
 }
コード例 #7
0
ファイル: NDOMapping.cs プロジェクト: mirkomaty/NDO
        /// <summary>
        /// Adds a class mapping.
        /// </summary>
        /// <param name="fullName">Fully qualified name of the class.</param>
        /// <param name="AssemblyName">Name of the assembly, the class resides in.</param>
        /// <param name="columnAttributes">If not null, the mapping values will be taken from the column attributes.</param>
        /// <returns>A new Class object.</returns>
        public Class AddStandardClass(string fullName, string AssemblyName, OidColumnAttribute[] columnAttributes)
        {
            this.Changed = true;
            Class c = new Class(this);

            c.FullName     = fullName;
            c.AssemblyName = AssemblyName;

            string tableName = fullName.Substring(fullName.LastIndexOf('.') + 1);
            int    p         = tableName.LastIndexOf('`');

            if (p > -1)
            {
                tableName = tableName.Substring(0, p);
            }

            if (this.standardDbOwner != string.Empty)
            {
                tableName = standardDbOwner + "." + tableName;
            }

            bool tableNameIsFree = false;
            int  i = 0;

            while (!tableNameIsFree)
            {
                tableNameIsFree = true;
                foreach (Class c2 in classes.Values)
                {
                    if (c2.TableName == tableName)
                    {
                        tableNameIsFree = false;
                        break;
                    }
                }
                if (!tableNameIsFree)
                {
                    i++;
                    tableName = fullName.Substring(fullName.LastIndexOf('.') + 1) + i.ToString();
                }
            }

            c.TableName = tableName;

            if (connections.Count == 0)
            {
                AddStandardConnection();
            }
            c.ConnectionId = this.connections[0].ID;
            ClassOid oid = c.NewOid();

            if (columnAttributes == null)
            {
                OidColumn column = oid.NewOidColumn();
                column.Name = "ID";
            }
            else
            {
                oid.RemapOidColumns(columnAttributes);
                int count = oid.OidColumns.Count;
                i = 1;
                new OidColumnIterator(oid).Iterate(delegate(OidColumn oidColumn, bool isLastElement)
                {
                    if (string.IsNullOrEmpty(oidColumn.Name))
                    {
                        if (count == 1)
                        {
                            oidColumn.Name = "ID";
                        }
                        else
                        {
                            oidColumn.Name = "ID" + i;
                        }
                    }
                    i++;
                });
            }

            AddClass(c);
            return(c);
        }