コード例 #1
0
 public static void deleteTemplate(Template template) throws SQLException {
   if (template.getId() != null) {
     for (Templateproperty property : template.getEigenschaften()) {
       PropertyManager.deleteTemplateProperty(property);
     }
     Connection connection = null;
     try {
       connection = MySQLHelper.getInstance().getConnection();
       QueryRunner run = new QueryRunner();
       String sql = "DELETE FROM vorlagen WHERE VorlagenID = " + template.getId();
       run.update(connection, sql);
     } finally {
       if (connection != null) {
         MySQLHelper.closeConnection(connection);
       }
     }
   }
 }
コード例 #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);
    }
  }