orderMngmntWebapp\src\orderMngr\domain\order\OrderRepository.java
 
/* * Copyright (c) 2006 Rogério Liesenfeld * This file is subject to the terms of the MIT license (see LICENSE.txt). */
/*...*/
5 
package orderMngr.domain.order;
 
 
import java.math.*; import java.sql.*; import java.util.*; import static orderMngr.service.Database.*;
import ...
 
135
public final class OrderRepository
    14 
    {
    15 
       public void create(Order order)
    16 
       {
    1 Path coverage: 1/2 A: 0 B: 1
    171
          String sql = "insert into order (number, customer_id) values (?, ?)";
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
    181
          int orderNo = order.getNumber();
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
    191
          executeInsertUpdateOrDelete(sql, orderNo, order.getCustomerId());
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
     
    211
          for (OrderItem item : order.getItems()) {
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
    222
             executeInsertUpdateOrDelete(
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32x2
    23 
                "insert into order_item (order_no, product_id, product_desc, quantity, unit_price) values (?, ?, ?, ?, ?)",
    241
                orderNo, item.getProductId(), item.getProductDescription(), item.getQuantity(),
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
    251
                item.getUnitPrice());
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
    261
          }
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
    271
       }
    1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
     
    29 
       public void update(Order order)
    30 
       {
    311
          String sql = "update order set customer_id=? where number=?";
    1. orderMngr.domain.order.OrderRepositoryTest#updateOrder: 50
    321
          executeInsertUpdateOrDelete(sql, order.getCustomerId(), order.getNumber());
    1. orderMngr.domain.order.OrderRepositoryTest#updateOrder: 50
    331
       }
    1. orderMngr.domain.order.OrderRepositoryTest#updateOrder: 50
     
    35 
       public void remove(Order order)
    36 
       {
    371
          String sql = "delete from order where number=?";
    1. orderMngr.domain.order.OrderRepositoryTest#removeOrder: 62
    381
          executeInsertUpdateOrDelete(sql, order.getNumber());
    1. orderMngr.domain.order.OrderRepositoryTest#removeOrder: 62
    391
       }
    1. orderMngr.domain.order.OrderRepositoryTest#removeOrder: 62
     
    41 
       public Order findByNumber(int orderNumber)
    42 
       {
    43 
          try {
    441
             return loadOrder(orderNumber);
    1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
    45 
          }
    460
          catch (SQLException e) {
      470
               throw new RuntimeException(e);
        48 
              }
        49 
           }
         
        51 
           private Order loadOrder(int orderNumber) throws SQLException
        52 
           {
        1 Path coverage: 1/2 A: 1 B: 0
        531
              ResultSet result = executeQuery("select customer_id from order where number=?", orderNumber);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
         
        55 
              try {
        561
                 if (result.next()) {
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
        571
                    String customerId = result.getString(1);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
        581
                    Order order = new Order(orderNumber, customerId);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
        591
                    loadOrderItems(order);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
        601
                    return order;
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
        61 
                 }
         
        630
                 return null;
          64 
                }
          65 
                finally {
          661
                   closeStatement(result);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          67 
                }
          68 
             }
           
          70 
             private void loadOrderItems(Order order) throws SQLException
          71 
             {
          2 Path coverage: 2/2 A: 1 B: 1
          722
                ResultSet result =
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          2. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          732
                   executeQuery(
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          2. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          74 
                      "select product_id, product_desc, quantity, unit_price from order_item where order_number=?",
          752
                      order.getNumber());
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          2. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
           
          77 
                try {
          783
                   while (result.next()) {
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          2. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56x2
          791
                      String productId = result.getString(1);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          801
                      String productDescription = result.getString(2);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          811
                      int quantity = result.getInt(3);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          821
                      BigDecimal unitPrice = result.getBigDecimal(4);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
           
          841
                      OrderItem item = new OrderItem(order, productId, productDescription, quantity, unitPrice);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          851
                      order.getItems().add(item);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          861
                   }
          1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          87 
                }
          88 
                finally {
          892
                   closeStatement(result);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          2. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          902
                }
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          2. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
          912
             }
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          2. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 56
           
          93 
             public List<Order> findByCustomer(String customerId)
          94 
             {
          1 Path coverage: 1/2 A: 0 B: 1
          951
                ResultSet result = executeQuery("select number from order where customer_id=?", customerId);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
           
          97 
                try {
          981
                   List<Order> orders = new ArrayList<>();
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
           
          1002
                   while (result.next()) {
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75x2
          1011
                      int orderNumber = result.getInt(1);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          1021
                      Order order = new Order(orderNumber, customerId);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          1031
                      loadOrderItems(order);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          1041
                      orders.add(order);
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          1051
                   }
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
           
          1071
                   return orders;
          1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
          108 
                }
          1090
                catch (SQLException e) {
            1100
                     throw new RuntimeException(e);
              111 
                    }
              112 
                    finally {
              1131
                       closeStatement(result);
              1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 75
              114 
                    }
              115 
                 }
              116 
              }