Inheritance: IDisposable
Beispiel #1
0
 public virtual async Task NonQueryAsync(MapperDb db, Sql sql)
 {
     using (var command = db.GetCommand(sql))
     {
         await this.NonQueryAsync(db, command).ConfigureAwait(false);
     }
 }
Beispiel #2
0
 public virtual async Task NonQueryAsync(MapperDb db, string sql, params object[] args)
 {
     using (var command = db.GetCommand(sql, args))
     {
         await this.NonQueryAsync(db, command).ConfigureAwait(false);
     }
 }
Beispiel #3
0
        private static string GetCacheKey(MapperDb db, DbCommand command)
        {
            var key = db.ConnectionString;
            key += "." + command.CommandText + ".";

            var dbParameters = (from DbParameter parameter in command.Parameters select parameter.Value.ToString()).ToList();
            key += "." + string.Join(",", dbParameters);
            return key;
        }
Beispiel #4
0
        public static Collection<ICollection<KeyValuePair<string, object>>> Get(MapperDb db, DbCommand command)
        {
            if (!db.CacheResults)
            {
                return null;
            }

            string key = GetCacheKey(db, command);
            var item = MapperCache.GetCache<Collection<ICollection<KeyValuePair<string, object>>>>(key);

            return item;
        }
Beispiel #5
0
        public virtual async Task NonQueryAsync(MapperDb db, DbCommand command)
        {
            var connection = db.GetConnection();
            if (connection == null)
            {
                throw new MapperException("Could not create database connection.");
            }

            await db.OpenSharedConnectionAsync().ConfigureAwait(false);
            command.Connection = connection;
            command.Transaction = db.GetTransaction();

            await command.ExecuteNonQueryAsync().ConfigureAwait(false);
        }
Beispiel #6
0
        public static void Set(MapperDb db, DbCommand command, Collection<ICollection<KeyValuePair<string, object>>> item)
        {
            if (!db.CacheResults)
            {
                return;
            }

            string key = GetCacheKey(db, command);
            var cacheDuration = db.CacheMilliseconds;
            var expiresOn = DateTimeOffset.UtcNow.AddMilliseconds(cacheDuration);


            MapperCache.AddToCache(key, item, expiresOn);
        }
Beispiel #7
0
        private static NonQueryOperation GetOperation(MapperDb db)
        {
            NonQueryOperation operation;

            switch (db.DatabaseType)
            {
                case DatabaseType.MySql:
                    operation = new MySqlNonQuery();
                    break;
                case DatabaseType.SqlServer:
                    operation = new SqlServerNonQuery();
                    break;
                default:
                    operation = new PostgreSQLNonQuery();
                    break;
            }

            return operation;
        }
Beispiel #8
0
 public DatabaseFactory(MapperDb db)
 {
     this.Db = db;
 }