public List <Service> LoadMany(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} " +
                             ServiceTable.GetColumnNames("[s]") +
                             (this.Depth > 0 ? "," + ApplicationTable.GetColumnNames("[s_a]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_a_i]") : string.Empty) +
                             (this.Depth > 1 ? "," + ApplicationTypeTable.GetColumnNames("[s_a_at]") : string.Empty) +
                             (this.Depth > 1 ? "," + RuntimeTypeTable.GetColumnNames("[s_a_rt]") : string.Empty) +
                             (this.Depth > 0 ? "," + ProductTable.GetColumnNames("[s_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_p_i]") : string.Empty) +
                             (this.Depth > 0 ? "," + MerchantTable.GetColumnNames("[s_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_m_i]") : string.Empty) +
                             (this.Depth > 1 ? "," + TemplateTable.GetColumnNames("[s_m_t]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceTypeTable.GetColumnNames("[s_st]") : string.Empty) +
                             (this.Depth > 0 ? "," + UserSessionTypeTable.GetColumnNames("[s_ust]") : string.Empty) +
                             (this.Depth > 0 ? "," + CountryTable.GetColumnNames("[s_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[s_c_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + LanguageTable.GetColumnNames("[s_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceConfigurationTable.GetColumnNames("[s_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + PaymentConfigurationTable.GetColumnNames("[s_sc_pc]") : string.Empty) +
                             (this.Depth > 0 ? "," + TemplateTable.GetColumnNames("[s_t]") : string.Empty) +
                             " FROM [core].[Service] AS [s] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Application] AS [s_a] ON [s].[ApplicationID] = [s_a].[ApplicationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_a_i] ON [s_a].[InstanceID] = [s_a_i].[InstanceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ApplicationType] AS [s_a_at] ON [s_a].[ApplicationTypeID] = [s_a_at].[ApplicationTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[RuntimeType] AS [s_a_rt] ON [s_a].[RuntimeTypeID] = [s_a_rt].[RuntimeTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Product] AS [s_p] ON [s].[ProductID] = [s_p].[ProductID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_p_i] ON [s_p].[InstanceID] = [s_p_i].[InstanceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Merchant] AS [s_m] ON [s].[MerchantID] = [s_m].[MerchantID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_m_i] ON [s_m].[InstanceID] = [s_m_i].[InstanceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Template] AS [s_m_t] ON [s_m].[TemplateID] = [s_m_t].[TemplateID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceType] AS [s_st] ON [s].[ServiceTypeID] = [s_st].[ServiceTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[UserSessionType] AS [s_ust] ON [s].[UserSessionTypeID] = [s_ust].[UserSessionTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Country] AS [s_c] ON [s].[FallbackCountryID] = [s_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [s_c_l] ON [s_c].[LanguageID] = [s_c_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Language] AS [s_l] ON [s].[FallbackLanguageID] = [s_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceConfiguration] AS [s_sc] ON [s].[ServiceConfigurationID] = [s_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentConfiguration] AS [s_sc_pc] ON [s_sc].[PaymentConfigurationID] = [s_sc_pc].[PaymentConfigurationID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Template] AS [s_t] ON [s].[TemplateID] = [s_t].[TemplateID] ";
                }


                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("s", "customloadmany", "notfound"), "Service list could not be loaded using custom logic as no items were found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(new List <Service>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ServiceTable              sTable       = new ServiceTable(query);
                ApplicationTable          s_aTable     = (this.Depth > 0) ? new ApplicationTable(query) : null;
                InstanceTable             s_a_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                ApplicationTypeTable      s_a_atTable  = (this.Depth > 1) ? new ApplicationTypeTable(query) : null;
                RuntimeTypeTable          s_a_rtTable  = (this.Depth > 1) ? new RuntimeTypeTable(query) : null;
                ProductTable              s_pTable     = (this.Depth > 0) ? new ProductTable(query) : null;
                InstanceTable             s_p_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                MerchantTable             s_mTable     = (this.Depth > 0) ? new MerchantTable(query) : null;
                InstanceTable             s_m_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                TemplateTable             s_m_tTable   = (this.Depth > 1) ? new TemplateTable(query) : null;
                ServiceTypeTable          s_stTable    = (this.Depth > 0) ? new ServiceTypeTable(query) : null;
                UserSessionTypeTable      s_ustTable   = (this.Depth > 0) ? new UserSessionTypeTable(query) : null;
                CountryTable              s_cTable     = (this.Depth > 0) ? new CountryTable(query) : null;
                LanguageTable             s_c_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                LanguageTable             s_lTable     = (this.Depth > 0) ? new LanguageTable(query) : null;
                ServiceConfigurationTable s_scTable    = (this.Depth > 0) ? new ServiceConfigurationTable(query) : null;
                PaymentConfigurationTable s_sc_pcTable = (this.Depth > 1) ? new PaymentConfigurationTable(query) : null;
                TemplateTable             s_tTable     = (this.Depth > 0) ? new TemplateTable(query) : null;

                List <Service> result = new List <Service>();
                do
                {
                    Instance             s_a_iObject   = (this.Depth > 1) ? s_a_iTable.CreateInstance() : null;
                    ApplicationType      s_a_atObject  = (this.Depth > 1) ? s_a_atTable.CreateInstance() : null;
                    RuntimeType          s_a_rtObject  = (this.Depth > 1) ? s_a_rtTable.CreateInstance() : null;
                    Application          s_aObject     = (this.Depth > 0) ? s_aTable.CreateInstance(s_a_iObject, s_a_atObject, s_a_rtObject) : null;
                    Instance             s_p_iObject   = (this.Depth > 1) ? s_p_iTable.CreateInstance() : null;
                    Product              s_pObject     = (this.Depth > 0) ? s_pTable.CreateInstance(s_p_iObject) : null;
                    Instance             s_m_iObject   = (this.Depth > 1) ? s_m_iTable.CreateInstance() : null;
                    Template             s_m_tObject   = (this.Depth > 1) ? s_m_tTable.CreateInstance() : null;
                    Merchant             s_mObject     = (this.Depth > 0) ? s_mTable.CreateInstance(s_m_iObject, s_m_tObject) : null;
                    ServiceType          s_stObject    = (this.Depth > 0) ? s_stTable.CreateInstance() : null;
                    UserSessionType      s_ustObject   = (this.Depth > 0) ? s_ustTable.CreateInstance() : null;
                    Language             s_c_lObject   = (this.Depth > 1) ? s_c_lTable.CreateInstance() : null;
                    Country              s_cObject     = (this.Depth > 0) ? s_cTable.CreateInstance(s_c_lObject) : null;
                    Language             s_lObject     = (this.Depth > 0) ? s_lTable.CreateInstance() : null;
                    PaymentConfiguration s_sc_pcObject = (this.Depth > 1) ? s_sc_pcTable.CreateInstance() : null;
                    ServiceConfiguration s_scObject    = (this.Depth > 0) ? s_scTable.CreateInstance(s_sc_pcObject) : null;
                    Template             s_tObject     = (this.Depth > 0) ? s_tTable.CreateInstance() : null;
                    Service              sObject       = (this.Depth > -1) ? sTable.CreateInstance(s_aObject, s_pObject, s_mObject, s_stObject, s_ustObject, s_cObject, s_lObject, s_scObject, s_tObject) : null;
                    result.Add(sObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("s", "customloadmany", "exception"), "Service list 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, "Service", "Exception while loading (custom/many) Service object from database. See inner exception for details.", ex);
            }
        }
        protected override Service 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 " +
                             ServiceTable.GetColumnNames("[s]") +
                             (this.Depth > 0 ? "," + ApplicationTable.GetColumnNames("[s_a]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_a_i]") : string.Empty) +
                             (this.Depth > 1 ? "," + ApplicationTypeTable.GetColumnNames("[s_a_at]") : string.Empty) +
                             (this.Depth > 1 ? "," + RuntimeTypeTable.GetColumnNames("[s_a_rt]") : string.Empty) +
                             (this.Depth > 0 ? "," + ProductTable.GetColumnNames("[s_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_p_i]") : string.Empty) +
                             (this.Depth > 0 ? "," + MerchantTable.GetColumnNames("[s_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[s_m_i]") : string.Empty) +
                             (this.Depth > 1 ? "," + TemplateTable.GetColumnNames("[s_m_t]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceTypeTable.GetColumnNames("[s_st]") : string.Empty) +
                             (this.Depth > 0 ? "," + UserSessionTypeTable.GetColumnNames("[s_ust]") : string.Empty) +
                             (this.Depth > 0 ? "," + CountryTable.GetColumnNames("[s_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[s_c_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + LanguageTable.GetColumnNames("[s_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceConfigurationTable.GetColumnNames("[s_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + PaymentConfigurationTable.GetColumnNames("[s_sc_pc]") : string.Empty) +
                             (this.Depth > 0 ? "," + TemplateTable.GetColumnNames("[s_t]") : string.Empty) +
                             " FROM [core].[Service] AS [s] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Application] AS [s_a] ON [s].[ApplicationID] = [s_a].[ApplicationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_a_i] ON [s_a].[InstanceID] = [s_a_i].[InstanceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ApplicationType] AS [s_a_at] ON [s_a].[ApplicationTypeID] = [s_a_at].[ApplicationTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[RuntimeType] AS [s_a_rt] ON [s_a].[RuntimeTypeID] = [s_a_rt].[RuntimeTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Product] AS [s_p] ON [s].[ProductID] = [s_p].[ProductID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_p_i] ON [s_p].[InstanceID] = [s_p_i].[InstanceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Merchant] AS [s_m] ON [s].[MerchantID] = [s_m].[MerchantID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Instance] AS [s_m_i] ON [s_m].[InstanceID] = [s_m_i].[InstanceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Template] AS [s_m_t] ON [s_m].[TemplateID] = [s_m_t].[TemplateID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceType] AS [s_st] ON [s].[ServiceTypeID] = [s_st].[ServiceTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[UserSessionType] AS [s_ust] ON [s].[UserSessionTypeID] = [s_ust].[UserSessionTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Country] AS [s_c] ON [s].[FallbackCountryID] = [s_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [s_c_l] ON [s_c].[LanguageID] = [s_c_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Language] AS [s_l] ON [s].[FallbackLanguageID] = [s_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ServiceConfiguration] AS [s_sc] ON [s].[ServiceConfigurationID] = [s_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentConfiguration] AS [s_sc_pc] ON [s_sc].[PaymentConfigurationID] = [s_sc_pc].[PaymentConfigurationID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Template] AS [s_t] ON [s].[TemplateID] = [s_t].[TemplateID] ";
                }
                sqlCmdText += "WHERE [s].[ServiceID] = @ServiceID;";

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

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("s", "loadinternal", "notfound"), "Service 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);

                ServiceTable              sTable       = new ServiceTable(query);
                ApplicationTable          s_aTable     = (this.Depth > 0) ? new ApplicationTable(query) : null;
                InstanceTable             s_a_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                ApplicationTypeTable      s_a_atTable  = (this.Depth > 1) ? new ApplicationTypeTable(query) : null;
                RuntimeTypeTable          s_a_rtTable  = (this.Depth > 1) ? new RuntimeTypeTable(query) : null;
                ProductTable              s_pTable     = (this.Depth > 0) ? new ProductTable(query) : null;
                InstanceTable             s_p_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                MerchantTable             s_mTable     = (this.Depth > 0) ? new MerchantTable(query) : null;
                InstanceTable             s_m_iTable   = (this.Depth > 1) ? new InstanceTable(query) : null;
                TemplateTable             s_m_tTable   = (this.Depth > 1) ? new TemplateTable(query) : null;
                ServiceTypeTable          s_stTable    = (this.Depth > 0) ? new ServiceTypeTable(query) : null;
                UserSessionTypeTable      s_ustTable   = (this.Depth > 0) ? new UserSessionTypeTable(query) : null;
                CountryTable              s_cTable     = (this.Depth > 0) ? new CountryTable(query) : null;
                LanguageTable             s_c_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                LanguageTable             s_lTable     = (this.Depth > 0) ? new LanguageTable(query) : null;
                ServiceConfigurationTable s_scTable    = (this.Depth > 0) ? new ServiceConfigurationTable(query) : null;
                PaymentConfigurationTable s_sc_pcTable = (this.Depth > 1) ? new PaymentConfigurationTable(query) : null;
                TemplateTable             s_tTable     = (this.Depth > 0) ? new TemplateTable(query) : null;


                Instance             s_a_iObject   = (this.Depth > 1) ? s_a_iTable.CreateInstance() : null;
                ApplicationType      s_a_atObject  = (this.Depth > 1) ? s_a_atTable.CreateInstance() : null;
                RuntimeType          s_a_rtObject  = (this.Depth > 1) ? s_a_rtTable.CreateInstance() : null;
                Application          s_aObject     = (this.Depth > 0) ? s_aTable.CreateInstance(s_a_iObject, s_a_atObject, s_a_rtObject) : null;
                Instance             s_p_iObject   = (this.Depth > 1) ? s_p_iTable.CreateInstance() : null;
                Product              s_pObject     = (this.Depth > 0) ? s_pTable.CreateInstance(s_p_iObject) : null;
                Instance             s_m_iObject   = (this.Depth > 1) ? s_m_iTable.CreateInstance() : null;
                Template             s_m_tObject   = (this.Depth > 1) ? s_m_tTable.CreateInstance() : null;
                Merchant             s_mObject     = (this.Depth > 0) ? s_mTable.CreateInstance(s_m_iObject, s_m_tObject) : null;
                ServiceType          s_stObject    = (this.Depth > 0) ? s_stTable.CreateInstance() : null;
                UserSessionType      s_ustObject   = (this.Depth > 0) ? s_ustTable.CreateInstance() : null;
                Language             s_c_lObject   = (this.Depth > 1) ? s_c_lTable.CreateInstance() : null;
                Country              s_cObject     = (this.Depth > 0) ? s_cTable.CreateInstance(s_c_lObject) : null;
                Language             s_lObject     = (this.Depth > 0) ? s_lTable.CreateInstance() : null;
                PaymentConfiguration s_sc_pcObject = (this.Depth > 1) ? s_sc_pcTable.CreateInstance() : null;
                ServiceConfiguration s_scObject    = (this.Depth > 0) ? s_scTable.CreateInstance(s_sc_pcObject) : null;
                Template             s_tObject     = (this.Depth > 0) ? s_tTable.CreateInstance() : null;
                Service              sObject       = sTable.CreateInstance(s_aObject, s_pObject, s_mObject, s_stObject, s_ustObject, s_cObject, s_lObject, s_scObject, s_tObject);
                sqlReader.Close();

                return(sObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("s", "loadinternal", "exception"), "Service 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, "Service", "Exception while loading Service object from database. See inner exception for details.", ex);
            }
        }
Exemple #3
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 #4
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);
            }
        }
Exemple #5
0
        protected override PaymentConfiguration 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 " +
                             PaymentConfigurationTable.GetColumnNames("[pc]") +
                             (this.Depth > 0 ? "," + PaymentCredentialsTable.GetColumnNames("[pc_pc]") : string.Empty) +
                             (this.Depth > 0 ? "," + PaymentInterfaceTable.GetColumnNames("[pc_pi]") : string.Empty) +
                             (this.Depth > 0 ? "," + PaymentProviderTable.GetColumnNames("[pc_pp]") : string.Empty) +
                             (this.Depth > 0 ? "," + BehaviorModelTable.GetColumnNames("[pc_bm]") : string.Empty) +
                             " FROM [core].[PaymentConfiguration] AS [pc] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentCredentials] AS [pc_pc] ON [pc].[PaymentCredentialsID] = [pc_pc].[PaymentCredentialsID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentInterface] AS [pc_pi] ON [pc].[PaymentInterfaceID] = [pc_pi].[PaymentInterfaceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentProvider] AS [pc_pp] ON [pc].[PaymentProviderID] = [pc_pp].[PaymentProviderID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[BehaviorModel] AS [pc_bm] ON [pc].[BehaviorModelID] = [pc_bm].[BehaviorModelID] ";
                }
                sqlCmdText += "WHERE [pc].[PaymentConfigurationID] = @PaymentConfigurationID;";

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

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "loadinternal", "notfound"), "PaymentConfiguration 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);

                PaymentConfigurationTable pcTable    = new PaymentConfigurationTable(query);
                PaymentCredentialsTable   pc_pcTable = (this.Depth > 0) ? new PaymentCredentialsTable(query) : null;
                PaymentInterfaceTable     pc_piTable = (this.Depth > 0) ? new PaymentInterfaceTable(query) : null;
                PaymentProviderTable      pc_ppTable = (this.Depth > 0) ? new PaymentProviderTable(query) : null;
                BehaviorModelTable        pc_bmTable = (this.Depth > 0) ? new BehaviorModelTable(query) : null;


                PaymentCredentials   pc_pcObject = (this.Depth > 0) ? pc_pcTable.CreateInstance() : null;
                PaymentInterface     pc_piObject = (this.Depth > 0) ? pc_piTable.CreateInstance() : null;
                PaymentProvider      pc_ppObject = (this.Depth > 0) ? pc_ppTable.CreateInstance() : null;
                BehaviorModel        pc_bmObject = (this.Depth > 0) ? pc_bmTable.CreateInstance() : null;
                PaymentConfiguration pcObject    = pcTable.CreateInstance(pc_pcObject, pc_piObject, pc_ppObject, pc_bmObject);
                sqlReader.Close();

                return(pcObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "loadinternal", "exception"), "PaymentConfiguration 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, "PaymentConfiguration", "Exception while loading PaymentConfiguration object from database. See inner exception for details.", ex);
            }
        }
Exemple #6
0
        public List <PaymentConfiguration> LoadMany(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} " +
                             PaymentConfigurationTable.GetColumnNames("[pc]") +
                             (this.Depth > 0 ? "," + PaymentCredentialsTable.GetColumnNames("[pc_pc]") : string.Empty) +
                             (this.Depth > 0 ? "," + PaymentInterfaceTable.GetColumnNames("[pc_pi]") : string.Empty) +
                             (this.Depth > 0 ? "," + PaymentProviderTable.GetColumnNames("[pc_pp]") : string.Empty) +
                             (this.Depth > 0 ? "," + BehaviorModelTable.GetColumnNames("[pc_bm]") : string.Empty) +
                             " FROM [core].[PaymentConfiguration] AS [pc] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentCredentials] AS [pc_pc] ON [pc].[PaymentCredentialsID] = [pc_pc].[PaymentCredentialsID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentInterface] AS [pc_pi] ON [pc].[PaymentInterfaceID] = [pc_pi].[PaymentInterfaceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[PaymentProvider] AS [pc_pp] ON [pc].[PaymentProviderID] = [pc_pp].[PaymentProviderID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[BehaviorModel] AS [pc_bm] ON [pc].[BehaviorModelID] = [pc_bm].[BehaviorModelID] ";
                }


                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("pc", "customloadmany", "notfound"), "PaymentConfiguration list could not be loaded using custom logic as no items were found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(new List <PaymentConfiguration>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                PaymentConfigurationTable pcTable    = new PaymentConfigurationTable(query);
                PaymentCredentialsTable   pc_pcTable = (this.Depth > 0) ? new PaymentCredentialsTable(query) : null;
                PaymentInterfaceTable     pc_piTable = (this.Depth > 0) ? new PaymentInterfaceTable(query) : null;
                PaymentProviderTable      pc_ppTable = (this.Depth > 0) ? new PaymentProviderTable(query) : null;
                BehaviorModelTable        pc_bmTable = (this.Depth > 0) ? new BehaviorModelTable(query) : null;

                List <PaymentConfiguration> result = new List <PaymentConfiguration>();
                do
                {
                    PaymentCredentials   pc_pcObject = (this.Depth > 0) ? pc_pcTable.CreateInstance() : null;
                    PaymentInterface     pc_piObject = (this.Depth > 0) ? pc_piTable.CreateInstance() : null;
                    PaymentProvider      pc_ppObject = (this.Depth > 0) ? pc_ppTable.CreateInstance() : null;
                    BehaviorModel        pc_bmObject = (this.Depth > 0) ? pc_bmTable.CreateInstance() : null;
                    PaymentConfiguration pcObject    = (this.Depth > -1) ? pcTable.CreateInstance(pc_pcObject, pc_piObject, pc_ppObject, pc_bmObject) : null;
                    result.Add(pcObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "customloadmany", "exception"), "PaymentConfiguration list 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, "PaymentConfiguration", "Exception while loading (custom/many) PaymentConfiguration object from database. See inner exception for details.", ex);
            }
        }