Exemple #1
0
        public ServiceConfigurationEntry Load(ISqlConnectionInfo connection, SqlQueryParameters parameters)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT {0} " +
                             ServiceConfigurationEntryTable.GetColumnNames("[sce]") +
                             (this.Depth > 0 ? "," + ServiceConfigurationTable.GetColumnNames("[sce_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + PaymentConfigurationTable.GetColumnNames("[sce_sc_pc]") : string.Empty) +
                             " FROM [core].[ServiceConfigurationEntry] AS [sce] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceConfiguration] AS [sce_sc] ON [sce].[ServiceConfigurationID] = [sce_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentConfiguration] AS [sce_sc_pc] ON [sce_sc].[PaymentConfigurationID] = [sce_sc_pc].[PaymentConfigurationID] ";
                }


                parameters.Top = 1;
                sqlCmdText     = parameters.BuildQuery(sqlCmdText);
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                foreach (KeyValuePair <string, object> argument in parameters.Arguments)
                {
                    sqlCmd.Parameters.AddWithValue("@" + argument.Key, argument.Value);
                }

                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("sce", "customload", "notfound"), "ServiceConfigurationEntry could not be loaded using custom logic as it was not found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ServiceConfigurationEntryTable sceTable       = new ServiceConfigurationEntryTable(query);
                ServiceConfigurationTable      sce_scTable    = (this.Depth > 0) ? new ServiceConfigurationTable(query) : null;
                PaymentConfigurationTable      sce_sc_pcTable = (this.Depth > 1) ? new PaymentConfigurationTable(query) : null;


                PaymentConfiguration      sce_sc_pcObject = (this.Depth > 1) ? sce_sc_pcTable.CreateInstance() : null;
                ServiceConfiguration      sce_scObject    = (this.Depth > 0) ? sce_scTable.CreateInstance(sce_sc_pcObject) : null;
                ServiceConfigurationEntry sceObject       = sceTable.CreateInstance(sce_scObject);
                sqlReader.Close();

                return(sceObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("sce", "customload", "exception"), "ServiceConfigurationEntry could not be loaded using custom logic. See exception for details.", sqlCmdText, ex, this, connection, parameters);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "ServiceConfigurationEntry", "Exception while loading (custom/single) ServiceConfigurationEntry object from database. See inner exception for details.", ex);
            }
        }
Exemple #2
0
        protected override ServiceConfigurationEntry LoadInternal(ISqlConnectionInfo connection, int id)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT " +
                             ServiceConfigurationEntryTable.GetColumnNames("[sce]") +
                             (this.Depth > 0 ? "," + ServiceConfigurationTable.GetColumnNames("[sce_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + PaymentConfigurationTable.GetColumnNames("[sce_sc_pc]") : string.Empty) +
                             " FROM [core].[ServiceConfigurationEntry] AS [sce] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceConfiguration] AS [sce_sc] ON [sce].[ServiceConfigurationID] = [sce_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentConfiguration] AS [sce_sc_pc] ON [sce_sc].[PaymentConfigurationID] = [sce_sc_pc].[PaymentConfigurationID] ";
                }
                sqlCmdText += "WHERE [sce].[ServiceConfigurationEntryID] = @ServiceConfigurationEntryID;";

                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@ServiceConfigurationEntryID", id);
                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("sce", "loadinternal", "notfound"), "ServiceConfigurationEntry could not be loaded by id as it was not found.", sqlCmdText, this, connection, id);
                    if (this.Logger.IsWarnEnabled)
                    {
                        this.Logger.Warn(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ServiceConfigurationEntryTable sceTable       = new ServiceConfigurationEntryTable(query);
                ServiceConfigurationTable      sce_scTable    = (this.Depth > 0) ? new ServiceConfigurationTable(query) : null;
                PaymentConfigurationTable      sce_sc_pcTable = (this.Depth > 1) ? new PaymentConfigurationTable(query) : null;


                PaymentConfiguration      sce_sc_pcObject = (this.Depth > 1) ? sce_sc_pcTable.CreateInstance() : null;
                ServiceConfiguration      sce_scObject    = (this.Depth > 0) ? sce_scTable.CreateInstance(sce_sc_pcObject) : null;
                ServiceConfigurationEntry sceObject       = sceTable.CreateInstance(sce_scObject);
                sqlReader.Close();

                return(sceObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("sce", "loadinternal", "exception"), "ServiceConfigurationEntry could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "ServiceConfigurationEntry", "Exception while loading ServiceConfigurationEntry object from database. See inner exception for details.", ex);
            }
        }