Source/NFX/RelationalModel/RDBMSCompiler.cs
/// <summary>
/// Override to compile a indexes per table
/// </summary>
Override to compile a indexes per table
Override to compile a indexes per table
protected virtual void DoTableIndexes(RDBMSEntity table, Outputs outputs)
            {
                var sb = m_SeparateIndexes ? outputs[RDBMSCompiler.INDEXES_OUTPUT] : outputs[RDBMSCompiler.TABLES_OUTPUT];
                var indexes = table.Children.Where(c=>c.EntityType==RDBMSEntityType.Index);
                foreach(var idx in indexes)
                {
                   var node = (IConfigSectionNode)idx.SourceNode;
                   var unique = node.AttrByName(UNIQUE_ATTR).ValueAsBool();
                   var colNames = new List<string>();
                   foreach(var col in node.Children.Where(c=>c.IsSameName(COLUMN_SECTION)))
                   {
                       var cn = col.Value;
                       var column = table.Children.FirstOrDefault(c=>c.EntityType==RDBMSEntityType.Column && c.OriginalName.Equals(cn, NameComparison));
                       if (column==null)
                       {
                            m_CompileErrors.Add(new SchemaCompilationException(table.SourceNode.RootPath,
                                                                     "Table '{0}' defines index '{1}' which references column by name '{2}' which does not exist"
                                                                     .Args(table.OriginalName, idx.OriginalName, cn)));
                            return;
                       }
                       var colName =  GetQuotedIdentifierName(RDBMSEntityType.Column, column.TransformedName);
                       var colLen = col.AttrByName(LENGTH_ATTR).ValueAsInt();
                       if (colLen>0) colName += "({0})".Args(colLen);
                       var colOrder = col.AttrByName(ORDER_ATTR).ValueAsEnum<RDBMSSortOrder>();
                       var ord = TransformSortOrder( colOrder );
                       if (ord.IsNotNullOrWhiteSpace())
                         colName = "{0} {1}".Args(colName, ord);
                       colNames.Add( colName );
                   }
                   var colNamesLine = string.Join(", ",colNames);
                   var comment = node.AttrByName(COMMENT_ATTR).Value;
                   var commentClause = comment.IsNullOrWhiteSpace()? string.Empty :
                                       TransformKeywordCase(" comment {0}").Args( EscapeString(comment) );
                   sb.AppendLine(GetStatementDelimiterScript(RDBMSEntityType.Index, true));
                   sb.Append(TransformKeywordCase("  create {0} index {1} on {2}({3}){4}")
                                                        .Args(
                                                          TransformKeywordCase( unique?"unique":string.Empty ),
                                                          GetQuotedIdentifierName( RDBMSEntityType.Index, idx.TransformedName ),
                                                          GetQuotedIdentifierName( RDBMSEntityType.Table, table.TransformedName ),
                                                          colNamesLine,
                                                          commentClause
                                                        )
                               );
                   sb.AppendLine(GetStatementDelimiterScript(RDBMSEntityType.Index, false));
                }
            }
protected virtual void DoTableIndexes ( RDBMSEntity table , Outputs outputs ) { var sb = m_SeparateIndexes ? outputs [ RDBMSCompiler . INDEXES_OUTPUT ] : outputs [ RDBMSCompiler . TABLES_OUTPUT ] ; var indexes = table . Children . Where ( c => c . EntityType == RDBMSEntityType . Index ) ; foreach ( var idx in indexes ) { var node = ( IConfigSectionNode ) idx . SourceNode ; var unique = node . AttrByName ( UNIQUE_ATTR ) . ValueAsBool ( ) ; var colNames = new List < string > ( ) ; foreach ( var col in node . Children . Where ( c => c . IsSameName ( COLUMN_SECTION ) ) ) { var cn = col . Value ; var column = table . Children . FirstOrDefault ( c => c . EntityType == RDBMSEntityType . Column && c . OriginalName . Equals ( cn , NameComparison ) ) ; if ( column == null ) { m_CompileErrors . Add ( new SchemaCompilationException ( table . SourceNode . RootPath , " " . Args ( table . OriginalName , idx . OriginalName , cn ) ) ) ; return ; } var colName = GetQuotedIdentifierName ( RDBMSEntityType . Column , column . TransformedName ) ; var colLen = col . AttrByName ( LENGTH_ATTR ) . ValueAsInt ( ) ; if ( colLen > 0 ) colName += " " . Args ( colLen ) ; var colOrder = col . AttrByName ( ORDER_ATTR ) . ValueAsEnum < RDBMSSortOrder > ( ) ; var ord = TransformSortOrder ( colOrder ) ; if ( ord . IsNotNullOrWhiteSpace ( ) ) colName = " " . Args ( colName , ord ) ; colNames . Add ( colName ) ; } var colNamesLine = string . Join ( " " , colNames ) ; var comment = node . AttrByName ( COMMENT_ATTR ) . Value ; var commentClause = comment . IsNullOrWhiteSpace ( ) ? string . Empty : TransformKeywordCase ( " " ) . Args ( EscapeString ( comment ) ) ; sb . AppendLine ( GetStatementDelimiterScript ( RDBMSEntityType . Index , true ) ) ; sb . Append ( TransformKeywordCase ( " " ) . Args ( TransformKeywordCase ( unique ? " " : string . Empty ) , GetQuotedIdentifierName ( RDBMSEntityType . Index , idx . TransformedName ) , GetQuotedIdentifierName ( RDBMSEntityType . Table , table . TransformedName ) , colNamesLine , commentClause ) ) ; sb . AppendLine ( GetStatementDelimiterScript ( RDBMSEntityType . Index , false ) ) ; } }
Override to compile a indexes per table
Override to compile a indexes per table
table
RDBMSEntity
outputs
Outputs