commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wspe...@apache.org
Subject svn commit: r1482047 - in /commons/proper/dbutils/trunk/src: changes/changes.xml main/java/org/apache/commons/dbutils/QueryLoader.java
Date Mon, 13 May 2013 19:45:21 GMT
Author: wspeirs
Date: Mon May 13 19:45:20 2013
New Revision: 1482047

URL: http://svn.apache.org/r1482047
Log:
Applied patch from DBUTILS-107 and updated changes.xml file

Modified:
    commons/proper/dbutils/trunk/src/changes/changes.xml
    commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/QueryLoader.java

Modified: commons/proper/dbutils/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/changes/changes.xml?rev=1482047&r1=1482046&r2=1482047&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbutils/trunk/src/changes/changes.xml Mon May 13 19:45:20 2013
@@ -47,6 +47,9 @@ The <action> type attribute can be add,u
       <action dev="wspeirs" due-to="Micah Huff" type="add" issue="DBUTILS-108">
         Create functionality to return auto-generated keys in batches of SQL inserts
       </action>
+      <action dev="wspeirs" due-to="PB" type="add" issue="DBUTILS-107">
+        Patch QueryLoader to also load from XML properties files
+      </action>
       <action dev="simonetripodi" due-to="Moandji Ezana" type="add" issue="DBUTILS-98">
         Add missing JavaDoc to QueryRunner#insert
       </action>

Modified: commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/QueryLoader.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/QueryLoader.java?rev=1482047&r1=1482046&r2=1482047&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/QueryLoader.java
(original)
+++ commons/proper/dbutils/trunk/src/main/java/org/apache/commons/dbutils/QueryLoader.java
Mon May 13 19:45:20 2013
@@ -19,8 +19,10 @@ package org.apache.commons.dbutils;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
+import java.util.InvalidPropertiesFormatException;
 import java.util.Map;
 import java.util.Properties;
+import java.util.regex.Pattern;
 
 /**
  * <code>QueryLoader</code> is a registry for sets of queries so
@@ -36,6 +38,11 @@ public class QueryLoader {
     private static final QueryLoader instance = new QueryLoader();
 
     /**
+     * Matches .xml file extensions.
+     */
+    private static final Pattern dotXml = Pattern.compile(".+\\.[xX][mM][lL]");
+
+    /**
      * Return an instance of this class.
      * @return The Singleton instance.
      */
@@ -58,7 +65,9 @@ public class QueryLoader {
     /**
      * 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 cached Map.  The properties file to load can be in either
+     * line-oriented or XML format.  XML formatted properties files must use a
+     * <code>.xml</code> file extension.
      *
      * @param path The path that the ClassLoader will use to find the file.
      * This is <strong>not</strong> a file system path.  If you had a jarred
@@ -67,7 +76,10 @@ public class QueryLoader {
      * @throws IOException if a file access error occurs
      * @throws IllegalArgumentException if the ClassLoader can't find a file at
      * the given path.
+     * @throws InvalidPropertiesFormatException if the XML properties file is
+     * invalid
      * @return Map of query names to SQL values
+     * @see java.util.Properties
      */
     public synchronized Map<String, String> load(String path) throws IOException {
 
@@ -83,13 +95,19 @@ public class QueryLoader {
 
     /**
      * Loads a set of named queries into a Map object.  This implementation
-     * reads a properties file at the given path.
+     * 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 <code>.xml</code> file extension.
+
      * @param path The path that the ClassLoader will use to find the file.
      * @throws IOException if a file access error occurs
      * @throws IllegalArgumentException if the ClassLoader can't find a file at
      * the given path.
+     * @throws InvalidPropertiesFormatException if the XML properties file is
+     * invalid
      * @since DbUtils 1.1
      * @return Map of query names to SQL values
+     * @see java.util.Properties
      */
     protected Map<String, String> loadQueries(String path) throws IOException {
         // Findbugs flags getClass().getResource as a bad practice; maybe we should change
the API?
@@ -101,7 +119,11 @@ public class QueryLoader {
 
         Properties props = new Properties();
         try {
-            props.load(in);
+            if (dotXml.matcher(path).matches()) {
+                props.loadFromXML(in);
+            } else {
+                props.load(in);
+            }
         } finally {
             in.close();
         }



Mime
View raw message