/// <summary> /// Gets a parameter value for a specific SqlAgent. /// </summary> /// <param name="sqlAgent">an SqlAgent that requests value and holds formating preferences</param> public object GetValue(ISqlAgent sqlAgent) { if (_value != null && sqlAgent.BooleanStoredAsTinyInt && _value.GetType() == typeof(bool)) { if ((bool)_value) { return(1); } else { return(0); } } if (_value != null && _value.GetType() == typeof(Guid)) { if (sqlAgent.GuidStoredAsBlob) { return(((Guid)_value).ToByteArray()); } else { return(((Guid)_value).ToString("N")); } } return(_value); }
/// <summary> /// Creates a new Orm service. /// </summary> /// <param name="agent">an instance of an Sql agent to use for queries and statements; its implementation /// type should match Orm service implementation type</param> public OrmServiceBase(ISqlAgent agent) { _agent = agent ?? throw new ArgumentNullException(nameof(agent)); if (!_agent.SqlImplementationId.EqualsByConvention(SqlImplementationId)) { throw new ArgumentException(string.Format(Properties.Resources.SqlAgentAndOrmServiceTypeMismatchException, _agent.SqlImplementationId, SqlImplementationId), nameof(agent)); } }
/// <summary> /// Creates a new Orm service. /// </summary> /// <param name="agent">an instance of an Sql agent to use for queries and statements; its implementation /// type should match Orm service implementation type</param> public SchemaManagerBase(ISqlAgent agent) { _agent = agent ?? throw new ArgumentNullException(nameof(agent)); if (!_agent.SqlImplementationId.EqualsByConvention(SqlImplementationId)) { throw new ArgumentException(string.Format(Properties.Resources.SqlAgentAndSchemaManagerTypeMismatchException, _agent.SqlImplementationId, SqlImplementationId), nameof(agent)); } if (_agent.CurrentDatabase.IsNullOrWhiteSpace()) { throw new ArgumentException( Properties.Resources.SchemaManagerRequiresDatabaseException, nameof(agent)); } }
/// <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()]); }