/// <summary> /// Gets the name of the procedure. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public ProcedureName GetProcedureName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var procedureName = new ProcedureName { DbName = dbName }; procedureName.NameWords = ExtractWords(words, dbName, extraction); procedureName.MethodName = Format(words, procedureName.NameWords, nameFormat.Case, Singularization.DontChange); return(procedureName); }
/// <summary> /// Gets the name of the parameter. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public ParameterName GetParameterName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var parameterName = new ParameterName { DbName = dbName }; parameterName.NameWords = ExtractWords(words, dbName, extraction); parameterName.CallName = Format(words, parameterName.NameWords, Case.camelCase, Singularization.DontChange); return(parameterName); }
/// <summary> /// Gets the name of the schema. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public SchemaName GetSchemaName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var schemaName = new SchemaName { DbName = dbName }; schemaName.NameWords = ExtractWords(words, dbName, extraction); schemaName.ClassName = Format(words, schemaName.NameWords, nameFormat.Case, Singularization.DontChange); return(schemaName); }
/// <summary> /// Gets the name of the schema. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public SchemaName GetSchemaName(string dbName, WordsExtraction extraction, NameFormat nameFormat #if !MONO_STRICT , string contextClassNamePostfix #endif ) { var words = GetLanguageWords(nameFormat.Culture); var schemaName = new SchemaName { DbName = dbName }; schemaName.NameWords = ExtractWords(words, dbName, extraction); schemaName.ClassName = Format(words, schemaName.NameWords, nameFormat.Case, Singularization.DontChange); #if !MONO_STRICT schemaName.ClassName += contextClassNamePostfix; #endif return(schemaName); }
/// <summary> /// Gets the name of the association. /// </summary> /// <param name="dbManyName">Name of the db many.</param> /// <param name="dbOneName">Name of the db one.</param> /// <param name="dbConstraintName">Name of the db constraint.</param> /// <param name="foreignKeyName">Name of the foreign key.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public AssociationName GetAssociationName(string dbManyName, string dbOneName, string dbConstraintName, string foreignKeyName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var associationName = new AssociationName { DbName = dbManyName }; associationName.NameWords = ExtractWords(words, dbManyName, extraction); associationName.ManyToOneMemberName = Format(words, dbOneName, nameFormat.Case, GetSingularization(Singularization.Singular, nameFormat)); // TODO: this works only for PascalCase if (dbManyName == dbOneName) { associationName.ManyToOneMemberName = foreignKeyName.Replace(',', '_') + associationName.ManyToOneMemberName; } // TODO: support new extraction associationName.OneToManyMemberName = Format(words, dbManyName, nameFormat.Case, GetSingularization(Singularization.Plural, nameFormat)); return(associationName); }
/// <summary> /// Gets the name of the column. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public ColumnName GetColumnName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var columnName = new ColumnName { DbName = dbName }; columnName.NameWords = ExtractWords(words, dbName, extraction); // if no extraction (preset name, just copy it) if (extraction == WordsExtraction.None) { columnName.PropertyName = dbName; } else { columnName.PropertyName = Format(words, columnName.NameWords, nameFormat.Case, Singularization.DontChange); } return(columnName); }
/// <summary> /// Gets the name of the table. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public TableName GetTableName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var tableName = new TableName { DbName = dbName }; tableName.NameWords = ExtractWords(words, dbName, extraction); // if no extraction (preset name, just copy it) if (extraction == WordsExtraction.None) { tableName.ClassName = tableName.DbName; } else { tableName.ClassName = Format(words, tableName.NameWords, nameFormat.Case, GetSingularization(Singularization.Singular, nameFormat)); } tableName.MemberName = Format(words, tableName.NameWords, nameFormat.Case, GetSingularization(Singularization.Plural, nameFormat)); return(tableName); }
/// <summary> /// Gets the name of the column. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public ColumnName GetColumnName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var columnName = new ColumnName { DbName = dbName }; columnName.NameWords = ExtractWords(words, dbName, extraction); // if no extraction (preset name, just copy it) if (extraction == WordsExtraction.None) columnName.PropertyName = dbName; else columnName.PropertyName = Format(words, columnName.NameWords, nameFormat.Case, Singularization.DontChange); return columnName; }
/// <summary> /// Extracts the words from given text. /// </summary> /// <param name="words">The words.</param> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction type (case or language identification).</param> /// <returns></returns> protected virtual IList<string> ExtractWords(ILanguageWords words, string dbName, WordsExtraction extraction) { switch (extraction) { case WordsExtraction.None: return new[] { dbName }; case WordsExtraction.FromCase: return ExtractWordsFromCase(dbName, SubstitutionChar); case WordsExtraction.FromDictionary: return ExtractWordsFromCaseAndLanguage(words, dbName); default: throw new ArgumentOutOfRangeException("extraction"); } }
/// <summary> /// Creates the name of the table given a name and schema /// </summary> /// <param name="dbTableName">Name of the db table.</param> /// <param name="dbSchema">The db schema.</param> /// <param name="nameAliases">The name aliases.</param> /// <param name="nameFormat">The name format.</param> /// <param name="extraction">The extraction.</param> /// <returns></returns> protected virtual TableName CreateTableName(string dbTableName, string dbSchema, INameAliases nameAliases, NameFormat nameFormat, WordsExtraction extraction) { // if we have an alias, use it, and don't try to analyze it (a human probably already did the job) var tableTypeAlias = nameAliases != null ? nameAliases.GetTableTypeAlias(dbTableName, dbSchema) : null; if (tableTypeAlias != null) extraction = WordsExtraction.None; else tableTypeAlias = dbTableName; var tableName = NameFormatter.GetTableName(tableTypeAlias, extraction, nameFormat); // alias for member var tableMemberAlias = nameAliases != null ? nameAliases.GetTableMemberAlias(dbTableName, dbSchema) : null; if (tableMemberAlias != null) tableName.MemberName = tableMemberAlias; tableName.DbName = GetFullDbName(dbTableName, dbSchema); return tableName; }
/// <summary> /// Extracts the words from given text. /// </summary> /// <param name="words">The words.</param> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction type (case or language identification).</param> /// <returns></returns> protected virtual IList <string> ExtractWords(ILanguageWords words, string dbName, WordsExtraction extraction) { switch (extraction) { case WordsExtraction.None: return(new[] { dbName }); case WordsExtraction.FromCase: return(ExtractWordsFromCase(dbName, SubstitutionChar)); case WordsExtraction.FromDictionary: return(ExtractWordsFromCaseAndLanguage(words, dbName)); default: throw new ArgumentOutOfRangeException("extraction"); } }
/// <summary> /// Gets the name of the schema. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public SchemaName GetSchemaName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var schemaName = new SchemaName { DbName = dbName }; schemaName.NameWords = ExtractWords(words, dbName, extraction); schemaName.ClassName = Format(words, schemaName.NameWords, nameFormat.Case, Singularization.DontChange); return schemaName; }
/// <summary> /// Gets the name of the association. /// </summary> /// <param name="dbManyName">Name of the db many.</param> /// <param name="dbOneName">Name of the db one.</param> /// <param name="dbConstraintName">Name of the db constraint.</param> /// <param name="foreignKeyName">Name of the foreign key.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public AssociationName GetAssociationName(string dbManyName, string dbOneName, string dbConstraintName, string foreignKeyName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var associationName = new AssociationName { DbName = dbManyName }; associationName.NameWords = ExtractWords(words, dbManyName, extraction); associationName.ManyToOneMemberName = Format(words, dbOneName, nameFormat.Case, GetSingularization(Singularization.Singular, nameFormat)); // TODO: this works only for PascalCase if (dbManyName == dbOneName) associationName.ManyToOneMemberName = foreignKeyName.Replace(',', '_') + associationName.ManyToOneMemberName; // TODO: support new extraction associationName.OneToManyMemberName = Format(words, dbManyName, nameFormat.Case, GetSingularization(Singularization.Plural, nameFormat)); return associationName; }
/// <summary> /// Creates the name of the table given a name and schema /// </summary> /// <param name="dbTableName">Name of the db table.</param> /// <param name="dbSchema">The db schema.</param> /// <param name="nameAliases">The name aliases.</param> /// <param name="nameFormat">The name format.</param> /// <param name="extraction">The extraction.</param> /// <returns></returns> protected virtual TableName CreateTableName(string dbTableName, string dbSchema, INameAliases nameAliases, NameFormat nameFormat, WordsExtraction extraction) { // if we have an alias, use it, and don't try to analyze it (a human probably already did the job) var tableTypeAlias = nameAliases != null?nameAliases.GetTableTypeAlias(dbTableName, dbSchema) : null; if (tableTypeAlias != null) { extraction = WordsExtraction.None; } else { tableTypeAlias = dbTableName; } var tableName = NameFormatter.GetTableName(tableTypeAlias, extraction, nameFormat); // alias for member var tableMemberAlias = nameAliases != null?nameAliases.GetTableMemberAlias(dbTableName, dbSchema) : null; if (tableMemberAlias != null) { tableName.MemberName = tableMemberAlias; } tableName.DbName = GetFullDbName(dbTableName, dbSchema); return(tableName); }
/// <summary> /// Gets the name of the table. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public TableName GetTableName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var tableName = new TableName { DbName = dbName }; tableName.NameWords = ExtractWords(words, dbName, extraction); // if no extraction (preset name, just copy it) if (extraction == WordsExtraction.None) tableName.ClassName = tableName.DbName; else tableName.ClassName = Format(words, tableName.NameWords, nameFormat.Case, GetSingularization(Singularization.Singular, nameFormat)); tableName.MemberName = Format(words, tableName.NameWords, nameFormat.Case, GetSingularization(Singularization.Plural, nameFormat)); return tableName; }
/// <summary> /// Gets the name of the parameter. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public ParameterName GetParameterName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var parameterName = new ParameterName { DbName = dbName }; parameterName.NameWords = ExtractWords(words, dbName, extraction); parameterName.CallName = Format(words, parameterName.NameWords, Case.camelCase, Singularization.DontChange); return parameterName; }
/// <summary> /// Gets the name of the procedure. /// </summary> /// <param name="dbName">Name of the db.</param> /// <param name="extraction">The extraction.</param> /// <param name="nameFormat">The name format.</param> /// <returns></returns> public ProcedureName GetProcedureName(string dbName, WordsExtraction extraction, NameFormat nameFormat) { var words = GetLanguageWords(nameFormat.Culture); var procedureName = new ProcedureName { DbName = dbName }; procedureName.NameWords = ExtractWords(words, dbName, extraction); procedureName.MethodName = Format(words, procedureName.NameWords, nameFormat.Case, Singularization.DontChange); return procedureName; }