AbstractSQLBuilder { public String buildUpdateSQL(final DataRecord dataRecord, final Collection<Column> conditionColumns) { String sqlCacheKey = UPDATE_SQL_CACHE_KEY_PREFIX + dataRecord.getTableName(); if (!sqlCacheMap.containsKey(sqlCacheKey)) { sqlCacheMap.put(sqlCacheKey, buildUpdateSQLInternal(dataRecord.getTableName(), conditionColumns)); } StringBuilder updatedColumnString = new StringBuilder(); for (Column each : extractUpdatedColumns(dataRecord.getColumns())) { updatedColumnString.append(String.format("%s = ?,", quote(each.getName()))); } updatedColumnString.setLength(updatedColumnString.length() - 1); return String.format(sqlCacheMap.get(sqlCacheKey), updatedColumnString); }  String buildInsertSQL(final DataRecord dataRecord); String buildUpdateSQL(final DataRecord dataRecord, final Collection<Column> conditionColumns); String buildDeleteSQL(final DataRecord dataRecord, final Collection<Column> conditionColumns); String buildCountSQL(final String tableName);  }
@Test public void assertBuildUpdateSQLWithPrimaryKey() { String actual = sqlBuilder.buildUpdateSQL(mockDataRecord("t2"), RecordUtil.extractPrimaryColumns(mockDataRecord("t2"))); assertThat(actual, is("UPDATE `t2` SET `c1` = ?,`c2` = ?,`c3` = ? WHERE `id` = ?")); }
@Test public void assertBuildUpdateSQLWithShardingColumns() { DataRecord dataRecord = mockDataRecord("t2"); String actual = sqlBuilder.buildUpdateSQL(dataRecord, mockConditionColumns(dataRecord)); assertThat(actual, is("UPDATE `t2` SET `c1` = ?,`c2` = ?,`c3` = ? WHERE `id` = ? and `sc` = ?")); }