protected override Translation 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 " + TranslationTable.GetColumnNames("[t]") + (this.Depth > 0 ? "," + TranslationTypeTable.GetColumnNames("[t_tt]") : string.Empty) + " FROM [core].[Translation] AS [t] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[TranslationType] AS [t_tt] ON [t].[TranslationTypeID] = [t_tt].[TranslationTypeID] "; } sqlCmdText += "WHERE [t].[TranslationID] = @TranslationID;"; SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand; sqlCmd.Parameters.AddWithValue("@TranslationID", id); SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader; if (!sqlReader.HasRows || !sqlReader.Read()) { IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("t", "loadinternal", "notfound"), "Translation 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); TranslationTable tTable = new TranslationTable(query); TranslationTypeTable t_ttTable = (this.Depth > 0) ? new TranslationTypeTable(query) : null; TranslationType t_ttObject = (this.Depth > 0) ? t_ttTable.CreateInstance() : null; Translation tObject = tTable.CreateInstance(t_ttObject); sqlReader.Close(); return(tObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("t", "loadinternal", "exception"), "Translation 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, "Translation", "Exception while loading Translation object from database. See inner exception for details.", ex); } }
public TranslationType 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} " + TranslationTypeTable.GetColumnNames("[tt]") + " FROM [core].[TranslationType] AS [tt] "; 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("tt", "customload", "notfound"), "TranslationType 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); TranslationTypeTable ttTable = new TranslationTypeTable(query); TranslationType ttObject = ttTable.CreateInstance(); sqlReader.Close(); return(ttObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tt", "customload", "exception"), "TranslationType 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, "TranslationType", "Exception while loading (custom/single) TranslationType object from database. See inner exception for details.", ex); } }
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); } }
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); } }
protected override Localization 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 " + LocalizationTable.GetColumnNames("[l]") + (this.Depth > 0 ? "," + ApplicationTable.GetColumnNames("[l_a]") : string.Empty) + (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[l_a_i]") : string.Empty) + (this.Depth > 1 ? "," + ApplicationTypeTable.GetColumnNames("[l_a_at]") : string.Empty) + (this.Depth > 1 ? "," + RuntimeTypeTable.GetColumnNames("[l_a_rt]") : string.Empty) + (this.Depth > 0 ? "," + ProductTable.GetColumnNames("[l_p]") : string.Empty) + (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[l_p_i]") : string.Empty) + (this.Depth > 0 ? "," + TranslationTable.GetColumnNames("[l_t]") : string.Empty) + (this.Depth > 1 ? "," + TranslationTypeTable.GetColumnNames("[l_t_tt]") : string.Empty) + " FROM [core].[Localization] AS [l] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[Application] AS [l_a] ON [l].[ApplicationID] = [l_a].[ApplicationID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[Instance] AS [l_a_i] ON [l_a].[InstanceID] = [l_a_i].[InstanceID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[ApplicationType] AS [l_a_at] ON [l_a].[ApplicationTypeID] = [l_a_at].[ApplicationTypeID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[RuntimeType] AS [l_a_rt] ON [l_a].[RuntimeTypeID] = [l_a_rt].[RuntimeTypeID] "; } if (this.Depth > 0) { sqlCmdText += "LEFT OUTER JOIN [core].[Product] AS [l_p] ON [l].[ProductID] = [l_p].[ProductID] "; } if (this.Depth > 1) { sqlCmdText += "LEFT OUTER JOIN [core].[Instance] AS [l_p_i] ON [l_p].[InstanceID] = [l_p_i].[InstanceID] "; } if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[Translation] AS [l_t] ON [l].[TranslationID] = [l_t].[TranslationID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[TranslationType] AS [l_t_tt] ON [l_t].[TranslationTypeID] = [l_t_tt].[TranslationTypeID] "; } sqlCmdText += "WHERE [l].[LocalizationID] = @LocalizationID;"; SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand; sqlCmd.Parameters.AddWithValue("@LocalizationID", id); SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader; if (!sqlReader.HasRows || !sqlReader.Read()) { IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("l", "loadinternal", "notfound"), "Localization 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); LocalizationTable lTable = new LocalizationTable(query); ApplicationTable l_aTable = (this.Depth > 0) ? new ApplicationTable(query) : null; InstanceTable l_a_iTable = (this.Depth > 1) ? new InstanceTable(query) : null; ApplicationTypeTable l_a_atTable = (this.Depth > 1) ? new ApplicationTypeTable(query) : null; RuntimeTypeTable l_a_rtTable = (this.Depth > 1) ? new RuntimeTypeTable(query) : null; ProductTable l_pTable = (this.Depth > 0) ? new ProductTable(query) : null; InstanceTable l_p_iTable = (this.Depth > 1) ? new InstanceTable(query) : null; TranslationTable l_tTable = (this.Depth > 0) ? new TranslationTable(query) : null; TranslationTypeTable l_t_ttTable = (this.Depth > 1) ? new TranslationTypeTable(query) : null; Instance l_a_iObject = (this.Depth > 1) ? l_a_iTable.CreateInstance() : null; ApplicationType l_a_atObject = (this.Depth > 1) ? l_a_atTable.CreateInstance() : null; RuntimeType l_a_rtObject = (this.Depth > 1) ? l_a_rtTable.CreateInstance() : null; Application l_aObject = (this.Depth > 0) ? l_aTable.CreateInstance(l_a_iObject, l_a_atObject, l_a_rtObject) : null; Instance l_p_iObject = (this.Depth > 1) ? l_p_iTable.CreateInstance() : null; Product l_pObject = (this.Depth > 0) ? l_pTable.CreateInstance(l_p_iObject) : null; TranslationType l_t_ttObject = (this.Depth > 1) ? l_t_ttTable.CreateInstance() : null; Translation l_tObject = (this.Depth > 0) ? l_tTable.CreateInstance(l_t_ttObject) : null; Localization lObject = lTable.CreateInstance(l_aObject, l_pObject, l_tObject); sqlReader.Close(); return(lObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("l", "loadinternal", "exception"), "Localization 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, "Localization", "Exception while loading Localization object from database. See inner exception for details.", ex); } }
public List <Localization> 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} " + LocalizationTable.GetColumnNames("[l]") + (this.Depth > 0 ? "," + ApplicationTable.GetColumnNames("[l_a]") : string.Empty) + (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[l_a_i]") : string.Empty) + (this.Depth > 1 ? "," + ApplicationTypeTable.GetColumnNames("[l_a_at]") : string.Empty) + (this.Depth > 1 ? "," + RuntimeTypeTable.GetColumnNames("[l_a_rt]") : string.Empty) + (this.Depth > 0 ? "," + ProductTable.GetColumnNames("[l_p]") : string.Empty) + (this.Depth > 1 ? "," + InstanceTable.GetColumnNames("[l_p_i]") : string.Empty) + (this.Depth > 0 ? "," + TranslationTable.GetColumnNames("[l_t]") : string.Empty) + (this.Depth > 1 ? "," + TranslationTypeTable.GetColumnNames("[l_t_tt]") : string.Empty) + " FROM [core].[Localization] AS [l] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[Application] AS [l_a] ON [l].[ApplicationID] = [l_a].[ApplicationID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[Instance] AS [l_a_i] ON [l_a].[InstanceID] = [l_a_i].[InstanceID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[ApplicationType] AS [l_a_at] ON [l_a].[ApplicationTypeID] = [l_a_at].[ApplicationTypeID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[RuntimeType] AS [l_a_rt] ON [l_a].[RuntimeTypeID] = [l_a_rt].[RuntimeTypeID] "; } if (this.Depth > 0) { sqlCmdText += "LEFT OUTER JOIN [core].[Product] AS [l_p] ON [l].[ProductID] = [l_p].[ProductID] "; } if (this.Depth > 1) { sqlCmdText += "LEFT OUTER JOIN [core].[Instance] AS [l_p_i] ON [l_p].[InstanceID] = [l_p_i].[InstanceID] "; } if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[Translation] AS [l_t] ON [l].[TranslationID] = [l_t].[TranslationID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[TranslationType] AS [l_t_tt] ON [l_t].[TranslationTypeID] = [l_t_tt].[TranslationTypeID] "; } 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("l", "customloadmany", "notfound"), "Localization 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 <Localization>()); } SqlQuery query = new SqlQuery(sqlReader); LocalizationTable lTable = new LocalizationTable(query); ApplicationTable l_aTable = (this.Depth > 0) ? new ApplicationTable(query) : null; InstanceTable l_a_iTable = (this.Depth > 1) ? new InstanceTable(query) : null; ApplicationTypeTable l_a_atTable = (this.Depth > 1) ? new ApplicationTypeTable(query) : null; RuntimeTypeTable l_a_rtTable = (this.Depth > 1) ? new RuntimeTypeTable(query) : null; ProductTable l_pTable = (this.Depth > 0) ? new ProductTable(query) : null; InstanceTable l_p_iTable = (this.Depth > 1) ? new InstanceTable(query) : null; TranslationTable l_tTable = (this.Depth > 0) ? new TranslationTable(query) : null; TranslationTypeTable l_t_ttTable = (this.Depth > 1) ? new TranslationTypeTable(query) : null; List <Localization> result = new List <Localization>(); do { Instance l_a_iObject = (this.Depth > 1) ? l_a_iTable.CreateInstance() : null; ApplicationType l_a_atObject = (this.Depth > 1) ? l_a_atTable.CreateInstance() : null; RuntimeType l_a_rtObject = (this.Depth > 1) ? l_a_rtTable.CreateInstance() : null; Application l_aObject = (this.Depth > 0) ? l_aTable.CreateInstance(l_a_iObject, l_a_atObject, l_a_rtObject) : null; Instance l_p_iObject = (this.Depth > 1) ? l_p_iTable.CreateInstance() : null; Product l_pObject = (this.Depth > 0) ? l_pTable.CreateInstance(l_p_iObject) : null; TranslationType l_t_ttObject = (this.Depth > 1) ? l_t_ttTable.CreateInstance() : null; Translation l_tObject = (this.Depth > 0) ? l_tTable.CreateInstance(l_t_ttObject) : null; Localization lObject = (this.Depth > -1) ? lTable.CreateInstance(l_aObject, l_pObject, l_tObject) : null; result.Add(lObject); } while (sqlReader.Read()); sqlReader.Close(); return(result); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("l", "customloadmany", "exception"), "Localization 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, "Localization", "Exception while loading (custom/many) Localization object from database. See inner exception for details.", ex); } }
public List <TranslationGroup> 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} " + TranslationGroupTable.GetColumnNames("[tg]") + (this.Depth > 0 ? "," + TranslationTable.GetColumnNames("[tg_t]") : string.Empty) + (this.Depth > 1 ? "," + TranslationTypeTable.GetColumnNames("[tg_t_tt]") : string.Empty) + " FROM [core].[TranslationGroup] AS [tg] "; if (this.Depth > 0) { sqlCmdText += "INNER JOIN [core].[Translation] AS [tg_t] ON [tg].[TranslationID] = [tg_t].[TranslationID] "; } if (this.Depth > 1) { sqlCmdText += "INNER JOIN [core].[TranslationType] AS [tg_t_tt] ON [tg_t].[TranslationTypeID] = [tg_t_tt].[TranslationTypeID] "; } 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("tg", "customloadmany", "notfound"), "TranslationGroup 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 <TranslationGroup>()); } SqlQuery query = new SqlQuery(sqlReader); TranslationGroupTable tgTable = new TranslationGroupTable(query); TranslationTable tg_tTable = (this.Depth > 0) ? new TranslationTable(query) : null; TranslationTypeTable tg_t_ttTable = (this.Depth > 1) ? new TranslationTypeTable(query) : null; List <TranslationGroup> result = new List <TranslationGroup>(); do { TranslationType tg_t_ttObject = (this.Depth > 1) ? tg_t_ttTable.CreateInstance() : null; Translation tg_tObject = (this.Depth > 0) ? tg_tTable.CreateInstance(tg_t_ttObject) : null; TranslationGroup tgObject = (this.Depth > -1) ? tgTable.CreateInstance(tg_tObject) : null; result.Add(tgObject); } while (sqlReader.Read()); sqlReader.Close(); return(result); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tg", "customloadmany", "exception"), "TranslationGroup 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, "TranslationGroup", "Exception while loading (custom/many) TranslationGroup object from database. See inner exception for details.", ex); } }