Package org.apache.commons.dbutils
Class QueryLoader
- java.lang.Object
-
- org.apache.commons.dbutils.QueryLoader
-
public class QueryLoader extends java.lang.Object
QueryLoader
is a registry for sets of queries so that multiple copies of the same queries aren't loaded into memory. This implementation loads properties files filled with query name to SQL mappings. This class is thread safe.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.Pattern
dotXml
Matches .xml file extensions.private static QueryLoader
instance
The Singleton instance of this class.private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>
queries
Maps query set names to Maps of their queries.
-
Constructor Summary
Constructors Modifier Constructor Description protected
QueryLoader()
QueryLoader constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static QueryLoader
instance()
Return an instance of this class.java.util.Map<java.lang.String,java.lang.String>
load(java.lang.String path)
Loads a Map of query names to SQL values.protected java.util.Map<java.lang.String,java.lang.String>
loadQueries(java.lang.String path)
Loads a set of named queries into a Map object.void
unload(java.lang.String path)
Removes the queries for the given path from the cache.
-
-
-
Field Detail
-
instance
private static final QueryLoader instance
The Singleton instance of this class.
-
dotXml
private static final java.util.regex.Pattern dotXml
Matches .xml file extensions.
-
queries
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> queries
Maps query set names to Maps of their queries.
-
-
Method Detail
-
instance
public static QueryLoader instance()
Return an instance of this class.- Returns:
- The Singleton instance.
-
load
public java.util.Map<java.lang.String,java.lang.String> load(java.lang.String path) throws java.io.IOException
Loads a Map of query names to SQL values. The Maps are cached so a subsequent request to load queries from the same path will return the cached Map. The properties file to load can be in either line-oriented or XML format. XML formatted properties files must use a.xml
file extension.- Parameters:
path
- The path that the ClassLoader will use to find the file. This is not a file system path. If you had a jarred Queries.properties file in the com.yourcorp.app.jdbc package you would pass "/com/yourcorp/app/jdbc/Queries.properties" to this method.- Returns:
- Map of query names to SQL values
- Throws:
java.io.IOException
- if a file access error occursjava.lang.IllegalArgumentException
- if the ClassLoader can't find a file at the given path.java.util.InvalidPropertiesFormatException
- if the XML properties file is invalid- See Also:
Properties
-
loadQueries
protected java.util.Map<java.lang.String,java.lang.String> loadQueries(java.lang.String path) throws java.io.IOException
Loads a set of named queries into a Map object. This implementation reads a properties file at the given path. The properties file can be in either line-oriented or XML format. XML formatted properties files must use a.xml
file extension.- Parameters:
path
- The path that the ClassLoader will use to find the file.- Returns:
- Map of query names to SQL values
- Throws:
java.io.IOException
- if a file access error occursjava.lang.IllegalArgumentException
- if the ClassLoader can't find a file at the given path.java.util.InvalidPropertiesFormatException
- if the XML properties file is invalid- Since:
- DbUtils 1.1
- See Also:
Properties
-
unload
public void unload(java.lang.String path)
Removes the queries for the given path from the cache.- Parameters:
path
- The path that the queries were loaded from.
-
-