Ejemplo n.º 1
0
  @Override
  public UrlyBirdRoomOffer bookRoomOffer(final BookRoomCommand command) throws Exception {

    checkNotNull(command, "command");

    final RoomOffer clientRoomToBook = command.getRoomToBook();
    final int roomOfferIndex = clientRoomToBook.getIndex();

    long lock = NOT_LOCKED;
    try {
      lock = roomOfferDao.lock(roomOfferIndex);
      final RoomOffer dbRoomToBook = roomOfferDao.read(roomOfferIndex);

      checkStaleRoomData(clientRoomToBook, dbRoomToBook);

      if (!isRoomBookable.isSatisfiedBy(dbRoomToBook)) {
        throw new Exception("the room to book: " + clientRoomToBook + " is already booked");
      }

      final UrlyBirdRoomOffer bookedRoomOffer =
          factory.copyRoomOfferWithNewCustomer(clientRoomToBook, command.getCustomerId());
      roomOfferDao.update(bookedRoomOffer, lock);
      return bookedRoomOffer;
    } catch (final Exception e) {
      logger.throwing(getClass().getName(), "bookRoomOffer", e);
      throw new Exception(e);
    } finally {
      unlockQuietly(roomOfferIndex, lock);
    }
  }
Ejemplo n.º 2
0
  @Override
  public UrlyBirdRoomOffer updateRoomOffer(final UpdateRoomCommand command) throws Exception {

    checkNotNull(command, "command");

    long lock = NOT_LOCKED;
    final List<String> values = command.getNewValues();
    final RoomOffer clientRoomToUpdate = command.getRoomToUpdate();
    final int index = clientRoomToUpdate.getIndex();
    try {
      lock = roomOfferDao.lock(index);

      final RoomOffer dbRoomToUpdate = roomOfferDao.read(index);
      checkStaleRoomData(clientRoomToUpdate, dbRoomToUpdate);

      final UrlyBirdRoomOffer updatedRoomOffer = factory.createRoomOffer(values, index);

      roomOfferDao.update(updatedRoomOffer, lock);
      return updatedRoomOffer;
    } catch (final Exception e) {
      logger.throwing(getClass().getName(), "updateRoomOffer", e);
      throw new Exception(e);
    } finally {
      unlockQuietly(index, lock);
    }
  }
Ejemplo n.º 3
0
 public void updateUser(User user) {
   try {
     User u = sao.read(user.getUsername());
     u.setPassword(user.getPassword());
     u.setAccessLevel(user.getAccessLevel());
     sao.update(user);
   } catch (DataAccessException e) {
     System.out.println("(User Model) Unable to update product ");
     e.printStackTrace();
   }
 }