/** * Update user. * * @param user user to update. * @throws SQLException */ private void updateUser(Connection con, User user) throws SQLException { PreparedStatement pstmt = null; try { pstmt = con.prepareStatement(SQL_UPDATE_USER); int k = 1; pstmt.setString(k++, user.getPassword()); pstmt.setString(k++, user.getFirstName()); pstmt.setString(k++, user.getLastName()); pstmt.setLong(k, user.getId()); pstmt.executeUpdate(); } finally { close(pstmt); } }
public List<ExtendedUserOrderBean> getExtendedUserOrderBean(User user) throws DBException { List<ExtendedUserOrderBean> list = new ArrayList<>(); PreparedStatement ps = null; ResultSet rs = null; Connection con = null; try { con = getConnection(); con.setAutoCommit(false); ps = con.prepareStatement(SQL_GET_EXTENDED_USER_ORDER_BEAN); ps.setInt(1, user.getId()); rs = ps.executeQuery(); while (rs.next()) { list.add(extractExtendedUserOrderBean(rs)); } con.commit(); } catch (SQLException e) { rollback(con); LOG.error(Messages.ERR_CANNOT_OBTAIN_USER_ORDER_BEANS, e); } finally { close(con, ps, rs); } return list; }
/** * Extracts a user entity from the result set. * * @param rs Result set from which a user entity will be extracted. * @return User entity */ public User extractUser(ResultSet rs) throws SQLException { User user = new User(); user.setId(rs.getInt(Fields.ENTITY_ID)); user.setLogin(rs.getString(Fields.USER_LOGIN)); user.setPassword(rs.getString(Fields.USER_PASSWORD)); user.setFirstName(rs.getString(Fields.USER_FIRST_NAME)); user.setLastName(rs.getString(Fields.USER_LAST_NAME)); user.setRole(rs.getString(Fields.USER_ROLE)); user.setBan(rs.getBoolean(Fields.USER_BAN)); return user; }
/** * Returns orders of the given user and status * * @param user User entity. * @param statusId Status identifier. * @return List of order entities. * @throws DBException */ public List<Order> findOrders(User user, int statusId) throws DBException { List<Order> ordersList = new ArrayList<Order>(); PreparedStatement pstmt = null; ResultSet rs = null; Connection con = null; try { con = getConnection(); pstmt = con.prepareStatement(SQL_FIND_ORDERS_BY_STATUS_AND_USER); pstmt.setInt(1, statusId); pstmt.setLong(2, user.getId()); rs = pstmt.executeQuery(); while (rs.next()) { ordersList.add(extractOrder(rs)); } con.commit(); } catch (SQLException ex) { rollback(con); throw new DBException(Messages.ERR_CANNOT_OBTAIN_ORDERS_BY_USER_AND_STATUS_ID, ex); } finally { close(con, pstmt, rs); } return ordersList; }
public List<CatalogItem> findCatalogItems(User user) throws DBException { List<CatalogItem> catalogItemList = new ArrayList<>(); PreparedStatement ps = null; ResultSet rs = null; Connection con = null; try { con = getConnection(); ps = con.prepareStatement(SQL_GET_CATALOG_ITEMS_BY_USER); ps.setInt(1, user.getId()); rs = ps.executeQuery(); while (rs.next()) { catalogItemList.add(extractCatalogItem(rs)); } } catch (SQLException ex) { rollback(con); throw new DBException(Messages.ERR_CANNOT_OBTAIN_MENU_ITEMS_BY_IDENTIFIERS, ex); } finally { close(con); close(rs); close(ps); } return catalogItemList; }