Search code examples
javajodd

What is the use of queryMap in Jodd?


Recently, I found a class name like QueryMap in Jodd. What is the use of this class? Is it an internal class of Jodd framework, or is it a utility for use?


Solution

  • Welcome to un-documented feature :) Take a look at the DbHsqldbTestCase. There you can see how it is used:

    DbManager.getInstance().setQueryMap(new DbPropsQueryMap());
    

    DbPropsQueryMap is default implementation of a QueryMap. Its purpose is to load ALL *.sql.props and *.oom.props files from the resources and store the values. Look in the same test, there is a file called queries.sql.props.

    These props files are used for named queries. If you dont want to hardcode your query in the code, just put it in some props file.

    Then all you have to do is to use the key of the query (from the props file) like this:

    DbQuery query = new DbQuery(session, "myQuery");
    

    Or any other way you are creating the DbQuery - just use the key name instead of the whole query. That is all :)