private String loadfromFromFile ( String queryName ) throws IllegalStateException { try ( final InputStream is = getClass ( ) . getResourceAsStream ( scriptsFolder + queryName + ".sql" ) ; ) { String sql = StringUtils . join ( IOUtils . readLines ( is , StandardCharsets . UTF_8 ) , IOUtils . LINE_SEPARATOR ) ; // Look for tokens final String [ ] tokens = StringUtils . substringsBetween ( sql , "${" , "}" ) ; if ( tokens != null && tokens . length > 0 ) { final Map < String , String > values = Arrays . stream ( tokens ) . collect ( Collectors . toMap ( Function . identity ( ) , this :: load , ( o , n ) -> o ) ) ; sql = StrSubstitutor . replace ( sql , values ) ; } return sql ; } catch ( Exception e ) { throw new IllegalStateException ( "Could not load query " + scriptsFolder + queryName , e ) ; } }
Loads the query from the informed path and adds to cache