Beispiel #1
0
        private static IRouteResponse BeginTransaction(RequestCommon req)
        {
            var conn        = OpenConnection();
            var transaction = conn.BeginTransaction();

            transactions[req.UserId] = new Transaction(transaction, conn);

            return(RouteResponse.OK());
        }
Beispiel #2
0
        private static IRouteResponse Load(RequestCommon req)
        {
            Console.WriteLine($"Load store {req.StoreName} for user {req.UserId}");

            using (var conn = OpenConnection())
            {
                CheckForTable(conn, req.StoreName);
                var data = LoadStore(conn, req.StoreName, req.UserId);

                return(RouteResponse.OK(data));
            }
        }
Beispiel #3
0
        private static IRouteResponse CommitTransaction(RequestCommon req)
        {
            Console.WriteLine("Committing transactions...");
            var tinfo = transactions[req.UserId];

            Console.WriteLine($"{tinfo.transactionCount} {tinfo.rollbackCount} {tinfo.c.State}");
            tinfo.t.Commit();
            tinfo.c.Close();
            transactions.Remove(req.UserId, out _);

            return(RouteResponse.OK());
        }
Beispiel #4
0
        private static IRouteResponse RollbackTransaction(RequestCommon req)
        {
            var tinfo = transactions[req.UserId];

            Interlocked.Increment(ref tinfo.rollbackCount);

            while (Interlocked.Read(ref tinfo.transactionCount) > 0)
            {
                // Thread.Sleep(0) is evil, see some article I wrote somewhere regarding that.
                Thread.Sleep(1);
            }

            Console.WriteLine($"Abort {req.UserId}");
            transactions[req.UserId].t.Rollback();
            transactions[req.UserId].c.Close();
            transactions.Remove(req.UserId, out _);
            // No need to decrement the rollback counter as we're all done.

            return(RouteResponse.OK());
        }