// Path: src/main/java/business/SimpleAffableDbException.java
// public static class SimpleAffableQueryDbException extends SimpleAffableDbException {
//     public SimpleAffableQueryDbException(String message) {
//         super(message);
//     }
// 
//     public SimpleAffableQueryDbException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/business/JdbcUtils.java
// public static Connection getConnection()  {
//     if (dataSource == null) {
//         dataSource = getDataSource(JDBC_SIMPLEAFFABLEBEAN);
//     }
// 
//     try {
//         return dataSource.getConnection();
//     } catch (SQLException e) {
//         throw new SimpleAffableConnectionDbException("Encountered a SQL issue getting a connection", e);
//     }
// 
// }


import business.SimpleAffableDbException.SimpleAffableQueryDbException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static business.JdbcUtils.getConnection;
            "product p " +
        "WHERE " +
            "p.category_id = ?";

    private static final String FIND_BY_PRODUCT_ID_SQL =
        "SELECT " +
            " p.product_id, " +
            " p.category_id, " +
            " p.name, " +
            " p.price, " +
            " p.last_update " +
        "FROM " +
            " product p " +
        "WHERE " +
            "p.product_id = ?";


    @Override
    public List<Product> findByCategoryId(long categoryId) {
        List<Product> result = new ArrayList<>(16);

        try (Connection connection = getConnection();
        PreparedStatement statement = connection.prepareStatement(FIND_BY_CATEGORY_SQL)) {
            statement.setLong(1, categoryId);
            try (ResultSet resultSet = statement.executeQuery()) {
                while (resultSet.next()) {
                    result.add(readProduct(resultSet));
                }
            }
        } catch (SQLException e) {
// Path: src/main/java/business/SimpleAffableDbException.java
// public static class SimpleAffableQueryDbException extends SimpleAffableDbException {
//     public SimpleAffableQueryDbException(String message) {
//         super(message);
//     }
// 
//     public SimpleAffableQueryDbException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }
// 
// Path: src/main/java/business/JdbcUtils.java
// public static Connection getConnection()  {
//     if (dataSource == null) {
//         dataSource = getDataSource(JDBC_SIMPLEAFFABLEBEAN);
//     }
// 
//     try {
//         return dataSource.getConnection();
//     } catch (SQLException e) {
//         throw new SimpleAffableConnectionDbException("Encountered a SQL issue getting a connection", e);
//     }
// 
// }


// Path: src/main/java/business/product/ProductDaoJdbc.java
import business.SimpleAffableDbException.SimpleAffableQueryDbException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static business.JdbcUtils.getConnection;

            "product p " +
        "WHERE " +
            "p.category_id = ?";

    private static final String FIND_BY_PRODUCT_ID_SQL =
        "SELECT " +
            " p.product_id, " +
            " p.category_id, " +
            " p.name, " +
            " p.price, " +
            " p.last_update " +
        "FROM " +
            " product p " +
        "WHERE " +
            "p.product_id = ?";


    @Override
    public List<Product> findByCategoryId(long categoryId) {
        List<Product> result = new ArrayList<>(16);

        try (Connection connection = getConnection();
        PreparedStatement statement = connection.prepareStatement(FIND_BY_CATEGORY_SQL)) {
            statement.setLong(1, categoryId);
            try (ResultSet resultSet = statement.executeQuery()) {
                while (resultSet.next()) {
                    result.add(readProduct(resultSet));
                }
            }
        } catch (SQLException e) {
            throw new SimpleAffableQueryDbException("Encountered problem reading products by category", e);