/// <summary>
        /// Visits the given <paramref name="addColumnNode"/>.
        /// </summary>
        /// <param name="addColumnNode"></param>
        public override void Visit(IAddColumnNode addColumnNode)
        {
            //
            // Create an "IAddReferenceNode" for "references" property
            if(addColumnNode.Properties[MdlSyntax.References] != null)
            {
                IAstNodeProperty referencesProperty = addColumnNode.Properties[MdlSyntax.References];
                string references = AstNodePropertyUtil.AsString(referencesProperty.Value);

                IAddReferenceNode addReferenceNode = new AddReferenceNode(addColumnNode, "");
                addReferenceNode.Location = referencesProperty.Location;
                addReferenceNode.Properties.AddProperty(AstNodeProperty.String(MdlSyntax.PkTable, references));

                //
                // Propagate on-delete and on-update
                var onDelete = addColumnNode.Properties["on-delete"];
                if(onDelete != null)
                    addReferenceNode.Properties.AddProperty(onDelete);

                var onUpdate = addColumnNode.Properties["on-update"];
                if(onUpdate != null)
                    addReferenceNode.Properties.AddProperty(onUpdate);

                addColumnNode.ChildNodes.Add(addReferenceNode);
            } // if

            //
            // Create an 'IAddIndexNode" for "unique" property
            if(addColumnNode.Properties[MdlSyntax.Unique] != null)
            {
                IAstNodeProperty uniqueProperty = addColumnNode.Properties[MdlSyntax.Unique];

                IAddIndexNode addIndexNode = new AddIndexNode(addColumnNode, "");
                addIndexNode.Location = uniqueProperty.Location;
                addIndexNode.Properties.AddProperty(AstNodeProperty.String(MdlSyntax.Unique, "true"));

                addColumnNode.ChildNodes.Add(addIndexNode);
            } // if

            //
            // Create an 'IAddConstraintNode" for "default" property
            if(addColumnNode.Properties[MdlSyntax.Default] != null)
            {
                IAstNodeProperty defaultProperty = addColumnNode.Properties[MdlSyntax.Default];

                IAddConstraintNode addConstraintNode = new AddConstraintNode(addColumnNode, "");
                addConstraintNode.Location = defaultProperty.Location;
                addConstraintNode.Properties.AddProperty(new AstNodeProperty(MdlSyntax.Default, defaultProperty.Value));

                addColumnNode.ChildNodes.Add(addConstraintNode);
            } // if
        }
예제 #2
0
        /// <summary>
        /// Builds up an AST with <paramref name="rootNode"/> as a root node 
        /// from the provided <paramref name="schema"/>.
        /// </summary>
        /// <param name="rootNode"></param>
        /// <param name="schema"></param>
        /// <returns></returns>
        public static IAstNode BuildAstNodeFromSchema(IAstNode rootNode, Schema schema)
        {
            foreach(ITableDefinition table in schema.Tables)
            {
                IAddTableNode addTableNode = new AddTableNode(rootNode, table.Name);
                rootNode.ChildNodes.Add(addTableNode);

                foreach(IColumnDefinition column in table.Columns)
                {
                    IAddColumnNode addColumnNode = new AddColumnNode(addTableNode, column.Name);
                    addTableNode.ChildNodes.Add(addColumnNode);

                    SemanticModelUtil.Copy(column, addColumnNode);
                    CopyProperties(column, addColumnNode);
                } // foreach

                foreach(IIndexDefinition index in table.Indexes)
                {
                    IAddIndexNode addIndexNode = new AddIndexNode(rootNode, index.Name);
                    rootNode.ChildNodes.Add(addIndexNode);

                    SemanticModelUtil.Copy(index, addIndexNode);
                    CopyProperties(index, addIndexNode);
                } // foreach

                foreach(IReferenceDefinition reference in table.References)
                {
                    IAddReferenceNode addReferenceNode = new AddReferenceNode(rootNode, reference.Name);
                    rootNode.ChildNodes.Add(addReferenceNode);

                    SemanticModelUtil.Copy(reference, addReferenceNode);
                    CopyProperties(reference, addReferenceNode);
                } // foreach
            } // foreach

            return rootNode;
        }