@Override public int executeRemove(List<? extends WorkflowElementParameter> entities) throws DatabaseException { Connection conn = getDatabase().getConnection(); int rowsAffected = 0; // create sql StringBuffer sql = new StringBuffer("DELETE FROM WorkflowElementParameter WHERE "); // key $f_index: id { sql.append("id in ("); boolean first = true; for (WorkflowElementParameter e : entities) { // put the , if (first) first = false; else sql.append(","); sql.append("'" + this.escapeSql(e.getId().toString()) + "'"); } sql.append(") "); } // execute sql Statement stmt = null; try { stmt = conn.createStatement(); rowsAffected = stmt.executeUpdate(sql.toString()); } catch (SQLException sqlEx) { throw new DatabaseException(sqlEx); } finally { JDBCDatabase.closeStatement(stmt); } return rowsAffected; }
@Override public int executeAdd(List<? extends WorkflowElementParameter> entities) throws DatabaseException { Connection conn = getDatabase().getConnection(); // create big mysql query StringBuffer sql = new StringBuffer( "INSERT INTO WorkflowElementParameter (WorkflowElement,Parameter,Value) VALUES "); { boolean first = true; for (WorkflowElementParameter e : entities) { // put the , if (first) first = false; else sql.append(","); sql.append("("); // workflowElement if (e.getWorkflowElement_Id() != null) { sql.append("'" + this.escapeSql(e.getWorkflowElement_Id().toString()) + "'" + ","); } else { sql.append("null,"); } // parameter if (e.getParameter_Id() != null) { sql.append("'" + this.escapeSql(e.getParameter_Id().toString()) + "'" + ","); } else { sql.append("null,"); } // value if (e.getValue() != null) { sql.append("'" + this.escapeSql(e.getValue().toString()) + "'"); } else { sql.append("null"); } sql.append(")"); } } // execute sql Statement stmt = null; try { stmt = conn.createStatement(); // logger.debug("created statement: "+sql.toString()); int updatedRows = stmt.executeUpdate(sql.toString(), Statement.RETURN_GENERATED_KEYS); getGeneratedKeys(entities, stmt, 0); return updatedRows; } catch (SQLException sqlEx) { throw new DatabaseException(sqlEx); } finally { JDBCDatabase.closeStatement(stmt); } }
@Override public int executeUpdate(List<? extends WorkflowElementParameter> entities) throws DatabaseException { Connection conn = getDatabase().getConnection(); // create sql string StringBuffer sql = new StringBuffer( "INSERT INTO WorkflowElementParameter (id,WorkflowElement,Parameter,Value) VALUES "); boolean first = true; for (WorkflowElementParameter e : entities) { // put the , if (first) first = false; else sql.append(","); sql.append("("); // id if (e.getId() != null) { sql.append("'" + this.escapeSql(e.getId()).toString() + "'" + ","); } else { sql.append("null,"); } // workflowElement if (e.getWorkflowElement_Id() != null) { sql.append("'" + this.escapeSql(e.getWorkflowElement_Id()).toString() + "'" + ","); } else { sql.append("null,"); } // parameter if (e.getParameter_Id() != null) { sql.append("'" + this.escapeSql(e.getParameter_Id()).toString() + "'" + ","); } else { sql.append("null,"); } // value if (e.getValue() != null) { sql.append("'" + this.escapeSql(e.getValue()).toString() + "'"); } else { sql.append("null"); } sql.append(")"); } sql.append( " ON DUPLICATE KEY UPDATE WorkflowElement=VALUES(WorkflowElement),Parameter=VALUES(Parameter),Value=VALUES(Value),id=LAST_INSERT_ID(id)"); // execute sql Statement stmt = null; try { stmt = conn.createStatement(); return stmt.executeUpdate(sql.toString()) / 2; } catch (SQLException sqlEx) { logger.debug("Query that caused exception:" + sql.toString()); throw new DatabaseException(sqlEx); } finally { JDBCDatabase.closeStatement(stmt); } }