1 61 62 package org.apache.commons.dbutils; 63 64 import java.io.IOException ; 65 import java.io.InputStream ; 66 import java.util.HashMap ; 67 import java.util.Map ; 68 import java.util.Properties ; 69 70 78 public class QueryLoader { 79 80 83 private static final QueryLoader instance = new QueryLoader(); 84 85 89 public static QueryLoader instance() { 90 return instance; 91 } 92 93 96 private Map queries = new HashMap (); 97 98 101 protected QueryLoader() { 102 super(); 103 } 104 105 118 public synchronized Map load(String path) throws IOException { 119 120 Map queryMap = (Map ) this.queries.get(path); 121 122 if (queryMap == null) { 123 queryMap = this.loadQueries(path); 124 this.queries.put(path, queryMap); 125 } 126 127 return queryMap; 128 } 129 130 135 private Map loadQueries(String path) throws IOException { 136 InputStream in = QueryLoader.class.getResourceAsStream(path); 137 138 if (in == null) { 139 throw new IllegalArgumentException (path + " not found."); 140 } 141 142 Properties props = new Properties (); 143 props.load(in); 144 145 return new HashMap (props); 147 } 148 149 153 public synchronized void unload(String path){ 154 this.queries.remove(path); 155 } 156 157 } 158 | Popular Tags |