// Create a new room location or add rooms to an existing location. // Note: if price <= 0 and the room location already exists, it maintains // its current price. @Override public boolean addRooms(int id, String location, int numRooms, int roomPrice) { Trace.info( "RM::addRooms(" + id + ", " + location + ", " + numRooms + ", $" + roomPrice + ") called."); Room curObj = (Room) readData(id, Room.getKey(location)); synchronized (syncLock) { if (curObj == null) { // Doesn't exist; add it. Room newObj = new Room(location, numRooms, roomPrice); writeData(id, newObj.getKey(), newObj); Trace.info( "RM::addRooms(" + id + ", " + location + ", " + numRooms + ", $" + roomPrice + ") OK."); } else { // Add count to existing object and update price. curObj.setCount(curObj.getCount() + numRooms); if (roomPrice > 0) { curObj.setPrice(roomPrice); } writeData(id, curObj.getKey(), curObj); Trace.info( "RM::addRooms(" + id + ", " + location + ", " + numRooms + ", $" + roomPrice + ") OK: " + "rooms = " + curObj.getCount() + ", price = $" + roomPrice); } return (true); } }
// Add room reservation to this customer. @Override public boolean cancelReserveRoom(int id, int customerId, String location) { return cancelReserveItem(id, customerId, Room.getKey(location), location); }
// Returns room price at this location. @Override public int queryRoomsPrice(int id, String location) { return queryPrice(id, Room.getKey(location)); }
// Delete rooms from a location. @Override public boolean deleteRooms(int id, String location) { return deleteItem(id, Room.getKey(location)); }