SqlViewUtils { public static String substituteSqlVariable( String sql, String name, String value ) { final String regex = "\\$\\{(" + name + ")\\}"; if ( value != null && SqlView.isValidQueryValue( value ) ) { return sql.replaceAll( regex, value ); } return sql; }  static Set<String> getVariables( String sql ); static String substituteSqlVariables( String sql, Map<String, String> variables ); static String substituteSqlVariable( String sql, String name, String value ); static String removeQuerySeparator( String sql ); static final String VARIABLE_EXPRESSION; static final Pattern VARIABLE_PATTERN; }
@Test public void testSubsituteSqlVariable() { String sql = "select * from datavalue where level=${level} and id='${id}'"; String expected = "select * from datavalue where level=4 and id='${id}'"; String actual = SqlViewUtils.substituteSqlVariable( sql, "level", "4" ); assertEquals( expected, actual ); }