/// <summary> /// Gets a formated name of database object (field, table, index) using formatting /// policy defined by an SqlAgent. /// </summary> /// <param name="unformatedName">unformatted name of the database object</param> /// <param name="sqlAgent">an SqlAgent that defines naming convention</param> public static string ToConventional(this string unformatedName, ISqlAgent sqlAgent) { if (sqlAgent.IsNull()) { throw new ArgumentNullException(nameof(sqlAgent)); } if (unformatedName.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(unformatedName)); } if (sqlAgent.AllSchemaNamesLowerCased) { return(unformatedName.Trim().ToLower()); } return(unformatedName.Trim()); }
/// <summary> /// Gets an SQL query or statement by the token for the SQL agent specified. /// </summary> /// <param name="token">a token (key, name) of the requested query or statement</param> /// <param name="sqlAgent">an SQL agent for which the SQL query or statement is meant for</param> /// <exception cref="ArgumentNullException">Parameters token or sqlAgent are not specified.</exception> /// <exception cref="FileNotFoundException">No repository files found or they contain no data /// for the SQL agent type specified.</exception> /// <exception cref="InvalidDataException">Failed to load SQL repository file due to bad format or duplicate query tokens.</exception> /// <exception cref="InvalidOperationException">SQL query token is unknown or SQL query dictionary is not available for the SQL implementation.</exception> public string GetSqlQuery(string token, ISqlAgent sqlAgent) { if (token.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(token)); } if (sqlAgent.IsNull()) { throw new ArgumentNullException(nameof(sqlAgent)); } if (_tokenDictionary.IsNull()) { lock (_dictLock) { if (_tokenDictionary.IsNull()) { Initialize(); } } } if (!_tokenDictionary.ContainsKey(sqlAgent.SqlImplementationId)) { throw new InvalidOperationException(string.Format(Properties.Resources.SqlDictionaryNotAvailableException, sqlAgent.Name)); } var dictionaryForSqlAgent = _tokenDictionary[sqlAgent.SqlImplementationId]; if (!dictionaryForSqlAgent.ContainsKey(token.Trim())) { throw new InvalidOperationException(string.Format(Properties.Resources.SqlDictionary_UnknownSqlQueryToken, token)); } return(dictionaryForSqlAgent[token.Trim()]); }