SQLBatchParams implements LogParam { @Override public void append(StringBuilder builder, Set<String> maskedFields, int maxParamLength) { int maxLength = builder.length() + maxParamLength; builder.append('['); int index = 0; for (Object[] batch : params) { if (index > 0) builder.append(", "); builder.append('['); int length = batch.length; for (int i = 0; i < length; i++) { if (i > 0) builder.append(", "); builder.append(SQLParams.value(batch[i], mapper)); } builder.append(']'); if (builder.length() >= maxLength) { builder.setLength(maxLength); builder.append("...(truncated)"); return; } index++; } builder.append(']'); } SQLBatchParams(EnumDBMapper mapper, List<Object[]> params); @Override void append(StringBuilder builder, Set<String> maskedFields, int maxParamLength);  }
@Test void append() { var mapper = new EnumDBMapper(); mapper.registerEnumClass(TestEnum.class); var params = new SQLBatchParams(mapper, List.of(new Object[]{"param1", 1, TestEnum.V1}, new Object[]{"param2", 2, TestEnum.V2}, new Object[]{"param3", 3, null})); var builder = new StringBuilder(); params.append(builder, Set.of(), 10000); assertThat(builder.toString()) .isEqualTo("[[param1, 1, DB_V1], [param2, 2, DB_V2], [param3, 3, null]]"); }
@Test void appendWithTruncation() { var params = new SQLBatchParams(new EnumDBMapper(), List.of(new Object[]{"param1", 1}, new Object[]{"param2", 2}, new Object[]{"param3", 3})); var builder = new StringBuilder(); params.append(builder, Set.of(), 10); assertThat(builder.toString()) .hasSize(10 + "...(truncated)".length()) .isEqualTo("[[param1, ...(truncated)"); }