Ejemplo n.º 1
0
 public int update(ProductLine productLine, Connection con) throws SQLException {
   try (PreparedStatement prepareStmt = con.prepareStatement(updateProductLine)) {
     prepareStmt.setString(1, productLine.getName());
     prepareStmt.setString(2, productLine.getDescription());
     prepareStmt.setInt(3, productLine.getId());
     return prepareStmt.executeUpdate();
   }
 }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
  public boolean delete(ProductLine p, Connection con) throws SQLException {
    ModuleDAO mDao = new ModuleDAO();

    for (Module m : p.getModules()) {
      mDao.delete(m, con);
    }

    try (PreparedStatement prepStatement = con.prepareStatement(remove)) {
      prepStatement.setLong(1, p.getId());
      return prepStatement.execute();
    }
  }
Ejemplo n.º 4
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;
  }
Ejemplo n.º 5
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()]);
    }
  }
Ejemplo n.º 6
0
  public int save(ProductLine productLine, Connection con)
      throws ClassNotFoundException, SQLException {
    try (PreparedStatement prepStatement =
        con.prepareStatement(insertProductLine, Statement.RETURN_GENERATED_KEYS)) {
      prepStatement.setString(1, productLine.getName());
      prepStatement.setString(2, productLine.getDescription());
      if (productLine.getParent() == null) {
        prepStatement.setNull(3, Types.NULL);
      } else {
        prepStatement.setInt(3, productLine.getParent().getId());
      }
      boolean a = prepStatement.execute();

      try (ResultSet rs = prepStatement.getGeneratedKeys()) {
        rs.next();
        return rs.getInt(1);
      }
    }
  }
Ejemplo n.º 7
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;
  }