protected override PaymentCredentials 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 " + PaymentCredentialsTable.GetColumnNames("[pc]") + " FROM [core].[PaymentCredentials] AS [pc] "; sqlCmdText += "WHERE [pc].[PaymentCredentialsID] = @PaymentCredentialsID;"; SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand; sqlCmd.Parameters.AddWithValue("@PaymentCredentialsID", id); SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader; if (!sqlReader.HasRows || !sqlReader.Read()) { IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "loadinternal", "notfound"), "PaymentCredentials 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); PaymentCredentialsTable pcTable = new PaymentCredentialsTable(query); PaymentCredentials pcObject = pcTable.CreateInstance(); sqlReader.Close(); return(pcObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "loadinternal", "exception"), "PaymentCredentials 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, "PaymentCredentials", "Exception while loading PaymentCredentials object from database. See inner exception for details.", ex); } }
public PaymentCredentials 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} " + PaymentCredentialsTable.GetColumnNames("[pc]") + " FROM [core].[PaymentCredentials] AS [pc] "; 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("pc", "customload", "notfound"), "PaymentCredentials 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); PaymentCredentialsTable pcTable = new PaymentCredentialsTable(query); PaymentCredentials pcObject = pcTable.CreateInstance(); sqlReader.Close(); return(pcObject); } catch (Exception ex) { database.HandleException(ex); IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("pc", "customload", "exception"), "PaymentCredentials 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, "PaymentCredentials", "Exception while loading (custom/single) PaymentCredentials object from database. See inner exception for details.", ex); } }
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); } }
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); } }