Source/NFX/RelationalModel/RDBMSCompiler.cs
/// <summary>
/// Override to compile a RDBMS Table
/// </summary>
Override to compile a RDBMS Table
Override to compile a RDBMS Table
protected virtual void DoColumn(IConfigSectionNode columnNode, RDBMSEntity table, StringBuilder sb, ref bool firstColumn, Outputs outputs)
            {
                var colComment = columnNode.AttrByName(SCRIPT_COMMENT_ATTR).Value;
                if (colComment.IsNotNullOrWhiteSpace())
                    sb.AppendLine("  -- {0}".Args( colComment ) );
                var columnName = columnNode.Value;
                if (columnName.IsNullOrWhiteSpace())
                {
                  m_CompileErrors.Add(new SchemaCompilationException(columnNode.RootPath, "Table '{0}' missing column name.".Args(table.OriginalName)));
                  return;
                }
                var column = new RDBMSEntity(table, columnNode, RDBMSEntityType.Column, columnName, columnNode.AttrByName(SHORT_NAME_ATTR).Value ?? columnName);
                TransformEntityName(column);
                var typeNode = columnNode.Navigate(TYPE_ATTR + "|$"+TYPE_ATTR);
                if (typeNode==null || typeNode.VerbatimValue.IsNullOrWhiteSpace())
                {
                  m_CompileErrors.Add(new SchemaCompilationException(columnNode.RootPath, "Column '{0}' missing {1} attribute.".Args(columnName, TYPE_ATTR)));
                  return;
                }
                var columnType = typeNode.Value;
                var type = new RDBMSEntity(column, typeNode, RDBMSEntityType.Domain, columnType);
                TransformEntityName(type);
                var domain = CreateDomain("{0}.{1}::{2}".Args(table.OriginalName, column.OriginalName, type.OriginalName), type.OriginalName, typeNode);
                if (domain==null)
                {
                    m_CompileErrors.Add(new SchemaCompilationException(columnNode.RootPath, "Domain could not be created: " +type.TransformedName ));
                    return;
                }
                domain.TransformColumnName(this, column);
                if (!firstColumn) sb.AppendLine(",");
                #region Column Line
                {
                    var cn = GetQuotedIdentifierName(RDBMSEntityType.Column, column.TransformedName);
                    var tn = GetQuotedIdentifierName(RDBMSEntityType.Domain, domain.GetTypeName(this));
                    var required = (domain.GetColumnRequirement(this) ?? false) || columnNode.AttrByName(REQUIRED_ATTR).ValueAsBool();
                    var nn = TransformKeywordCase( GetColumnNullNotNullClause(column, required) );
                    var auto = domain.GetColumnAutoGeneratedScript(this, column, outputs);
                    var dfltValue = columnNode.AttrByName(DEFAULT_ATTR).Value ?? domain.GetColumnDefaultScript(this, column, outputs);
                    var dflt = dfltValue.IsNotNullOrWhiteSpace()? "{0} {1}".Args(TransformKeywordCase("default"), EscapeString(dfltValue)) : string.Empty;
                    var chk = domain.GetColumnCheckScript(this, column, outputs);
                    var cmntValue = columnNode.AttrByName(COMMENT_ATTR).Value;
                    var cmnt = cmntValue.IsNotNullOrWhiteSpace()? "{0} {1}".Args(TransformKeywordCase("comment"), EscapeString(cmntValue)) : string.Empty;
                    sb.Append( FormatColumnStatement(cn, tn, nn, auto, dflt, chk, cmnt) );
                }
                #endregion
                firstColumn = false;
                foreach(var colSubNode in columnNode.Children)
                {
                    if (colSubNode.IsSameName(PRIMARY_KEY_SECTION) || colSubNode.IsSameName(REFERENCE_SECTION))
                    {
                        var keyType = colSubNode.IsSameName(PRIMARY_KEY_SECTION) ? RDBMSEntityType.PrimaryKey : RDBMSEntityType.Reference;
                        var keyName = colSubNode.Value;
                        if (keyName.IsNullOrWhiteSpace())
                            keyName = column.OriginalShortName;
                        var key = new RDBMSEntity(column, colSubNode, keyType, keyName, colSubNode.AttrByName(SHORT_NAME_ATTR).Value);
                        TransformEntityName(key);
                    }
                    else  if (colSubNode.IsSameName(TYPE_ATTR)) { } 
                    else
                        m_CompileErrors.Add(new SchemaCompilationException(colSubNode.RootPath,
                                                                           "Unrecognized item inside '{0}.{1}' column, section '{2}'"
                                                                           .Args(table.OriginalName, columnName, colSubNode.Name)));
                }
            }
protected virtual void DoColumn ( IConfigSectionNode columnNode , RDBMSEntity table , StringBuilder sb , ref bool firstColumn , Outputs outputs ) { var colComment = columnNode . AttrByName ( SCRIPT_COMMENT_ATTR ) . Value ; if ( colComment . IsNotNullOrWhiteSpace ( ) ) sb . AppendLine ( " " . Args ( colComment ) ) ; var columnName = columnNode . Value ; if ( columnName . IsNullOrWhiteSpace ( ) ) { m_CompileErrors . Add ( new SchemaCompilationException ( columnNode . RootPath , " " . Args ( table . OriginalName ) ) ) ; return ; } var column = new RDBMSEntity ( table , columnNode , RDBMSEntityType . Column , columnName , columnNode . AttrByName ( SHORT_NAME_ATTR ) . Value ?? columnName ) ; TransformEntityName ( column ) ; var typeNode = columnNode . Navigate ( TYPE_ATTR + " " + TYPE_ATTR ) ; if ( typeNode == null || typeNode . VerbatimValue . IsNullOrWhiteSpace ( ) ) { m_CompileErrors . Add ( new SchemaCompilationException ( columnNode . RootPath , " " . Args ( columnName , TYPE_ATTR ) ) ) ; return ; } var columnType = typeNode . Value ; var type = new RDBMSEntity ( column , typeNode , RDBMSEntityType . Domain , columnType ) ; TransformEntityName ( type ) ; var domain = CreateDomain ( " " . Args ( table . OriginalName , column . OriginalName , type . OriginalName ) , type . OriginalName , typeNode ) ; if ( domain == null ) { m_CompileErrors . Add ( new SchemaCompilationException ( columnNode . RootPath , " " + type . TransformedName ) ) ; return ; } domain . TransformColumnName ( this , column ) ; if ( ! firstColumn ) sb . AppendLine ( " " ) ; region  Column Line { var cn = GetQuotedIdentifierName ( RDBMSEntityType . Column , column . TransformedName ) ; var tn = GetQuotedIdentifierName ( RDBMSEntityType . Domain , domain . GetTypeName ( this ) ) ; var required = ( domain . GetColumnRequirement ( this ) ?? false ) || columnNode . AttrByName ( REQUIRED_ATTR ) . ValueAsBool ( ) ; var nn = TransformKeywordCase ( GetColumnNullNotNullClause ( column , required ) ) ; var auto = domain . GetColumnAutoGeneratedScript ( this , column , outputs ) ; var dfltValue = columnNode . AttrByName ( DEFAULT_ATTR ) . Value ?? domain . GetColumnDefaultScript ( this , column , outputs ) ; var dflt = dfltValue . IsNotNullOrWhiteSpace ( ) ? " " . Args ( TransformKeywordCase ( " " ) , EscapeString ( dfltValue ) ) : string . Empty ; var chk = domain . GetColumnCheckScript ( this , column , outputs ) ; var cmntValue = columnNode . AttrByName ( COMMENT_ATTR ) . Value ; var cmnt = cmntValue . IsNotNullOrWhiteSpace ( ) ? " " . Args ( TransformKeywordCase ( " " ) , EscapeString ( cmntValue ) ) : string . Empty ; sb . Append ( FormatColumnStatement ( cn , tn , nn , auto , dflt , chk , cmnt ) ) ; } endregion firstColumn = false ; foreach ( var colSubNode in columnNode . Children ) { if ( colSubNode . IsSameName ( PRIMARY_KEY_SECTION ) || colSubNode . IsSameName ( REFERENCE_SECTION ) ) { var keyType = colSubNode . IsSameName ( PRIMARY_KEY_SECTION ) ? RDBMSEntityType . PrimaryKey : RDBMSEntityType . Reference ; var keyName = colSubNode . Value ; if ( keyName . IsNullOrWhiteSpace ( ) ) keyName = column . OriginalShortName ; var key = new RDBMSEntity ( column , colSubNode , keyType , keyName , colSubNode . AttrByName ( SHORT_NAME_ATTR ) . Value ) ; TransformEntityName ( key ) ; } else if ( colSubNode . IsSameName ( TYPE_ATTR ) ) { } else m_CompileErrors . Add ( new SchemaCompilationException ( colSubNode . RootPath , " " . Args ( table . OriginalName , columnName , colSubNode . Name ) ) ) ; } }
Override to compile a RDBMS Table
Override to compile a RDBMS Table
//type may be used as section as well
columnNode
IConfigSectionNode
table
RDBMSEntity
sb
StringBuilder
bool
ref
outputs
Outputs