InTermFragmentBuilder extends AbstractTermFragmentBuilder { @Override public SqlFragments createFragments(String columnFullName, RDBColumnMetadata column, Term term) { List<Object> value = convertList(column, term); if (value == null || value.isEmpty()) { return EmptySqlFragments.INSTANCE; } int len = value.size(); PrepareSqlFragments fragments = PrepareSqlFragments.of(); if (len > 500) { fragments.addSql("("); } fragments.addSql(columnFullName) .addSql(symbol); int flag = 0; for (int i = 0; i < len; i++) { if (flag++ != 0) { fragments.addSql(","); } fragments.addSql("?"); if (flag > 500 && i != len - 1) { flag = 0; fragments.addSql(") or") .addSql(columnFullName) .addSql(symbol); } } if (len > 500) { fragments.addSql(")"); } return fragments .addSql(")") .addParameter(value); } InTermFragmentBuilder(String termType, String name, boolean isNot); @Override SqlFragments createFragments(String columnFullName, RDBColumnMetadata column, Term term);  }
@Test public void test() { InTermFragmentBuilder builder = new InTermFragmentBuilder("in", "在...之中",false); Term term = new Term(); term.setValue("1"); SqlFragments fragments = builder.createFragments("id", null, term); assertNotNull(fragments); SqlRequest request = fragments.toRequest(); System.out.println(request.getSql()); Assert.assertEquals(request.getSql(), "id in( ? )"); }
@Test public void testLarge() { InTermFragmentBuilder builder = new InTermFragmentBuilder("in", "在...之中",false); Term term = new Term(); List<Integer> values = Flux.range(0, 510).collectList().block(); assertNotNull(values); term.setValue(values); SqlFragments fragments = builder.createFragments("id", null, term); assertNotNull(fragments); SqlRequest request = fragments.toRequest(); assertArrayEquals(values.toArray(),request.getParameters()); System.out.println(request.getSql()); }