// 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/SimpleAffableDbException.java
// public static class SimpleAffableUpdateDbException extends SimpleAffableDbException {
//     public SimpleAffableUpdateDbException(String message) {
//         super(message);
//     }
// 
//     public SimpleAffableUpdateDbException(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 business.SimpleAffableDbException.SimpleAffableUpdateDbException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import static business.JdbcUtils.getConnection;
        try (PreparedStatement statement =
                 connection.prepareStatement(CREATE_CUSTOMER_SQL, Statement.RETURN_GENERATED_KEYS)) {
            statement.setString(1, customerForm.getName());
            statement.setString(2, customerForm.getEmail());
            statement.setString(3, customerForm.getPhone());
            statement.setString(4, customerForm.getAddress());
            statement.setString(5, customerForm.getCityRegion());
            statement.setString(6, customerForm.getCcNumber());
            int affected = statement.executeUpdate();
            if (affected != 1) {
                throw new SimpleAffableUpdateDbException("Failed to insert a customer, affected row count = "
                    + affected);
            }
            long customerId;
            ResultSet rs = statement.getGeneratedKeys();
            if (rs.next()) {
                customerId = rs.getLong(1);
            } else {
                throw new SimpleAffableQueryDbException("Failed to retrieve customerId auto-generated key");
            }

            return customerId;
        } catch (SQLException e) {
            throw new SimpleAffableUpdateDbException("Encountered problem creating a new customer ", e);
        }
    }

    @Override
    public Customer findByCustomerId(long customerId) {
        Customer result = null;
// 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/SimpleAffableDbException.java
// public static class SimpleAffableUpdateDbException extends SimpleAffableDbException {
//     public SimpleAffableUpdateDbException(String message) {
//         super(message);
//     }
// 
//     public SimpleAffableUpdateDbException(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/customer/CustomerDaoJdbc.java
import business.SimpleAffableDbException.SimpleAffableQueryDbException;
import business.SimpleAffableDbException.SimpleAffableUpdateDbException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import static business.JdbcUtils.getConnection;

        try (PreparedStatement statement =
                 connection.prepareStatement(CREATE_CUSTOMER_SQL, Statement.RETURN_GENERATED_KEYS)) {
            statement.setString(1, customerForm.getName());
            statement.setString(2, customerForm.getEmail());
            statement.setString(3, customerForm.getPhone());
            statement.setString(4, customerForm.getAddress());
            statement.setString(5, customerForm.getCityRegion());
            statement.setString(6, customerForm.getCcNumber());
            int affected = statement.executeUpdate();
            if (affected != 1) {
                throw new SimpleAffableUpdateDbException("Failed to insert a customer, affected row count = "
                    + affected);
            }
            long customerId;
            ResultSet rs = statement.getGeneratedKeys();
            if (rs.next()) {
                customerId = rs.getLong(1);
            } else {
                throw new SimpleAffableQueryDbException("Failed to retrieve customerId auto-generated key");
            }

            return customerId;
        } catch (SQLException e) {
            throw new SimpleAffableUpdateDbException("Encountered problem creating a new customer ", e);
        }
    }

    @Override
    public Customer findByCustomerId(long customerId) {
        Customer result = null;
        try (Connection connection = getConnection();