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); } } } }
@Override public Template handle(ResultSet rs) throws SQLException { try { if (rs.next()) { int templateId = rs.getInt("VorlagenID"); String herkunft = rs.getString("Herkunft"); int processId = rs.getInt("ProzesseID"); Template template = new Template(); template.setId(templateId); template.setHerkunft(herkunft); template.setProcessId(processId); List<Templateproperty> properties = PropertyManager.getTemplateProperties(templateId); template.setEigenschaften(properties); return template; } } finally { if (rs != null) { rs.close(); } } return null; }
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); } }