コード例 #1
0
        public List <TranslationKey> 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} " +
                             TranslationKeyTable.GetColumnNames("[tk]") +
                             (this.Depth > 0 ? "," + TranslationKeyTable.GetColumnNames("[tk_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationKeyTable.GetColumnNames("[tk_tk_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationTable.GetColumnNames("[tk_tk_t]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tk_tk_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[tk_tk_s]") : string.Empty) +
                             (this.Depth > 0 ? "," + TranslationTable.GetColumnNames("[tk_t]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationTypeTable.GetColumnNames("[tk_t_tt]") : string.Empty) +
                             (this.Depth > 0 ? "," + LanguageTable.GetColumnNames("[tk_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceTable.GetColumnNames("[tk_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + ApplicationTable.GetColumnNames("[tk_s_a]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProductTable.GetColumnNames("[tk_s_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + MerchantTable.GetColumnNames("[tk_s_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTypeTable.GetColumnNames("[tk_s_st]") : string.Empty) +
                             (this.Depth > 1 ? "," + UserSessionTypeTable.GetColumnNames("[tk_s_ust]") : string.Empty) +
                             (this.Depth > 1 ? "," + CountryTable.GetColumnNames("[tk_s_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tk_s_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceConfigurationTable.GetColumnNames("[tk_s_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + TemplateTable.GetColumnNames("[tk_s_t]") : string.Empty) +
                             " FROM [core].[TranslationKey] AS [tk] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[TranslationKey] AS [tk_tk] ON [tk].[FallbackTranslationKeyID] = [tk_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[TranslationKey] AS [tk_tk_tk] ON [tk_tk].[FallbackTranslationKeyID] = [tk_tk_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Translation] AS [tk_tk_t] ON [tk_tk].[TranslationID] = [tk_tk_t].[TranslationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tk_tk_l] ON [tk_tk].[LanguageID] = [tk_tk_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [tk_tk_s] ON [tk_tk].[ServiceID] = [tk_tk_s].[ServiceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Translation] AS [tk_t] ON [tk].[TranslationID] = [tk_t].[TranslationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationType] AS [tk_t_tt] ON [tk_t].[TranslationTypeID] = [tk_t_tt].[TranslationTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tk_l] ON [tk].[LanguageID] = [tk_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [tk_s] ON [tk].[ServiceID] = [tk_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Application] AS [tk_s_a] ON [tk_s].[ApplicationID] = [tk_s_a].[ApplicationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Product] AS [tk_s_p] ON [tk_s].[ProductID] = [tk_s_p].[ProductID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Merchant] AS [tk_s_m] ON [tk_s].[MerchantID] = [tk_s_m].[MerchantID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[ServiceType] AS [tk_s_st] ON [tk_s].[ServiceTypeID] = [tk_s_st].[ServiceTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[UserSessionType] AS [tk_s_ust] ON [tk_s].[UserSessionTypeID] = [tk_s_ust].[UserSessionTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Country] AS [tk_s_c] ON [tk_s].[FallbackCountryID] = [tk_s_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tk_s_l] ON [tk_s].[FallbackLanguageID] = [tk_s_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[ServiceConfiguration] AS [tk_s_sc] ON [tk_s].[ServiceConfigurationID] = [tk_s_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Template] AS [tk_s_t] ON [tk_s].[TemplateID] = [tk_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("tk", "customloadmany", "notfound"), "TranslationKey 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 <TranslationKey>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                TranslationKeyTable       tkTable       = new TranslationKeyTable(query);
                TranslationKeyTable       tk_tkTable    = (this.Depth > 0) ? new TranslationKeyTable(query) : null;
                TranslationKeyTable       tk_tk_tkTable = (this.Depth > 1) ? new TranslationKeyTable(query) : null;
                TranslationTable          tk_tk_tTable  = (this.Depth > 1) ? new TranslationTable(query) : null;
                LanguageTable             tk_tk_lTable  = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceTable              tk_tk_sTable  = (this.Depth > 1) ? new ServiceTable(query) : null;
                TranslationTable          tk_tTable     = (this.Depth > 0) ? new TranslationTable(query) : null;
                TranslationTypeTable      tk_t_ttTable  = (this.Depth > 1) ? new TranslationTypeTable(query) : null;
                LanguageTable             tk_lTable     = (this.Depth > 0) ? new LanguageTable(query) : null;
                ServiceTable              tk_sTable     = (this.Depth > 0) ? new ServiceTable(query) : null;
                ApplicationTable          tk_s_aTable   = (this.Depth > 1) ? new ApplicationTable(query) : null;
                ProductTable              tk_s_pTable   = (this.Depth > 1) ? new ProductTable(query) : null;
                MerchantTable             tk_s_mTable   = (this.Depth > 1) ? new MerchantTable(query) : null;
                ServiceTypeTable          tk_s_stTable  = (this.Depth > 1) ? new ServiceTypeTable(query) : null;
                UserSessionTypeTable      tk_s_ustTable = (this.Depth > 1) ? new UserSessionTypeTable(query) : null;
                CountryTable              tk_s_cTable   = (this.Depth > 1) ? new CountryTable(query) : null;
                LanguageTable             tk_s_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceConfigurationTable tk_s_scTable  = (this.Depth > 1) ? new ServiceConfigurationTable(query) : null;
                TemplateTable             tk_s_tTable   = (this.Depth > 1) ? new TemplateTable(query) : null;

                List <TranslationKey> result = new List <TranslationKey>();
                do
                {
                    TranslationKey       tk_tk_tkObject = (this.Depth > 1) ? tk_tk_tkTable.CreateInstance() : null;
                    Translation          tk_tk_tObject  = (this.Depth > 1) ? tk_tk_tTable.CreateInstance() : null;
                    Language             tk_tk_lObject  = (this.Depth > 1) ? tk_tk_lTable.CreateInstance() : null;
                    Service              tk_tk_sObject  = (this.Depth > 1) ? tk_tk_sTable.CreateInstance() : null;
                    TranslationKey       tk_tkObject    = (this.Depth > 0) ? tk_tkTable.CreateInstance(tk_tk_tkObject, tk_tk_tObject, tk_tk_lObject, tk_tk_sObject) : null;
                    TranslationType      tk_t_ttObject  = (this.Depth > 1) ? tk_t_ttTable.CreateInstance() : null;
                    Translation          tk_tObject     = (this.Depth > 0) ? tk_tTable.CreateInstance(tk_t_ttObject) : null;
                    Language             tk_lObject     = (this.Depth > 0) ? tk_lTable.CreateInstance() : null;
                    Application          tk_s_aObject   = (this.Depth > 1) ? tk_s_aTable.CreateInstance() : null;
                    Product              tk_s_pObject   = (this.Depth > 1) ? tk_s_pTable.CreateInstance() : null;
                    Merchant             tk_s_mObject   = (this.Depth > 1) ? tk_s_mTable.CreateInstance() : null;
                    ServiceType          tk_s_stObject  = (this.Depth > 1) ? tk_s_stTable.CreateInstance() : null;
                    UserSessionType      tk_s_ustObject = (this.Depth > 1) ? tk_s_ustTable.CreateInstance() : null;
                    Country              tk_s_cObject   = (this.Depth > 1) ? tk_s_cTable.CreateInstance() : null;
                    Language             tk_s_lObject   = (this.Depth > 1) ? tk_s_lTable.CreateInstance() : null;
                    ServiceConfiguration tk_s_scObject  = (this.Depth > 1) ? tk_s_scTable.CreateInstance() : null;
                    Template             tk_s_tObject   = (this.Depth > 1) ? tk_s_tTable.CreateInstance() : null;
                    Service              tk_sObject     = (this.Depth > 0) ? tk_sTable.CreateInstance(tk_s_aObject, tk_s_pObject, tk_s_mObject, tk_s_stObject, tk_s_ustObject, tk_s_cObject, tk_s_lObject, tk_s_scObject, tk_s_tObject) : null;
                    TranslationKey       tkObject       = (this.Depth > -1) ? tkTable.CreateInstance(tk_tkObject, tk_tObject, tk_lObject, tk_sObject) : null;
                    result.Add(tkObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tk", "customloadmany", "exception"), "TranslationKey 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, "TranslationKey", "Exception while loading (custom/many) TranslationKey object from database. See inner exception for details.", ex);
            }
        }
コード例 #2
0
        protected override TranslationValue 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 " +
                             TranslationValueTable.GetColumnNames("[tv]") +
                             (this.Depth > 0 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationTable.GetColumnNames("[tv_tk_t]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tv_tk_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[tv_tk_s]") : string.Empty) +
                             (this.Depth > 0 ? "," + TranslationGroupKeyTable.GetColumnNames("[tv_tgk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationGroupTable.GetColumnNames("[tv_tgk_tg]") : string.Empty) +
                             " FROM [core].[TranslationValue] AS [tv] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationKey] AS [tv_tk] ON [tv].[TranslationKeyID] = [tv_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[TranslationKey] AS [tv_tk_tk] ON [tv_tk].[FallbackTranslationKeyID] = [tv_tk_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Translation] AS [tv_tk_t] ON [tv_tk].[TranslationID] = [tv_tk_t].[TranslationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tv_tk_l] ON [tv_tk].[LanguageID] = [tv_tk_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [tv_tk_s] ON [tv_tk].[ServiceID] = [tv_tk_s].[ServiceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationGroupKey] AS [tv_tgk] ON [tv].[TranslationGroupKeyID] = [tv_tgk].[TranslationGroupKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationGroup] AS [tv_tgk_tg] ON [tv_tgk].[TranslationGroupID] = [tv_tgk_tg].[TranslationGroupID] ";
                }
                sqlCmdText += "WHERE [tv].[TranslationValueID] = @TranslationValueID;";

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

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

                TranslationValueTable    tvTable        = new TranslationValueTable(query);
                TranslationKeyTable      tv_tkTable     = (this.Depth > 0) ? new TranslationKeyTable(query) : null;
                TranslationKeyTable      tv_tk_tkTable  = (this.Depth > 1) ? new TranslationKeyTable(query) : null;
                TranslationTable         tv_tk_tTable   = (this.Depth > 1) ? new TranslationTable(query) : null;
                LanguageTable            tv_tk_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceTable             tv_tk_sTable   = (this.Depth > 1) ? new ServiceTable(query) : null;
                TranslationGroupKeyTable tv_tgkTable    = (this.Depth > 0) ? new TranslationGroupKeyTable(query) : null;
                TranslationGroupTable    tv_tgk_tgTable = (this.Depth > 1) ? new TranslationGroupTable(query) : null;


                TranslationKey      tv_tk_tkObject  = (this.Depth > 1) ? tv_tk_tkTable.CreateInstance() : null;
                Translation         tv_tk_tObject   = (this.Depth > 1) ? tv_tk_tTable.CreateInstance() : null;
                Language            tv_tk_lObject   = (this.Depth > 1) ? tv_tk_lTable.CreateInstance() : null;
                Service             tv_tk_sObject   = (this.Depth > 1) ? tv_tk_sTable.CreateInstance() : null;
                TranslationKey      tv_tkObject     = (this.Depth > 0) ? tv_tkTable.CreateInstance(tv_tk_tkObject, tv_tk_tObject, tv_tk_lObject, tv_tk_sObject) : null;
                TranslationGroup    tv_tgk_tgObject = (this.Depth > 1) ? tv_tgk_tgTable.CreateInstance() : null;
                TranslationGroupKey tv_tgkObject    = (this.Depth > 0) ? tv_tgkTable.CreateInstance(tv_tgk_tgObject) : null;
                TranslationValue    tvObject        = tvTable.CreateInstance(tv_tkObject, tv_tgkObject);
                sqlReader.Close();

                return(tvObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tv", "loadinternal", "exception"), "TranslationValue 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, "TranslationValue", "Exception while loading TranslationValue object from database. See inner exception for details.", ex);
            }
        }
コード例 #3
0
        protected override TranslationKey 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 " +
                             TranslationKeyTable.GetColumnNames("[tk]") +
                             (this.Depth > 0 ? "," + TranslationKeyTable.GetColumnNames("[tk_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationKeyTable.GetColumnNames("[tk_tk_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationTable.GetColumnNames("[tk_tk_t]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tk_tk_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[tk_tk_s]") : string.Empty) +
                             (this.Depth > 0 ? "," + TranslationTable.GetColumnNames("[tk_t]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationTypeTable.GetColumnNames("[tk_t_tt]") : string.Empty) +
                             (this.Depth > 0 ? "," + LanguageTable.GetColumnNames("[tk_l]") : string.Empty) +
                             (this.Depth > 0 ? "," + ServiceTable.GetColumnNames("[tk_s]") : string.Empty) +
                             (this.Depth > 1 ? "," + ApplicationTable.GetColumnNames("[tk_s_a]") : string.Empty) +
                             (this.Depth > 1 ? "," + ProductTable.GetColumnNames("[tk_s_p]") : string.Empty) +
                             (this.Depth > 1 ? "," + MerchantTable.GetColumnNames("[tk_s_m]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTypeTable.GetColumnNames("[tk_s_st]") : string.Empty) +
                             (this.Depth > 1 ? "," + UserSessionTypeTable.GetColumnNames("[tk_s_ust]") : string.Empty) +
                             (this.Depth > 1 ? "," + CountryTable.GetColumnNames("[tk_s_c]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tk_s_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceConfigurationTable.GetColumnNames("[tk_s_sc]") : string.Empty) +
                             (this.Depth > 1 ? "," + TemplateTable.GetColumnNames("[tk_s_t]") : string.Empty) +
                             " FROM [core].[TranslationKey] AS [tk] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[TranslationKey] AS [tk_tk] ON [tk].[FallbackTranslationKeyID] = [tk_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[TranslationKey] AS [tk_tk_tk] ON [tk_tk].[FallbackTranslationKeyID] = [tk_tk_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Translation] AS [tk_tk_t] ON [tk_tk].[TranslationID] = [tk_tk_t].[TranslationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tk_tk_l] ON [tk_tk].[LanguageID] = [tk_tk_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [tk_tk_s] ON [tk_tk].[ServiceID] = [tk_tk_s].[ServiceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[Translation] AS [tk_t] ON [tk].[TranslationID] = [tk_t].[TranslationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationType] AS [tk_t_tt] ON [tk_t].[TranslationTypeID] = [tk_t_tt].[TranslationTypeID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tk_l] ON [tk].[LanguageID] = [tk_l].[LanguageID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [tk_s] ON [tk].[ServiceID] = [tk_s].[ServiceID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Application] AS [tk_s_a] ON [tk_s].[ApplicationID] = [tk_s_a].[ApplicationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Product] AS [tk_s_p] ON [tk_s].[ProductID] = [tk_s_p].[ProductID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Merchant] AS [tk_s_m] ON [tk_s].[MerchantID] = [tk_s_m].[MerchantID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[ServiceType] AS [tk_s_st] ON [tk_s].[ServiceTypeID] = [tk_s_st].[ServiceTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[UserSessionType] AS [tk_s_ust] ON [tk_s].[UserSessionTypeID] = [tk_s_ust].[UserSessionTypeID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Country] AS [tk_s_c] ON [tk_s].[FallbackCountryID] = [tk_s_c].[CountryID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tk_s_l] ON [tk_s].[FallbackLanguageID] = [tk_s_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[ServiceConfiguration] AS [tk_s_sc] ON [tk_s].[ServiceConfigurationID] = [tk_s_sc].[ServiceConfigurationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Template] AS [tk_s_t] ON [tk_s].[TemplateID] = [tk_s_t].[TemplateID] ";
                }
                sqlCmdText += "WHERE [tk].[TranslationKeyID] = @TranslationKeyID;";

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

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

                TranslationKeyTable       tkTable       = new TranslationKeyTable(query);
                TranslationKeyTable       tk_tkTable    = (this.Depth > 0) ? new TranslationKeyTable(query) : null;
                TranslationKeyTable       tk_tk_tkTable = (this.Depth > 1) ? new TranslationKeyTable(query) : null;
                TranslationTable          tk_tk_tTable  = (this.Depth > 1) ? new TranslationTable(query) : null;
                LanguageTable             tk_tk_lTable  = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceTable              tk_tk_sTable  = (this.Depth > 1) ? new ServiceTable(query) : null;
                TranslationTable          tk_tTable     = (this.Depth > 0) ? new TranslationTable(query) : null;
                TranslationTypeTable      tk_t_ttTable  = (this.Depth > 1) ? new TranslationTypeTable(query) : null;
                LanguageTable             tk_lTable     = (this.Depth > 0) ? new LanguageTable(query) : null;
                ServiceTable              tk_sTable     = (this.Depth > 0) ? new ServiceTable(query) : null;
                ApplicationTable          tk_s_aTable   = (this.Depth > 1) ? new ApplicationTable(query) : null;
                ProductTable              tk_s_pTable   = (this.Depth > 1) ? new ProductTable(query) : null;
                MerchantTable             tk_s_mTable   = (this.Depth > 1) ? new MerchantTable(query) : null;
                ServiceTypeTable          tk_s_stTable  = (this.Depth > 1) ? new ServiceTypeTable(query) : null;
                UserSessionTypeTable      tk_s_ustTable = (this.Depth > 1) ? new UserSessionTypeTable(query) : null;
                CountryTable              tk_s_cTable   = (this.Depth > 1) ? new CountryTable(query) : null;
                LanguageTable             tk_s_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceConfigurationTable tk_s_scTable  = (this.Depth > 1) ? new ServiceConfigurationTable(query) : null;
                TemplateTable             tk_s_tTable   = (this.Depth > 1) ? new TemplateTable(query) : null;


                TranslationKey       tk_tk_tkObject = (this.Depth > 1) ? tk_tk_tkTable.CreateInstance() : null;
                Translation          tk_tk_tObject  = (this.Depth > 1) ? tk_tk_tTable.CreateInstance() : null;
                Language             tk_tk_lObject  = (this.Depth > 1) ? tk_tk_lTable.CreateInstance() : null;
                Service              tk_tk_sObject  = (this.Depth > 1) ? tk_tk_sTable.CreateInstance() : null;
                TranslationKey       tk_tkObject    = (this.Depth > 0) ? tk_tkTable.CreateInstance(tk_tk_tkObject, tk_tk_tObject, tk_tk_lObject, tk_tk_sObject) : null;
                TranslationType      tk_t_ttObject  = (this.Depth > 1) ? tk_t_ttTable.CreateInstance() : null;
                Translation          tk_tObject     = (this.Depth > 0) ? tk_tTable.CreateInstance(tk_t_ttObject) : null;
                Language             tk_lObject     = (this.Depth > 0) ? tk_lTable.CreateInstance() : null;
                Application          tk_s_aObject   = (this.Depth > 1) ? tk_s_aTable.CreateInstance() : null;
                Product              tk_s_pObject   = (this.Depth > 1) ? tk_s_pTable.CreateInstance() : null;
                Merchant             tk_s_mObject   = (this.Depth > 1) ? tk_s_mTable.CreateInstance() : null;
                ServiceType          tk_s_stObject  = (this.Depth > 1) ? tk_s_stTable.CreateInstance() : null;
                UserSessionType      tk_s_ustObject = (this.Depth > 1) ? tk_s_ustTable.CreateInstance() : null;
                Country              tk_s_cObject   = (this.Depth > 1) ? tk_s_cTable.CreateInstance() : null;
                Language             tk_s_lObject   = (this.Depth > 1) ? tk_s_lTable.CreateInstance() : null;
                ServiceConfiguration tk_s_scObject  = (this.Depth > 1) ? tk_s_scTable.CreateInstance() : null;
                Template             tk_s_tObject   = (this.Depth > 1) ? tk_s_tTable.CreateInstance() : null;
                Service              tk_sObject     = (this.Depth > 0) ? tk_sTable.CreateInstance(tk_s_aObject, tk_s_pObject, tk_s_mObject, tk_s_stObject, tk_s_ustObject, tk_s_cObject, tk_s_lObject, tk_s_scObject, tk_s_tObject) : null;
                TranslationKey       tkObject       = tkTable.CreateInstance(tk_tkObject, tk_tObject, tk_lObject, tk_sObject);
                sqlReader.Close();

                return(tkObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tk", "loadinternal", "exception"), "TranslationKey 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, "TranslationKey", "Exception while loading TranslationKey object from database. See inner exception for details.", ex);
            }
        }
コード例 #4
0
        public List <TranslationValue> 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} " +
                             TranslationValueTable.GetColumnNames("[tv]") +
                             (this.Depth > 0 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationTable.GetColumnNames("[tv_tk_t]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tv_tk_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[tv_tk_s]") : string.Empty) +
                             (this.Depth > 0 ? "," + TranslationGroupKeyTable.GetColumnNames("[tv_tgk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationGroupTable.GetColumnNames("[tv_tgk_tg]") : string.Empty) +
                             " FROM [core].[TranslationValue] AS [tv] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationKey] AS [tv_tk] ON [tv].[TranslationKeyID] = [tv_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[TranslationKey] AS [tv_tk_tk] ON [tv_tk].[FallbackTranslationKeyID] = [tv_tk_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Translation] AS [tv_tk_t] ON [tv_tk].[TranslationID] = [tv_tk_t].[TranslationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tv_tk_l] ON [tv_tk].[LanguageID] = [tv_tk_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [tv_tk_s] ON [tv_tk].[ServiceID] = [tv_tk_s].[ServiceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationGroupKey] AS [tv_tgk] ON [tv].[TranslationGroupKeyID] = [tv_tgk].[TranslationGroupKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationGroup] AS [tv_tgk_tg] ON [tv_tgk].[TranslationGroupID] = [tv_tgk_tg].[TranslationGroupID] ";
                }


                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("tv", "customloadmany", "notfound"), "TranslationValue 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 <TranslationValue>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                TranslationValueTable    tvTable        = new TranslationValueTable(query);
                TranslationKeyTable      tv_tkTable     = (this.Depth > 0) ? new TranslationKeyTable(query) : null;
                TranslationKeyTable      tv_tk_tkTable  = (this.Depth > 1) ? new TranslationKeyTable(query) : null;
                TranslationTable         tv_tk_tTable   = (this.Depth > 1) ? new TranslationTable(query) : null;
                LanguageTable            tv_tk_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceTable             tv_tk_sTable   = (this.Depth > 1) ? new ServiceTable(query) : null;
                TranslationGroupKeyTable tv_tgkTable    = (this.Depth > 0) ? new TranslationGroupKeyTable(query) : null;
                TranslationGroupTable    tv_tgk_tgTable = (this.Depth > 1) ? new TranslationGroupTable(query) : null;

                List <TranslationValue> result = new List <TranslationValue>();
                do
                {
                    TranslationKey      tv_tk_tkObject  = (this.Depth > 1) ? tv_tk_tkTable.CreateInstance() : null;
                    Translation         tv_tk_tObject   = (this.Depth > 1) ? tv_tk_tTable.CreateInstance() : null;
                    Language            tv_tk_lObject   = (this.Depth > 1) ? tv_tk_lTable.CreateInstance() : null;
                    Service             tv_tk_sObject   = (this.Depth > 1) ? tv_tk_sTable.CreateInstance() : null;
                    TranslationKey      tv_tkObject     = (this.Depth > 0) ? tv_tkTable.CreateInstance(tv_tk_tkObject, tv_tk_tObject, tv_tk_lObject, tv_tk_sObject) : null;
                    TranslationGroup    tv_tgk_tgObject = (this.Depth > 1) ? tv_tgk_tgTable.CreateInstance() : null;
                    TranslationGroupKey tv_tgkObject    = (this.Depth > 0) ? tv_tgkTable.CreateInstance(tv_tgk_tgObject) : null;
                    TranslationValue    tvObject        = (this.Depth > -1) ? tvTable.CreateInstance(tv_tkObject, tv_tgkObject) : null;
                    result.Add(tvObject);
                } while (sqlReader.Read());
                sqlReader.Close();

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