SqlViewUtils { public static Set<String> getVariables( String sql ) { Set<String> variables = new HashSet<>(); Matcher matcher = VARIABLE_PATTERN.matcher( sql ); while ( matcher.find() ) { variables.add( matcher.group( 1 ) ); } return variables; }  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 testGetVariables() { String sql = "select * from dataelement where name = '${de_name}' and aggregationType = '${de_aggregation_type}'"; Set<String> variables = SqlViewUtils.getVariables( sql ); assertEquals( 2, variables.size() ); assertTrue( variables.contains( "de_name" ) ); assertTrue( variables.contains( "de_aggregation_type" ) ); }