SqlStatementFactory { String createUpdateSqlString(String quotedTablePath, EntryColumnData entryColumnData) { StringBuilder query = new StringBuilder("UPDATE ") .append(quotedTablePath) .append(" SET "); int idx = 0; for (ColumnData column : entryColumnData.getEntryValueColumnData()) { idx++; if (idx > 1) { query.append(", "); } query.append(quote).append(column.getColumnName()).append(quote); query.append(" = ?"); } return addKeyColumnsToQuery(entryColumnData, query); } SqlStatementFactory(String identifierQuoteString);   }
@Test public void getUpdateSqlString() throws Exception { String expectedStatement = String.format("UPDATE %s SET %s = ?, %s = ? WHERE %s = ?", QUOTED_TABLE_PATH, quoted(VALUE_COLUMN_1_NAME), quoted(VALUE_COLUMN_2_NAME), quoted(KEY_COLUMN_1_NAME)); String statement = factory.createUpdateSqlString(QUOTED_TABLE_PATH, entryColumnData); assertThat(statement).isEqualTo(expectedStatement); }
@Test public void getUpdateSqlStringGivenMultipleKeys() throws Exception { keyColumnData.add(new ColumnData(KEY_COLUMN_2_NAME, null, JDBCType.NULL)); String statement = factory.createUpdateSqlString(QUOTED_TABLE_PATH, entryColumnData); String expectedStatement = String.format("UPDATE %s SET %s = ?, %s = ? WHERE %s = ? AND %s = ?", QUOTED_TABLE_PATH, quoted(VALUE_COLUMN_1_NAME), quoted(VALUE_COLUMN_2_NAME), quoted(KEY_COLUMN_1_NAME), quoted(KEY_COLUMN_2_NAME)); assertThat(statement).isEqualTo(expectedStatement); }