コード例 #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()]);
    }
  }