package fjdbc.demodb;

import fj.*;
import fjdbc.*;

import java.lang.Void;
import java.math.BigDecimal;
import java.sql.SQLException;

import static fj.P.p;

public final class Transactions {

  public static final Transaction<Void, Void> createSchema =
    new Transaction<Void, Void>() {
      @Override
      public TransactionIsolation getIsolation() {
        return TransactionIsolation.serializable;
      }
      @Override
      public Void run(TransactionContext context, Void aVoid) throws SQLException {
        context.execute(Statements.createAccountTable);
        return null;
      }
    };

  public static final Transaction<Void, Void> dropSchema =
    new Transaction<Void, Void>() {
      @Override
      public TransactionIsolation getIsolation() {
        return TransactionIsolation.serializable;
      }
      @Override
      public Void run(TransactionContext context, Void aVoid) throws SQLException {
        context.execute(Statements.dropAccountTable);
        return null;
      }
    };

  public static final Transaction<P3<Integer, Integer, BigDecimal>, Void> transfer =
    new Transaction<P3<Integer, Integer, BigDecimal>, Void>() {
      @Override
      public TransactionIsolation getIsolation() {
        return TransactionIsolation.serializable;
      }
      @Override
      public Void run(TransactionContext context, P3<Integer, Integer, BigDecimal> params) throws SQLException {
        context.execute(Statements.modifyBalance, p(params._1(), params._3().negate()));
        context.execute(Statements.modifyBalance, p(params._2(), params._3()));
        return null;
      }
    };

  /**
   * Needed for simulation of serialization conflicts.
   */
  public static final Transaction<P2<Integer, Integer>, Void> conflictSimulation =
    new Transaction<P2<Integer, Integer>, Void>() {
      @Override
      public TransactionIsolation getIsolation() {
        return transfer.getIsolation();
      }
      @Override
      public Void run(TransactionContext context, P2<Integer, Integer> params) throws SQLException {
        for (int i = 0; i < 100; i++) {
          context.execute(transfer, p(params._1(), params._2(), new BigDecimal(1)));
        }
        return null;
      }
    };

}

@@ -259,32 +259,45 @@
  new Transaction
+.Serializable
 %3CVoid, Void%3E() %7B
@@ -317,133 +317,8 @@
 ide%0A
-      public TransactionIsolation getIsolation() %7B%0A        return TransactionIsolation.serializable;%0A      %7D%0A      @Override%0A
     
@@ -560,32 +560,45 @@
  new Transaction
+.Serializable
 %3CVoid, Void%3E() %7B
@@ -618,133 +618,8 @@
 ide%0A
-      public TransactionIsolation getIsolation() %7B%0A        return TransactionIsolation.serializable;%0A      %7D%0A      @Override%0A
     
@@ -885,32 +885,45 @@
  new Transaction
+.Serializable
 %3CP3%3CInteger, Int
@@ -971,133 +971,8 @@
 ide%0A
-      public TransactionIsolation getIsolation() %7B%0A        return TransactionIsolation.serializable;%0A      %7D%0A      @Override%0A
     

Simplify the transactions