public override void Commit() { MySqlStorageConnection.AttemptActionReturnObject(() => { _storage.UseTransaction(connection => { connection.EnlistTransaction(Transaction.Current); foreach (var command in _commandQueue) { command(connection); } }); return(0); }); }
private int AcquireLock(string resource, TimeSpan timeout) { return(MySqlStorageConnection.AttemptActionReturnObject(() => _storage.UseConnection(connection => connection .Execute( "INSERT INTO DistributedLock (Resource, CreatedAt) " + " SELECT @resource, @now " + " FROM dual " + " WHERE NOT EXISTS ( " + " SELECT * FROM DistributedLock "+ " WHERE Resource = @resource "+ " AND CreatedAt > @expired)", new { resource, now = DateTime.UtcNow, expired = DateTime.UtcNow.Add(timeout.Negate()) })) )); }