Пример #1
0
  private ProductLine getProductLineFromDBWithChild(Connection con, int id) throws SQLException {

    ModuleDAO moduleDao = new ModuleDAO();

    ProductLine productLine = null;
    try (PreparedStatement prepStatement = con.prepareStatement(selectProductLine)) {
      prepStatement.setInt(1, id);
      try (ResultSet result = prepStatement.executeQuery()) {

        while (result.next()) {
          productLine = new ProductLine();
          productLine.setId(result.getInt("productline_id"));
          productLine.setName(result.getString("name"));
          productLine.setDescription(result.getString("description"));
          Integer parent = result.getInt("parent_productline");
          if (result.wasNull()) {
            productLine.setParent(null);
          } else {
            productLine.setParent(getProductLine(parent, con));
          }
        }
        if (productLine != null) {
          productLine.setModules(moduleDao.getModulesWhithChildsByProductLine(productLine, con));
        }
      }
    }
    return productLine;
  }
Пример #2
0
  private ProductLine[] getProductLinesByParentFromDB(Connection con, int parent_id)
      throws ClassNotFoundException, SQLException {

    ModuleDAO moduleDao = new ModuleDAO();

    ProductLine productLine = null;
    try (PreparedStatement prepStatement = con.prepareStatement(selectProductLinesByParent)) {
      prepStatement.setInt(1, parent_id);
      Set<ProductLine> resultSet = new HashSet<>();
      try (ResultSet result = prepStatement.executeQuery()) {

        while (result.next()) {
          productLine = new ProductLine();
          productLine.setId(result.getInt("productline_id"));
          productLine.setName(result.getString("name"));
          productLine.setDescription(result.getString("description"));
          Integer parent = result.getInt("parent_productline");
          if (result.wasNull()) {
            productLine.setParent(null);
          } else {
            productLine.setParent(getProductLine(parent, con));
          }
          productLine.setModules(moduleDao.getModulesWhithChildsByProductLine(productLine, con));
          resultSet.add(productLine);
        }
      }
      return resultSet.toArray(new ProductLine[resultSet.size()]);
    }
  }
Пример #3
0
  public int createAll(ProductLine productLine, Connection connection)
      throws ClassNotFoundException, SQLException {
    ModuleDAO moduleDao = new ModuleDAO();

    int plId = this.save(productLine, connection);
    productLine.setId(plId);
    moduleDao.createAll(productLine.getModules(), connection);
    return plId;
  }
Пример #4
0
  public Set<ProductLine> getProductLine(Connection con) throws SQLException {
    Set<ProductLine> set = new HashSet<ProductLine>();
    try (PreparedStatement prepareStmt = con.prepareStatement(selectAllProductLine)) {
      ResultSet result = prepareStmt.executeQuery();

      while (result.next()) {
        ProductLine p = new ProductLine();
        p.setId(result.getInt("productline_id"));
        p.setName(result.getString("name"));
        p.setDescription(result.getString("description"));
        Integer parent = result.getInt("parent_productline");
        if (result.wasNull()) {
          p.setParent(null);
        } else {
          p.setParent(getProductLineFromDB(con, parent));
        }
        set.add(p);
      }
    }
    return set;
  }