示例#1
0
        public void Load(string service, string method, string query, CacheObjectType type)
        {
            Log.Debug($"Loading cache data for {service}::{method} of type {type}");

            // if the cache already exists do not generate it again!
            if (this.Exists(service, method) == true)
            {
                return;
            }

            try
            {
                MySqlConnection connection  = null;
                MySqlDataReader reader      = Database.Query(ref connection, query);
                PyDataType      cacheObject = null;

                using (connection)
                    using (reader)
                    {
                        switch (type)
                        {
                        case CacheObjectType.Rowset:
                            cacheObject = Rowset.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.CRowset:
                            cacheObject = CRowset.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.TupleSet:
                            cacheObject = TupleSet.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.PackedRowList:
                            cacheObject = PyPackedRowList.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.IntIntDict:
                            cacheObject = IntIntDictionary.FromMySqlDataReader(reader);
                            break;

                        case CacheObjectType.IndexRowset:
                            cacheObject = IndexRowset.FromMySqlDataReader(reader, 0);
                            break;
                        }

                        StoreCall(service, method, cacheObject, DateTime.UtcNow.ToFileTimeUtc());
                    }
            }
            catch (Exception)
            {
                Log.Error($"Cannot generate cache data for {service}::{method}");
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Helper method that queries the cached object and converts it to the proper type to be stored
        /// </summary>
        /// <param name="query">The query to run</param>
        /// <param name="type">The type of object to store</param>
        /// <returns>The final object to be used by the cache</returns>
        private PyDataType QueryCacheObject(string query, CacheObjectType type)
        {
            MySqlConnection connection = null;
            MySqlDataReader reader     = Database.Query(ref connection, query);

            using (connection)
                using (reader)
                {
                    return(type switch
                    {
                        CacheObjectType.Rowset => Rowset.FromMySqlDataReader(Database, reader),
                        CacheObjectType.CRowset => CRowset.FromMySqlDataReader(Database, reader),
                        CacheObjectType.TupleSet => TupleSet.FromMySqlDataReader(Database, reader),
                        CacheObjectType.PackedRowList => PyPackedRowList.FromMySqlDataReader(Database, reader),
                        CacheObjectType.IntIntDict => IntIntDictionary.FromMySqlDataReader(reader),
                        CacheObjectType.IndexRowset => IndexRowset.FromMySqlDataReader(Database, reader, 0),
                        _ => null
                    });
示例#3
0
        /// <summary>
        /// Runs one prepared query with the given values as parameters and returns a IntIntDictionary representing the result
        /// </summary>
        /// <param name="query">The prepared query</param>
        /// <returns>The Rowset object representing the result</returns>
        public PyDataType PrepareIntIntDictionary(string query)
        {
            try
            {
                MySqlConnection connection = null;
                // create the correct command
                MySqlCommand command = this.PrepareQuery(ref connection, query);

                MySqlDataReader reader = command.ExecuteReader();

                using (connection)
                    using (reader)
                    {
                        // run the prepared statement
                        return(IntIntDictionary.FromMySqlDataReader(reader));
                    }
            }
            catch (Exception e)
            {
                Log.Error($"MySQL error: {e.Message}");
                throw;
            }
        }