Revision 3340
Added by Jing Tao over 17 years ago
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
79 | 79 |
|
80 | 80 |
/** useful if you just want to grab a list of docids **/ |
81 | 81 |
Vector docidOverride = new Vector(); |
82 |
|
|
83 |
// a hash table serves as query reuslt cache. Key of hashtable |
|
84 |
// is a query string and value is ResultDocumentSet Object |
|
85 |
private static Hashtable queryResultCache = new Hashtable(); |
|
86 |
|
|
87 |
// Capacity of the query result cache |
|
88 |
private static final int QUERYRESULTCACHESIZE = Integer.parseInt(MetaCatUtil.getOption("queryresult_cache_size")); |
|
82 | 89 |
|
83 | 90 |
/** |
84 | 91 |
* the main routine used to test the DBQuery utility. |
... | ... | |
385 | 392 |
Hashtable sessionHash = MetaCatServlet.getSessionHash(); |
386 | 393 |
HttpSession sess = (HttpSession)sessionHash.get(sessionid); |
387 | 394 |
|
388 |
QuerySpecification cachedQuerySpec = null; |
|
389 |
if (sess != null) |
|
390 |
{ |
|
391 |
cachedQuerySpec = (QuerySpecification)sess.getAttribute("query"); |
|
392 |
} |
|
393 | 395 |
|
396 |
|
|
394 | 397 |
resultset.append("<?xml version=\"1.0\"?>\n"); |
395 | 398 |
resultset.append("<resultset>\n"); |
396 | 399 |
resultset.append(" <pagestart>" + pagestart + "</pagestart>\n"); |
... | ... | |
1246 | 1249 |
return xmlquery; |
1247 | 1250 |
} |
1248 | 1251 |
} |
1252 |
|
|
1253 |
/* |
|
1254 |
* Method to store query string and DocumentResultSet into query result |
|
1255 |
* cache. If the size alreay reache the limitation, the cache will be |
|
1256 |
* cleared first, then store them. |
|
1257 |
*/ |
|
1258 |
private void storeQueryResultIntoCache(String query, ResultDocumentSet resultSet) |
|
1259 |
{ |
|
1260 |
synchronized (queryResultCache) |
|
1261 |
{ |
|
1262 |
if (queryResultCache.size() >= QUERYRESULTCACHESIZE) |
|
1263 |
{ |
|
1264 |
queryResultCache.clear(); |
|
1265 |
} |
|
1266 |
queryResultCache.put(query, resultSet); |
|
1267 |
|
|
1268 |
} |
|
1269 |
} |
|
1270 |
|
|
1271 |
/* |
|
1272 |
* Method to get DocumentResultSet from query result cache. |
|
1273 |
* Note: the returned ResultDoucmentSet can be null. |
|
1274 |
*/ |
|
1275 |
private ResultDocumentSet getResultDocumentSetFromCache(String query) |
|
1276 |
{ |
|
1277 |
ResultDocumentSet resultSet = null; |
|
1278 |
synchronized (queryResultCache) |
|
1279 |
{ |
|
1280 |
try |
|
1281 |
{ |
|
1282 |
resultSet = (ResultDocumentSet)queryResultCache.get(query); |
|
1283 |
|
|
1284 |
} |
|
1285 |
catch (Exception e) |
|
1286 |
{ |
|
1287 |
resultSet = null; |
|
1288 |
} |
|
1289 |
|
|
1290 |
} |
|
1291 |
return resultSet; |
|
1292 |
} |
|
1293 |
|
|
1294 |
/** |
|
1295 |
* Method to clear the query result cache. |
|
1296 |
*/ |
|
1297 |
public static void clearQueryResultCache() |
|
1298 |
{ |
|
1299 |
synchronized (queryResultCache) |
|
1300 |
{ |
|
1301 |
queryResultCache.clear(); |
|
1302 |
} |
|
1303 |
} |
|
1249 | 1304 |
|
1250 | 1305 |
|
1251 | 1306 |
/* |
Also available in: Unified diff
Add a result set cache