DaoUtils { public static String createSqlList(Iterable values, boolean quoteValues) { if (values == null || !values.iterator().hasNext()) { return "()"; } StringBuilder buf = new StringBuilder(); buf.append('('); for (final Object value : values) { Object o = value; if (quoteValues) { buf.append("'"); } buf.append(o); if (quoteValues) { buf.append("'"); } buf.append(','); } buf.delete(buf.length() - 1, buf.length()); buf.append(')'); return buf.toString(); }  static Long getLong(ResultSet rs, String columnName); static Integer getInteger(ResultSet rs, String columnName); static Boolean getBoolean(ResultSet rs, String columnName); static Date getDate(ResultSet rs, String columnName); static Double getDouble(ResultSet rs, String columnName); static Long getLongIfPresent(ResultSet rs, String columnName); static Integer getIntegerIfPresent(ResultSet rs, String columnName); static Boolean getBooleanIfPresent(ResultSet rs, String columnName); static Date getDateIfPresent(ResultSet rs, String columnName); static Double getDoubleIfPresent(ResultSet rs, String columnName); static String getStringIfPresent(ResultSet rs, String columnName); static void setLong(PreparedStatement stmt, Long value, int index); static void setInteger(PreparedStatement stmt, Integer value, int index); static void setShort(PreparedStatement stmt, Short value, int index); static void setDate(PreparedStatement stmt, Date value, int index); static void setBoolean(PreparedStatement stmt, Boolean value, int index); static void setDouble(PreparedStatement stmt, Double value, int index); static String createSqlList(Iterable values, boolean quoteValues); static String createSqlList(Object[] values, boolean quoteValues); static boolean existsTable(DataSource dataSource, final String tableName); static String getDatabaseURLAndUserName(DataSource dataSource); static final String ORDER_ASC; static final String ORDER_DESC; }
@Test public void testCreateSqlList() { List<String> values = new ArrayList<String>(); values.add("a"); values.add("b"); values.add("c"); assertEquals("('a','b','c')", DaoUtils.createSqlList(values, true)); assertEquals("(a,b,c)", DaoUtils.createSqlList(values, false)); List<Object> values2 = new ArrayList<Object>(); values2.add("a"); values2.add(1L); values2.add("b"); assertEquals("('a','1','b')", DaoUtils.createSqlList(values2, true)); assertEquals("(a,1,b)", DaoUtils.createSqlList(values2, false)); values2.clear(); assertEquals("()", DaoUtils.createSqlList(values2, true)); assertEquals("()", DaoUtils.createSqlList(values2, false)); values2.add("foo"); assertEquals("('foo')", DaoUtils.createSqlList(values2, true)); assertEquals("(foo)", DaoUtils.createSqlList(values2, false)); }