// 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;
        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);
        }

        return result;
    }

    @Override
    public Product findByProductId(long productId) {
        Product result = null;

        try (Connection connection = getConnection();
             PreparedStatement statement = connection.prepareStatement(FIND_BY_PRODUCT_ID_SQL)) {
            statement.setLong(1, productId);
            try (ResultSet resultSet = statement.executeQuery()) {
                if (resultSet.next()) {
                    result = 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;

        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);
        }

        return result;
    }

    @Override
    public Product findByProductId(long productId) {
        Product result = null;

        try (Connection connection = getConnection();
             PreparedStatement statement = connection.prepareStatement(FIND_BY_PRODUCT_ID_SQL)) {
            statement.setLong(1, productId);
            try (ResultSet resultSet = statement.executeQuery()) {
                if (resultSet.next()) {
                    result = readProduct(resultSet);
                }
            }
        } catch (SQLException e) {
            throw new SimpleAffableQueryDbException("Encountered problem reading products by product id", e);