orderMngmntWebapp\src\orderMngr\domain\order\OrderRepository.java
 
/* * Copyright (c) 2006-2014 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 ...
 
1311
public final class OrderRepository
  1. orderMngr.domain.order.OrderFactory_MockupsAPI_Test#createOrder: 38
14 
{
15 
   public void create(Order order)
16 
   {
2 Path coverage: 1/2 A: 0 B: 2
172
      String sql = "insert into order (number, customer_id) values (?, ?)";
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61
182
      int orderNo = order.getNumber();
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61
192
      executeInsertUpdateOrDelete(sql, orderNo, order.getCustomerId());
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61
 
212
      for (OrderItem item : order.getItems()) {
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61
224
         executeInsertUpdateOrDelete(
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32x2
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61x2
23 
            "insert into order_item (order_no, product_id, product_desc, quantity, unit_price) values (?, ?, ?, ?, ?)",
242
            orderNo, item.getProductId(), item.getProductDescription(), item.getQuantity(),
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61
252
            item.getUnitPrice());
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61
262
      }
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61
272
   }
  1. orderMngr.domain.order.OrderRepositoryTest#createOrder: 32
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#createOrder: 61
 
29 
   public void update(Order order)
30 
   {
312
      String sql = "update order set customer_id=? where number=?";
  1. orderMngr.domain.order.OrderRepositoryTest#updateOrder: 50
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#updateOrder: 81
322
      executeInsertUpdateOrDelete(sql, order.getCustomerId(), order.getNumber());
  1. orderMngr.domain.order.OrderRepositoryTest#updateOrder: 50
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#updateOrder: 81
332
   }
  1. orderMngr.domain.order.OrderRepositoryTest#updateOrder: 50
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#updateOrder: 81
 
35 
   public void remove(Order order)
36 
   {
372
      String sql = "delete from order where number=?";
  1. orderMngr.domain.order.OrderRepositoryTest#removeOrder: 62
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#removeOrder: 98
382
      executeInsertUpdateOrDelete(sql, order.getNumber());
  1. orderMngr.domain.order.OrderRepositoryTest#removeOrder: 62
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#removeOrder: 98
392
   }
  1. orderMngr.domain.order.OrderRepositoryTest#removeOrder: 62
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#removeOrder: 98
 
41 
   public Order findByNumber(int orderNumber)
42 
   {
43 
      try {
442
         return loadOrder(orderNumber);
  1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
  2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
45 
      }
460
      catch (SQLException e) {
    470
             throw new RuntimeException(e);
      48 
            }
      49 
         }
       
      51 
         private Order loadOrder(int orderNumber) throws SQLException
      52 
         {
      2 Path coverage: 1/2 A: 2 B: 0
      532
            ResultSet result = executeQuery("select customer_id from order where number=?", orderNumber);
      1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
      2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
       
      55 
            try {
      562
               if (result.next()) {
      1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
      2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
      572
                  String customerId = result.getString(1);
      1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
      2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
      582
                  Order order = new Order(orderNumber, customerId);
      1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
      2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
      592
                  loadOrderItems(order);
      1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
      2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
      602
                  return order;
      1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
      2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
      61 
               }
       
      630
               return null;
        64 
              }
        65 
              finally {
        662
                 closeStatement(result);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        67 
              }
        68 
           }
         
        70 
           private void loadOrderItems(Order order) throws SQLException
        71 
           {
        2 Path coverage: 1/2 A: 0 B: 2
        722
              ResultSet result =
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        732
                 executeQuery(
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        74 
                    "select product_id, product_desc, quantity, unit_price from order_item where order_number=?",
        752
                    order.getNumber());
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
         
        77 
              try {
        784
                 while (result.next()) {
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58x2
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169x2
        792
                    String productId = result.getString(1);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        802
                    String productDescription = result.getString(2);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        812
                    int quantity = result.getInt(3);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        822
                    BigDecimal unitPrice = result.getBigDecimal(4);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
         
        842
                    OrderItem item = new OrderItem(order, productId, productDescription, quantity, unitPrice);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        852
                    order.getItems().add(item);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        862
                 }
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        87 
              }
        88 
              finally {
        892
                 closeStatement(result);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        902
              }
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
        912
           }
        1. orderMngr.domain.order.OrderFindersTest#findOrderByNumber: 58
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByNumber: 169
         
        93 
           public List<Order> findByCustomer(String customerId)
        94 
           {
        2 Path coverage: 1/2 A: 0 B: 2
        952
              ResultSet result = executeQuery("select number from order where customer_id=?", customerId);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182
         
        97 
              try {
        982
                 List<Order> orders = new ArrayList<>();
        1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182
         
        1004
                 while (result.next()) {
        1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85x2
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182x2
        1012
                    int orderNumber = result.getInt(1);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182
        1022
                    Order order = new Order(orderNumber, customerId);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182
        1032
                    loadOrderItems(order);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182
        1042
                    orders.add(order);
        1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182
        1052
                 }
        1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182
         
        1072
                 return orders;
        1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85
        2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182
        108 
              }
        1090
              catch (SQLException e) {
          1100
                   throw new RuntimeException(e);
            111 
                  }
            112 
                  finally {
            1132
                     closeStatement(result);
            1. orderMngr.domain.order.OrderFindersTest#findOrderByCustomer: 85
            2. orderMngr.domain.order.OrderRepository_MockupsAPI_Test#findOrderByCustomer: 182
            114 
                  }
            115 
               }
            116 
            }