Article createArticle(String name) { Article a = new Article(); a.setArticleName(name); a.setIsSelloutArticle(true); a.setMinimumStock(100); a.setOrderedUnits(17); a.setPrice(0.45); a.setStock(234); a.setSupplierId(4); a.setUnit("bottle"); return a; }
/** * Returns the article data for the given identity. * * @param articleIdentity the article identity * @throws IllegalStateException if there is no article with the given identity * @throws SQLException if there is a problem with the underlying JDBC connection */ public Article queryArticle(final long articleIdentity) throws SQLException { final Article article = new Article(); synchronized (this.connection) { try (PreparedStatement statement = this.connection.prepareStatement(SQL_SELECT_ARTICLE)) { statement.setLong(1, articleIdentity); try (ResultSet resultSet = statement.executeQuery()) { if (!resultSet.next()) throw new IllegalStateException("article doesn't exist."); article.setIdentity(resultSet.getLong("identity")); article.setDescription(resultSet.getString("description")); article.setCount(resultSet.getInt("count")); article.setPrice(resultSet.getLong("price")); } } } return article; }
/** * Returns all article data. * * @throws IllegalStateException if the login data is invalid * @throws SQLException if there is a problem with the underlying JDBC connection */ public SortedSet<Article> queryArticles() throws SQLException { final SortedSet<Article> articles = new TreeSet<Article>(); synchronized (this.connection) { try (PreparedStatement statement = this.connection.prepareStatement(SQL_SELECT_ARTICLES)) { try (ResultSet resultSet = statement.executeQuery()) { while (resultSet.next()) { final Article article = new Article(); article.setIdentity(resultSet.getLong("identity")); article.setDescription(resultSet.getString("description")); article.setCount(resultSet.getInt("count")); article.setPrice(resultSet.getLong("price")); articles.add(article); } } } } return articles; }