Esempio n. 1
0
        protected override ReportLink 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 " +
                             ReportLinkTable.GetColumnNames("[rl]") +
                             (this.Depth > 0 ? "," + ReportLinkGroupTable.GetColumnNames("[rl_rlg]") : string.Empty) +
                             " FROM [core].[ReportLink] AS [rl] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ReportLinkGroup] AS [rl_rlg] ON [rl].[ReportLinkGroupID] = [rl_rlg].[ReportLinkGroupID] ";
                }
                sqlCmdText += "WHERE [rl].[ReportLinkID] = @ReportLinkID;";

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

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

                ReportLinkTable      rlTable     = new ReportLinkTable(query);
                ReportLinkGroupTable rl_rlgTable = (this.Depth > 0) ? new ReportLinkGroupTable(query) : null;


                ReportLinkGroup rl_rlgObject = (this.Depth > 0) ? rl_rlgTable.CreateInstance() : null;
                ReportLink      rlObject     = rlTable.CreateInstance(rl_rlgObject);
                sqlReader.Close();

                return(rlObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rl", "loadinternal", "exception"), "ReportLink 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, "ReportLink", "Exception while loading ReportLink object from database. See inner exception for details.", ex);
            }
        }
Esempio n. 2
0
        public ReportLinkGroup 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} " +
                             ReportLinkGroupTable.GetColumnNames("[rlg]") +
                             " FROM [core].[ReportLinkGroup] AS [rlg] ";


                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("rlg", "customload", "notfound"), "ReportLinkGroup 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);

                ReportLinkGroupTable rlgTable = new ReportLinkGroupTable(query);


                ReportLinkGroup rlgObject = rlgTable.CreateInstance();
                sqlReader.Close();

                return(rlgObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rlg", "customload", "exception"), "ReportLinkGroup 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, "ReportLinkGroup", "Exception while loading (custom/single) ReportLinkGroup object from database. See inner exception for details.", ex);
            }
        }
Esempio n. 3
0
        public List <Report> 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} " +
                             ReportTable.GetColumnNames("[r]") +
                             (this.Depth > 0 ? "," + ReportLinkTable.GetColumnNames("[r_rl]") : string.Empty) +
                             (this.Depth > 1 ? "," + ReportLinkGroupTable.GetColumnNames("[r_rl_rlg]") : string.Empty) +
                             " FROM [core].[Report] AS [r] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ReportLink] AS [r_rl] ON [r].[ReportLinkID] = [r_rl].[ReportLinkID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ReportLinkGroup] AS [r_rl_rlg] ON [r_rl].[ReportLinkGroupID] = [r_rl_rlg].[ReportLinkGroupID] ";
                }


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

                SqlQuery query = new SqlQuery(sqlReader);

                ReportTable          rTable        = new ReportTable(query);
                ReportLinkTable      r_rlTable     = (this.Depth > 0) ? new ReportLinkTable(query) : null;
                ReportLinkGroupTable r_rl_rlgTable = (this.Depth > 1) ? new ReportLinkGroupTable(query) : null;

                List <Report> result = new List <Report>();
                do
                {
                    ReportLinkGroup r_rl_rlgObject = (this.Depth > 1) ? r_rl_rlgTable.CreateInstance() : null;
                    ReportLink      r_rlObject     = (this.Depth > 0) ? r_rlTable.CreateInstance(r_rl_rlgObject) : null;
                    Report          rObject        = (this.Depth > -1) ? rTable.CreateInstance(r_rlObject) : null;
                    result.Add(rObject);
                } while (sqlReader.Read());
                sqlReader.Close();

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