@Test public void testMultiGetSql() { String sql = "select * from table where uid=? and type in (?) order by date"; Object[] params = new Object[] { 12345, new Object[] { 1234, 1234 } }; String rs = DaoUtil.expendMultiGetSql(sql, params); Assert.assertEquals("select * from table where uid=? and type in (?,?) order by date", rs); sql = "select * from table where uid=? and type in (?) and vflag in (?) order by date"; params = new Object[] {123, new Object[] {12,12}, new Object[]{12,12}}; rs = DaoUtil.expendMultiGetSql(sql, params); Assert.assertEquals("select * from table where uid=? and type in (?,?) and vflag in (?,?) order by date", rs); params = new Object[] {123, new Object[] {12}, new Object[]{12}}; rs = DaoUtil.expendMultiGetSql(sql, params); Assert.assertEquals("select * from table where uid=? and type in (?) and vflag in (?) order by date", rs); params = new Object[] {123, 12, 12}; rs = DaoUtil.expendMultiGetSql(sql, params); Assert.assertEquals("select * from table where uid=? and type in (?) and vflag in (?) order by date", rs); sql = "select * from table where uid=?"; rs = DaoUtil.expendMultiGetSql(sql, params); Assert.assertEquals("select * from table where uid=?", rs); }
public static String expendMultiGetSql(String sql, Object[] params) { int lastQuoteIndex = -1; for (int i = 0; i < params.length; i++) { lastQuoteIndex = sql.indexOf('?', lastQuoteIndex + 1); Object param = params[i]; if (param instanceof Object[]) { Object[] nestArrayParam = (Object[]) param; String multipleGetStatement = multiGetPrepareStatement(nestArrayParam.length); sql = sql.substring(0, lastQuoteIndex) + multipleGetStatement + sql.substring(lastQuoteIndex + 1); lastQuoteIndex += multipleGetStatement.length(); } } return sql; }
DaoUtil { public static String expendMultiGetSql(String sql, Object[] params) { int lastQuoteIndex = -1; for (int i = 0; i < params.length; i++) { lastQuoteIndex = sql.indexOf('?', lastQuoteIndex + 1); Object param = params[i]; if (param instanceof Object[]) { Object[] nestArrayParam = (Object[]) param; String multipleGetStatement = multiGetPrepareStatement(nestArrayParam.length); sql = sql.substring(0, lastQuoteIndex) + multipleGetStatement + sql.substring(lastQuoteIndex + 1); lastQuoteIndex += multipleGetStatement.length(); } } return sql; } }
DaoUtil { public static String expendMultiGetSql(String sql, Object[] params) { int lastQuoteIndex = -1; for (int i = 0; i < params.length; i++) { lastQuoteIndex = sql.indexOf('?', lastQuoteIndex + 1); Object param = params[i]; if (param instanceof Object[]) { Object[] nestArrayParam = (Object[]) param; String multipleGetStatement = multiGetPrepareStatement(nestArrayParam.length); sql = sql.substring(0, lastQuoteIndex) + multipleGetStatement + sql.substring(lastQuoteIndex + 1); lastQuoteIndex += multipleGetStatement.length(); } } return sql; }  }
DaoUtil { public static String expendMultiGetSql(String sql, Object[] params) { int lastQuoteIndex = -1; for (int i = 0; i < params.length; i++) { lastQuoteIndex = sql.indexOf('?', lastQuoteIndex + 1); Object param = params[i]; if (param instanceof Object[]) { Object[] nestArrayParam = (Object[]) param; String multipleGetStatement = multiGetPrepareStatement(nestArrayParam.length); sql = sql.substring(0, lastQuoteIndex) + multipleGetStatement + sql.substring(lastQuoteIndex + 1); lastQuoteIndex += multipleGetStatement.length(); } } return sql; }  static String createMutiGetEncodedSql(String sql, int paramsSize); static String createMutiGetSql(String sql, int paramsSize); static String expendMultiGetSql(String sql, Object[] params); static Object[] expendMultiGetParams(Object[] params); static String createMultiInsertSql(String sqlPrefix, String sqlSuffix, int valuesSize); static String buildSql(String rawSql, String db, String table); }
DaoUtil { public static String expendMultiGetSql(String sql, Object[] params) { int lastQuoteIndex = -1; for (int i = 0; i < params.length; i++) { lastQuoteIndex = sql.indexOf('?', lastQuoteIndex + 1); Object param = params[i]; if (param instanceof Object[]) { Object[] nestArrayParam = (Object[]) param; String multipleGetStatement = multiGetPrepareStatement(nestArrayParam.length); sql = sql.substring(0, lastQuoteIndex) + multipleGetStatement + sql.substring(lastQuoteIndex + 1); lastQuoteIndex += multipleGetStatement.length(); } } return sql; }  static String createMutiGetEncodedSql(String sql, int paramsSize); static String createMutiGetSql(String sql, int paramsSize); static String expendMultiGetSql(String sql, Object[] params); static Object[] expendMultiGetParams(Object[] params); static String createMultiInsertSql(String sqlPrefix, String sqlSuffix, int valuesSize); static String buildSql(String rawSql, String db, String table);  }