Exemplo n.º 1
0
/// <summary>
/// Calculate & persist metatable stats for tables belonging to broker
/// </summary>
/// <returns></returns>

        public int UpdateMetaTableStatistics()
        {
            MetaTableStats mts;
            DateTime       dt;
            string         sql;
            int            mthdId;
            long           rowCount;

            Dictionary <int, MetaTableStats> stats = new Dictionary <int, MetaTableStats>();
            DbCommandMx dao = new DbCommandMx();

// Get row count for each table

            sql =
                "select " +
                " mthd_vrsn_id, count(*) " +
                "from ( " +
                " select " +
                "  mthd_vrsn_id, rslt_grp_id" +
                "  from mbs_owner.mbs_adw_rslt " +
                " where " +
                "  sts_id = 1 " +
//				" and mthd_vrsn_id = 148411 " + // debug
                " group by mthd_vrsn_id, rslt_grp_id) " +
                "group by mthd_vrsn_id";

            dao.Prepare(sql);
            dao.ExecuteReader();
            while (dao.Read())
            {
                mthdId   = dao.GetInt(0);
                rowCount = dao.GetLong(1);
                if (!stats.ContainsKey(mthdId))
                {
                    stats[mthdId] = new MetaTableStats();
                }
                stats[mthdId].RowCount = rowCount;
            }

            dao.CloseReader();

// Get latest update date for each table

            sql =
                "select " +
                " mthd_vrsn_id, max(updt_dt) " +
                "from mbs_owner.mbs_adw_rslt " +
                "where " +
                " updt_dt <= sysdate and " +
                " sts_id = 1" +
//				" and mthd_vrsn_id = 148411 " + // debug
                "group by mthd_vrsn_id";

            dao.Prepare(sql);
            dao.ExecuteReader();
            while (dao.Read())
            {
                mthdId = dao.GetInt(0);
                dt     = dao.GetDateTime(1);
                if (!stats.ContainsKey(mthdId))
                {
                    stats[mthdId] = new MetaTableStats();
                }
                stats[mthdId].UpdateDateTime = dt;
            }

            dao.CloseReader();
            dao.Dispose();

            int updCnt = 0;

            foreach (int mthdId_ in stats.Keys)
            {
                mts = stats[mthdId_];
                try { UserObjectDao.UpdateUpdateDateAndCount(mthdId_, mts.UpdateDateTime, (int)mts.RowCount); }
                catch (Exception ex) { continue; }
                updCnt++;
            }

            return(stats.Count);
        }