コード例 #1
0
ファイル: Loader.java プロジェクト: nightron/SummerWindTuning
  private static Map<Order, List<OrderDetails>> buildOrderToOrderDetailsMap(
      Map<Integer, OrderDetails> orderDetails) {
    Map<Order, List<OrderDetails>> result = new HashMap<Order, List<OrderDetails>>();

    for (OrderDetails orderDetailsInstance : orderDetails.values()) {
      Order order = orderDetailsInstance.getOrderID();

      if (result.containsKey(order) == false) {
        result.put(order, new ArrayList<OrderDetails>());
      }

      result.get(order).add(orderDetailsInstance);
    }

    return result;
  }
コード例 #2
0
ファイル: Loader.java プロジェクト: nightron/SummerWindTuning
  // @Transactional
  public void loadData() {
    DataLoader dataLoader = new DataLoader();
    try {
      Map<BigInteger, Supplier> suppliers = dataLoader.loadSuppliers("suppliers.xml");
      System.out.println(suppliers.keySet());
      logger.info("loadData : Persisting " + suppliers.size() + " suppliers");
      for (Supplier s : suppliers.values()) {
        supplierDAO.create(s);
      }
      Map<String, Customer> customers = dataLoader.loadCustomers("customers.xml");

      logger.info("loadData : Persisting " + customers.size() + " customers");
      for (Customer c : customers.values()) {
        customerDAO.create(c);
      }

      Map<BigInteger, Category> categories = dataLoader.loadCategories("categories.xml");
      logger.info("loadData : Persisting " + categories.size() + " categories");
      for (Category c : categories.values()) {
        categoryDAO.create(c);
      }

      Map<BigInteger, Shipper> shippers = dataLoader.loadShippers("shippers.xml");
      logger.info("loadData : Persisting " + shippers.size() + " shippers");
      for (Shipper s : shippers.values()) {
        shipperDAO.create(s);
      }

      Map<BigInteger, Product> products =
          dataLoader.loadProducts("products.xml", suppliers, categories);
      logger.info("loadData : Persisting " + products.size() + " products");
      for (Product p : products.values()) productDAO.create(p);

      Map<BigInteger, Employee> employees = dataLoader.loadEmployees("employees.xml");
      logger.info("loadData : Persisting " + employees.size() + " employees");
      for (Employee e : employees.values()) {
        try {
          employeeDAO.create(e);
        } catch (Exception es) {
          logger.warn(es.getMessage());
        }
      }

      logger.info("Loading orders with details");

      Map<BigInteger, Order> orders =
          dataLoader.loadOrders("orders_rand_10000.xml", customers, employees, shippers);
      orders.putAll(dataLoader.loadOrders("orders_rand_20000.xml", customers, employees, shippers));

      Map<Integer, OrderDetails> orderDetails =
          dataLoader.loadOrderDetails("orderdetails_rand_10000.xml", orders, products);
      orderDetails.putAll(
          dataLoader.loadOrderDetails("orderdetails_rand_20000.xml", orders, products));

      Map<Order, List<OrderDetails>> orderToOrderDetails =
          buildOrderToOrderDetailsMap(orderDetails);

      for (OrderDetails od : orderDetails.values()) {
        od.getOrderID().addOrderDetails(od);
      }

      List<Order> orderList = new ArrayList<Order>(orders.values());

      logger.info("Orders persisting:");

      int size = orderList.size();
      int i = 0;
      long start, stop = 0;
      StringBuilder builder = new StringBuilder();
      for (int j = 1000; j < size; j += 1000) {
        start = System.currentTimeMillis();
        entityManager.getTransaction().begin();
        while (i < j) {
          //	entityManager.persist(orderList.get(i));
          orderDAO.create(orderList.get(i));
          i++;
        }
        entityManager.getTransaction().commit();

        stop = System.currentTimeMillis();
        builder.append((j / 1000) + " : " + (stop - start) + "\n");
        logger.info("Orders round: " + j / 1000 + " : " + (stop - start));
      }
      System.out.println(builder.toString());

    } catch (Exception e) {
      e.printStackTrace();
    }
  }