/*********************************************************************************** * @author John Miller * @version 1.0 * @date Thu Aug 21 11:30:18 EDT 2014 */ package transj; import java.util.List; import static java.lang.System.out; import static java.util.Arrays.asList; /*********************************************************************************** * This trait defines read (r) and write (w) operation-types. */ interface ReadWrite { final char r = 'r'; final char w = 'w'; } // ReadWrite /*********************************************************************************** * This class represents a transaction operation. An operation is a 3-tuple * (operation-type, transaction-id, data-object-id). */ class Op { final char typ; // type of operation final int tid; // transaction id final int oid; // data-object/tuple id public Op (char typ_, int tid_, int oid_) { typ = typ_; tid = tid_; oid = oid_; } // constructor public String toString () { return "(" + typ + ", " + tid + ", " + oid + ")"; } // toString } // Op /*********************************************************************************** * This class represents a transaction schedule as a list of operations, where each * operation is a 3-tuple (operation-type, transaction-id, data-object-id). */ class Schedule implements ReadWrite { private final List s; // list of operations making up the schedule /******************************************************************************* * Construct a schedule. * @param ss the input list of operations */ public Schedule (List ss) { s = ss; } // constructor /******************************************************************************* * Return the list of operations. */ public List get () { return s; } // get /******************************************************************************* * Determine whether this schedule is Conflict Serializable (CSR). * @param nTrans the number of transactions in this schedule */ boolean isCSR (int nTrans) { return false; } // isCSR /******************************************************************************* * Determine whether this schedule is View Serializable (VSR). * @param nTrans the number of transactions in this schedule */ boolean isVSR (int nTrans) { return false; } // isVSR /******************************************************************************* * Randomly generate a schedule. * @param nTrans the number of transactions * @param nOps the number of operations per transaction * @param nObjs the number of data objects accessed */ Schedule genSchedule (int nTrans, int nOps, int nObjs) { return null; } // genSchedule /******************************************************************************* * Convert the schedule to a string. */ public String toString () { return "Schedule ( " + s + " )"; } // toString /******************************************************************************* * The main method is used to test the Schedule class. */ public static void main (String [] args) { List list1 = asList (new Op (r, 0, 0), new Op (r, 1, 0), new Op (w, 0, 0), new Op (w, 1, 0)); Schedule s1 = new Schedule (list1); List list2 = asList (new Op (r, 0, 0), new Op (r, 1, 1), new Op (w, 0, 0), new Op (w, 1, 1)); Schedule s2 = new Schedule (list2); out.println ("s1 = " + s1 + " is CSR? " + s1.isCSR (2)); out.println ("s1 = " + s1 + " is VSR? " + s1.isVSR (2)); out.println ("s2 = " + s2 + " is CSR? " + s2.isCSR (2)); out.println ("s2 = " + s2 + " is VSR? " + s2.isVSR (2)); } // main } // Schedule class