@Override public Account getAccountByEmail(Account account) throws DAOException { Connection connect = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; // boolean isAuthenticated = false; // Integer accountId = 0; try { connect = ConnectionPool.getPool().getConnection(); preparedStatement = connect.prepareStatement(SELECT_ACCOUNT_DETAILS_BY_LOGIN_AND_PASSWORD); preparedStatement.setString(1, account.getEmail()); preparedStatement.setString(2, account.getPassword()); resultSet = preparedStatement.executeQuery(); resultSet.next(); account.setId(resultSet.getInt(AccountColumns.Id.getName())); account.setFirstName(resultSet.getString(AccountColumns.FirstName.getName())); account.setLastName(resultSet.getString(AccountColumns.LastName.getName())); account.setMiddleName(resultSet.getString(AccountColumns.MiddleName.getName())); account.setRoleId(resultSet.getInt(AccountColumns.RoleId.getName())); } catch (Exception e) { throw new DAOException(e); } finally { ConnectionPool.releaseConnection(connect, preparedStatement, resultSet); } return account; }
@Override public List<Booking> loadActiveBookingsByAccountId(Integer accountId) { Connection connect = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; // boolean isAuthenticated = false; List<Booking> bookings = new ArrayList<Booking>(); // Date currentDate = new Date(new java.util.Date().getTime()); try { connect = ConnectionPool.getPool().getConnection(); preparedStatement = connect.prepareStatement(SELECT_BOOKINGS_BY_ACCOUNT_ID); preparedStatement.setInt(1, accountId); // preparedStatement.setDate(2, currentDate); // preparedStatement.setDate(3, currentDate); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { Booking booking = new Booking(); booking.setId(resultSet.getInt(BookingColumns.Id.getName())); booking.setRoomId(resultSet.getInt(BookingColumns.roomId.getName())); booking.setCheckinDate(resultSet.getDate(BookingColumns.checkinDate.getName())); booking.setCheckoutDate(resultSet.getDate(BookingColumns.checkoutDate.getName())); System.out.println(booking.getId()); System.out.println(booking.getRoomId()); System.out.println(booking.getCheckinDate()); System.out.println(booking.getCheckoutDate()); bookings.add(booking); } } catch (Exception e) { throw new DAOException(e); } finally { ConnectionPool.releaseConnection(connect, preparedStatement, resultSet); } return bookings; }
@Override public void deleteBookingById(Integer bookingId) throws DAOException { Connection connect = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connect = ConnectionPool.getPool().getConnection(); preparedStatement = connect.prepareStatement(DELETE_BOOKING); // preparedStatement.setInt(1, booking.getId()); preparedStatement.setInt(1, bookingId); preparedStatement.executeUpdate(); } catch (Exception e) { throw new DAOException(e); } finally { ConnectionPool.releaseConnection(connect, preparedStatement, resultSet); } }
@Override public void saveAccount(Account account) throws DAOException { Connection connect = null; PreparedStatement preparedStatement = null; try { connect = ConnectionPool.getPool().getConnection(); preparedStatement = connect.prepareStatement(SAVE_ACCOUNT_SQL); preparedStatement.setString(1, account.getEmail()); preparedStatement.setString(2, account.getPassword()); preparedStatement.setString(3, account.getFirstName()); preparedStatement.setString(4, account.getLastName()); preparedStatement.setString(5, account.getMiddleName()); preparedStatement.executeUpdate(); } catch (Exception e) { throw new DAOException(e); } finally { ConnectionPool.releaseConnection(connect, preparedStatement); } }
@Override public boolean checkAccountAuthentication(Account account) throws DAOException { Connection connect = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; boolean isAuthenticated = false; try { connect = ConnectionPool.getPool().getConnection(); preparedStatement = connect.prepareStatement(SELECT_ACCOUNT_DETAILS_BY_LOGIN_AND_PASSWORD); preparedStatement.setString(1, account.getEmail()); preparedStatement.setString(2, account.getPassword()); resultSet = preparedStatement.executeQuery(); isAuthenticated = resultSet.next(); } catch (Exception e) { throw new DAOException(e); } finally { ConnectionPool.releaseConnection(connect, preparedStatement, resultSet); } return isAuthenticated; }
@Override public void saveBooking(Booking booking) throws DAOException { Connection connect = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connect = ConnectionPool.getPool().getConnection(); preparedStatement = connect.prepareStatement(SAVE_BOOKING); // preparedStatement.setInt(1, booking.getId()); preparedStatement.setInt(1, booking.getRoomId()); preparedStatement.setInt(2, booking.getAccountId()); Date orderDate = new Date(booking.getCheckinDate().getTime()); preparedStatement.setDate(3, orderDate); Date checkinDate = new Date(booking.getCheckinDate().getTime()); preparedStatement.setDate(4, checkinDate); Date checkoutDate = new Date(booking.getCheckoutDate().getTime()); preparedStatement.setDate(5, checkoutDate); preparedStatement.executeUpdate(); } catch (Exception e) { throw new DAOException(e); } finally { ConnectionPool.releaseConnection(connect, preparedStatement, resultSet); } }