Example #1
0
 public Weight add(int userId, double weight, Date weightDate) throws DAOException {
   String sql =
       "INSERT INTO diettracker.weight (userid, weight, weightdate, createddate) VALUES (?, ?, ?, now())";
   ResultSetHandler<Weight> resultSetHandler = new BeanHandler<>(Weight.class);
   QueryRunner queryRunner = new QueryRunner(getDataSource());
   Object[] params = {userId, weight, new java.sql.Date(weightDate.getTime())};
   try {
     return queryRunner.insert(sql, resultSetHandler, params);
   } catch (SQLException e) {
     e.printStackTrace();
     logger.fatal(e.getMessage() + " " + e.getCause());
     throw new DAOException(e.getMessage(), e.getCause());
   }
 }
Example #2
0
  public static void saveTemplate(Template template) throws SQLException {
    Connection connection = null;
    try {
      connection = MySQLHelper.getInstance().getConnection();
      QueryRunner run = new QueryRunner();
      String sql = "";

      if (template.getId() == null) {
        sql = "INSERT INTO vorlagen ( Herkunft, ProzesseID ) VALUES ( ?, ?)";
        Object[] param = {
          template.getHerkunft() == null ? null : template.getHerkunft(),
          template.getProzess().getId()
        };

        int id = run.insert(connection, sql, MySQLHelper.resultSetToIntegerHandler, param);
        template.setId(id);
      } else {
        sql =
            "UPDATE vorlagen set Herkunft = ?, ProzesseID = ? WHERE VorlagenID ="
                + template.getId();
        Object[] param = {
          template.getHerkunft() == null ? null : template.getHerkunft(),
          template.getProzess().getId()
        };
        run.update(connection, sql, param);
      }
    } finally {
      if (connection != null) {
        MySQLHelper.closeConnection(connection);
      }
    }

    List<Templateproperty> templateProperties = template.getEigenschaften();
    for (Templateproperty property : templateProperties) {
      property.setTemplateId(template.getId());
      property = PropertyManager.saveTemplateProperty(property);
    }
  }