Below is a code snippet where I want to replace few strings. I am using date_add pattern two places in my code, but its getting replaced only once.I am using string.replaceAll but still its not working for me. Please help me identifying the reason.
public class Implementation {
public static void main(String[] args) {
String ipquery = "select to_date(id) from location_dim location_dim where ( location_name = '123' ) limit 10 union all select item_id " +
"item_id from (select item_dim.time_id from item_dim item_dim where item_dim.time_id in ( select time_dim.id from time_dim " +
"where (( time_dim . day ) = date_add( '1999-01-01' , 2 )) ) ) item_dim inner join time_dim time_dim on (( item_dim . time_id ) " +
"= ( time_dim . id )) where (( time_dim . day ) = date_add( '1999-01-01' , 2 )) limit 20";
System.out.println(replace(ipquery));
}
public static String replace(String query) {
Map<String, String> imputnmatch = new HashMap<String, String>();
imputnmatch.put("to_date", "date");
imputnmatch.put("format_number", "format");
imputnmatch.put("date_sub\\((.*),\\s*([0-9]+\\s*)\\)",
"date_sub($1, interval $2 day)");
imputnmatch.put("date_add\\((.*),\\s*([0-9]+\\s*)\\)",
"date_add($1, interval $2 day)");
for (Map.Entry<String, String> entry : imputnmatch.entrySet()) {
query = query.replaceAll(entry.getKey(), entry.getValue());
System.out.println(entry.getKey() + " " + entry.getValue() + " " +query);
}
return query;
}
}