示例#1
0
 private RMItem readDataFromLog(int id, String key, int xId) {
   synchronized (logArray) {
     int indx;
     if ((indx = logContains(xId)) != -1) {
       Log temp = (Log) logArray.elementAt(indx);
       return (RMItem) temp.get(key);
     }
   }
   return null;
 }
示例#2
0
 private int logContains(int xId) {
   synchronized (logArray) {
     for (int i = 0; i < logArray.size(); i++) {
       Log temp = (Log) logArray.elementAt(i);
       if (temp.getXId() == xId) {
         return i;
       }
     }
   }
   return -1;
 }
示例#3
0
 private void writeDataToLog(int xId, String key, RMItem value) {
   System.out.println("entering writedatatolog");
   synchronized (logArray) {
     Log temp;
     int indx;
     if ((indx = logContains(xId)) != -1) {
       temp = (Log) logArray.elementAt(indx);
       temp.put(key, value);
     } else {
       temp = new Log(xId, new RMHashtable());
       temp.put(key, value);
       logArray.add(temp);
     }
   }
 }
示例#4
0
  public void abort(int transactionId) throws RemoteException, InvalidTransactionException {
    int indx = logContains(transactionId);

    Log temp;

    if (indx > -1) {

      temp = (Log) logArray.elementAt(indx);

    } else {
      System.out.println("nothing in array");
      return;
    }

    for (Enumeration e = temp.getKeys(); e.hasMoreElements(); ) {
      System.out.println("For loop");
      String key = (String) (e.nextElement());
      RMItem obj = temp.get(key);
      if (obj.getType() == 0) {
        Flight flight = (Flight) obj;
        if (flight.getCount() == -1) {
          System.out.println("entering count=-1 block");
          removeData(transactionId, key);
        } else {
          System.out.println("entering other block");
          writeData(transactionId, key, flight);
        }
      } else if (obj.getType() == 1) {
        Customer cust = (Customer) obj;
        if (cust.getID() == -1) {
          System.out.println("entering remove data for customer");
          removeData(transactionId, key);
        } else {
          System.out.println("entering write data for customer");
          writeData(transactionId, key, obj);
        }
      }
    }
  }