예제 #1
1
 public int newCustomer(int id) throws RemoteException {
   Trace.info("INFO: RM::newCustomer(" + id + ") called");
   // Generate a globally unique ID for the new customer
   int cid =
       Integer.parseInt(
           String.valueOf(id)
               + String.valueOf(Calendar.getInstance().get(Calendar.MILLISECOND))
               + String.valueOf(Math.round(Math.random() * 100 + 1)));
   Customer cust = new Customer(cid);
   writeData(id, cust.getKey(), cust);
   Customer temp = cust.clone();
   temp.setID(-1);
   temp.setType(1);
   writeDataToLog(id, cust.getKey(), temp);
   Trace.info("RM::newCustomer(" + cid + ") returns ID=" + cid);
   return cid;
 }
예제 #2
0
 // I opted to pass in customerID instead. This makes testing easier
 public boolean newCustomer(int id, int customerID) throws RemoteException {
   Trace.info("INFO: RM::newCustomer(" + id + ", " + customerID + ") called");
   Customer cust = (Customer) readData(id, Customer.getKey(customerID));
   if (cust == null) {
     cust = new Customer(customerID);
     writeData(id, cust.getKey(), cust);
     Customer temp = cust.clone();
     temp.setType(1);
     temp.setID(-1);
     writeDataToLog(id, cust.getKey(), temp);
     Trace.info("INFO: RM::newCustomer(" + id + ", " + customerID + ") created a new customer");
     return true;
   } else {
     Trace.info(
         "INFO: RM::newCustomer(" + id + ", " + customerID + ") failed--customer already exists");
     return false;
   } // else
 }