mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 22:13:08 +00:00
[DS-707] Inefficient use of keySet iterators
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5474 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -103,7 +103,7 @@ public interface BrowseCreateDAO
|
|||||||
* @param sortCols an Integer-String map of sort column numbers and values
|
* @param sortCols an Integer-String map of sort column numbers and values
|
||||||
* @throws BrowseException
|
* @throws BrowseException
|
||||||
*/
|
*/
|
||||||
public void insertIndex(String table, int itemID, Map sortCols) throws BrowseException;
|
public void insertIndex(String table, int itemID, Map<Integer, String> sortCols) throws BrowseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates an index record into the given table for the given item id. The Map should contain
|
* Updates an index record into the given table for the given item id. The Map should contain
|
||||||
@@ -127,7 +127,7 @@ public interface BrowseCreateDAO
|
|||||||
* @return true if the record is updated, false if not found
|
* @return true if the record is updated, false if not found
|
||||||
* @throws BrowseException
|
* @throws BrowseException
|
||||||
*/
|
*/
|
||||||
public boolean updateIndex(String table, int itemID, Map sortCols) throws BrowseException;
|
public boolean updateIndex(String table, int itemID, Map<Integer, String> sortCols) throws BrowseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the browse index's internal id for the location of the given string
|
* Get the browse index's internal id for the location of the given string
|
||||||
|
@@ -688,7 +688,7 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertIndex(String table, int itemID, Map sortCols)
|
public void insertIndex(String table, int itemID, Map<Integer, String> sortCols)
|
||||||
throws BrowseException
|
throws BrowseException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -700,12 +700,9 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
|
|||||||
row.setColumn("item_id", itemID);
|
row.setColumn("item_id", itemID);
|
||||||
|
|
||||||
// now set the columns for the other sort values
|
// now set the columns for the other sort values
|
||||||
Iterator itra = sortCols.keySet().iterator();
|
for (Map.Entry<Integer, String> sortCol : sortCols.entrySet())
|
||||||
while (itra.hasNext())
|
|
||||||
{
|
{
|
||||||
Integer key = (Integer) itra.next();
|
row.setColumn("sort_" + sortCol.getKey().toString(), utils.truncateSortValue(sortCol.getValue()));
|
||||||
String nValue = (String) sortCols.get(key);
|
|
||||||
row.setColumn("sort_" + key.toString(), utils.truncateSortValue(nValue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseManager.update(context, row);
|
DatabaseManager.update(context, row);
|
||||||
@@ -720,7 +717,7 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.dspace.browse.BrowseCreateDAO#updateIndex(java.lang.String, int, java.util.Map)
|
* @see org.dspace.browse.BrowseCreateDAO#updateIndex(java.lang.String, int, java.util.Map)
|
||||||
*/
|
*/
|
||||||
public boolean updateIndex(String table, int itemID, Map sortCols)
|
public boolean updateIndex(String table, int itemID, Map<Integer, String> sortCols)
|
||||||
throws BrowseException
|
throws BrowseException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -733,16 +730,13 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Iterate through all the sort values
|
// Iterate through all the sort values
|
||||||
Iterator itra = sortCols.keySet().iterator();
|
for (Map.Entry<Integer, String> sortCol : sortCols.entrySet())
|
||||||
while (itra.hasNext())
|
|
||||||
{
|
{
|
||||||
Integer key = (Integer) itra.next();
|
|
||||||
|
|
||||||
// Generate the appropriate column name
|
// Generate the appropriate column name
|
||||||
String column = "sort_" + key.toString();
|
String column = "sort_" + sortCol.getKey().toString();
|
||||||
|
|
||||||
// Create the value that will be written in to the column
|
// Create the value that will be written in to the column
|
||||||
String newValue = utils.truncateSortValue( (String) sortCols.get(key) );
|
String newValue = utils.truncateSortValue( sortCol.getValue() );
|
||||||
|
|
||||||
// Check the column exists - if it doesn't, something has gone seriously wrong
|
// Check the column exists - if it doesn't, something has gone seriously wrong
|
||||||
if (!row.hasColumn(column))
|
if (!row.hasColumn(column))
|
||||||
|
@@ -695,7 +695,7 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.dspace.browse.BrowseCreateDAO#insertIndex(java.lang.String, int, java.lang.String, java.lang.String, java.util.Map)
|
* @see org.dspace.browse.BrowseCreateDAO#insertIndex(java.lang.String, int, java.lang.String, java.lang.String, java.util.Map)
|
||||||
*/
|
*/
|
||||||
public void insertIndex(String table, int itemID, Map sortCols)
|
public void insertIndex(String table, int itemID, Map<Integer, String> sortCols)
|
||||||
throws BrowseException
|
throws BrowseException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -707,12 +707,9 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
|
|||||||
row.setColumn("item_id", itemID);
|
row.setColumn("item_id", itemID);
|
||||||
|
|
||||||
// now set the columns for the other sort values
|
// now set the columns for the other sort values
|
||||||
Iterator itra = sortCols.keySet().iterator();
|
for (Map.Entry<Integer, String> sortCol : sortCols.entrySet())
|
||||||
while (itra.hasNext())
|
|
||||||
{
|
{
|
||||||
Integer key = (Integer) itra.next();
|
row.setColumn("sort_" + sortCol.getKey().toString(), utils.truncateSortValue(sortCol.getValue()));
|
||||||
String nValue = (String) sortCols.get(key);
|
|
||||||
row.setColumn("sort_" + key.toString(), utils.truncateSortValue(nValue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseManager.update(context, row);
|
DatabaseManager.update(context, row);
|
||||||
@@ -727,7 +724,7 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.dspace.browse.BrowseCreateDAO#updateIndex(java.lang.String, int, java.util.Map)
|
* @see org.dspace.browse.BrowseCreateDAO#updateIndex(java.lang.String, int, java.util.Map)
|
||||||
*/
|
*/
|
||||||
public boolean updateIndex(String table, int itemID, Map sortCols)
|
public boolean updateIndex(String table, int itemID, Map<Integer, String> sortCols)
|
||||||
throws BrowseException
|
throws BrowseException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -740,16 +737,13 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Iterate through all the sort values
|
// Iterate through all the sort values
|
||||||
Iterator itra = sortCols.keySet().iterator();
|
for (Map.Entry<Integer, String> sortCol : sortCols.entrySet())
|
||||||
while (itra.hasNext())
|
|
||||||
{
|
{
|
||||||
Integer key = (Integer) itra.next();
|
|
||||||
|
|
||||||
// Generate the appropriate column name
|
// Generate the appropriate column name
|
||||||
String column = "sort_" + key.toString();
|
String column = "sort_" + sortCol.getKey().toString();
|
||||||
|
|
||||||
// Create the value that will be written in to the column
|
// Create the value that will be written in to the column
|
||||||
String newValue = utils.truncateSortValue( (String) sortCols.get(key) );
|
String newValue = utils.truncateSortValue( sortCol.getValue() );
|
||||||
|
|
||||||
// Check the column exists - if it doesn't, something has gone seriously wrong
|
// Check the column exists - if it doesn't, something has gone seriously wrong
|
||||||
if (!row.hasColumn(column))
|
if (!row.hasColumn(column))
|
||||||
|
@@ -270,7 +270,7 @@ public class ChecksumHistoryDAO extends DAOSupport
|
|||||||
*
|
*
|
||||||
* @return number of bitstreams deleted
|
* @return number of bitstreams deleted
|
||||||
*/
|
*/
|
||||||
public int prune(Map interests)
|
public int prune(Map<String, Long> interests)
|
||||||
{
|
{
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try
|
try
|
||||||
@@ -278,12 +278,10 @@ public class ChecksumHistoryDAO extends DAOSupport
|
|||||||
conn = DatabaseManager.getConnection();
|
conn = DatabaseManager.getConnection();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Iterator iter = interests.keySet().iterator(); iter.hasNext();)
|
for (Map.Entry<String, Long> interest : interests.entrySet())
|
||||||
{
|
{
|
||||||
String result = (String) iter.next();
|
|
||||||
Long dur = (Long) interests.get(result);
|
|
||||||
count += deleteHistoryByDateAndCode(new Date(now
|
count += deleteHistoryByDateAndCode(new Date(now
|
||||||
- dur.longValue()), result, conn);
|
- interest.getValue().longValue()), interest.getKey(), conn);
|
||||||
conn.commit();
|
conn.commit();
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
@@ -180,7 +180,7 @@ public final class ResultsPruner
|
|||||||
/**
|
/**
|
||||||
* Map of retention durations, keyed by result code name
|
* Map of retention durations, keyed by result code name
|
||||||
*/
|
*/
|
||||||
Map interests = new HashMap();
|
Map<String, Long> interests = new HashMap<String, Long>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checksum results database Data access
|
* Checksum results database Data access
|
||||||
|
@@ -70,11 +70,10 @@ public class LicenseUtils
|
|||||||
|
|
||||||
if (additionalInfo != null)
|
if (additionalInfo != null)
|
||||||
{
|
{
|
||||||
int i = 1;
|
int i = 7; // Start is next index after previous args
|
||||||
for (String key : additionalInfo.keySet())
|
for (Map.Entry<String, Object> info : additionalInfo.entrySet())
|
||||||
{
|
{
|
||||||
args[6 + i] = new FormattableArgument(key, additionalInfo
|
args[i] = new FormattableArgument(info.getKey(), info.getValue());
|
||||||
.get(key));
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1255,23 +1255,10 @@ public class Group extends DSpaceObject
|
|||||||
// so now to establish all parent,child relationships we can iterate
|
// so now to establish all parent,child relationships we can iterate
|
||||||
// through the parents hash
|
// through the parents hash
|
||||||
|
|
||||||
Iterator<Integer> i = parents.keySet().iterator();
|
for (Map.Entry<Integer, Set<Integer>> parent : parents.entrySet())
|
||||||
|
|
||||||
while (i.hasNext())
|
|
||||||
{
|
{
|
||||||
Integer parentID = i.next();
|
Set<Integer> myChildren = getChildren(parents, parent.getKey());
|
||||||
|
parent.getValue().addAll(myChildren);
|
||||||
Set<Integer> myChildren = getChildren(parents, parentID);
|
|
||||||
|
|
||||||
Iterator<Integer> j = myChildren.iterator();
|
|
||||||
|
|
||||||
while (j.hasNext())
|
|
||||||
{
|
|
||||||
// child of a parent
|
|
||||||
Integer childID = j.next();
|
|
||||||
|
|
||||||
((Set<Integer>) parents.get(parentID)).add(childID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// empty out group2groupcache table
|
// empty out group2groupcache table
|
||||||
|
@@ -44,6 +44,7 @@ import java.net.URLEncoder;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@@ -342,33 +343,30 @@ public class QueryArgs
|
|||||||
*
|
*
|
||||||
* @return the created HashMap
|
* @return the created HashMap
|
||||||
*/
|
*/
|
||||||
public HashMap buildQueryHash(HttpServletRequest request)
|
public Map<String, String> buildQueryMap(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
HashMap queryHash = new HashMap();
|
Map<String, String> queryMap = new HashMap<String, String>();
|
||||||
String numFieldStr = request.getParameter("num_search_field");
|
String numFieldStr = request.getParameter("num_search_field");
|
||||||
// for backward compatibility
|
// for backward compatibility
|
||||||
if (numFieldStr == null) numFieldStr = "3";
|
if (numFieldStr == null) numFieldStr = "3";
|
||||||
int numField = Integer.parseInt(numFieldStr);
|
int numField = Integer.parseInt(numFieldStr);
|
||||||
for (int i = 1; i < numField; i++)
|
for (int i = 1; i < numField; i++)
|
||||||
{
|
{
|
||||||
queryHash.put("query"+i, (request.getParameter("query"+i) == null) ? ""
|
String queryStr = "query" + i;
|
||||||
: request.getParameter("query"+i));
|
String fieldStr = "field" + i;
|
||||||
queryHash.put("field"+i,
|
String conjunctionStr = "conjunction" + i;
|
||||||
(request.getParameter("field"+i) == null) ? "ANY" : request
|
|
||||||
.getParameter("field"+i));
|
queryMap.put(queryStr, StringUtils.defaultString(request.getParameter(queryStr), ""));
|
||||||
queryHash.put("conjunction"+i,
|
queryMap.put(fieldStr, StringUtils.defaultString(request.getParameter(fieldStr), "ANY"));
|
||||||
(request.getParameter("conjunction"+i) == null) ? "AND"
|
queryMap.put(conjunctionStr, StringUtils.defaultString(request.getParameter(conjunctionStr), "AND"));
|
||||||
: request.getParameter("conjunction"+i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
queryHash.put("query"+numField, (request.getParameter("query"+numField) == null) ? ""
|
String queryStr = "query" + numField;
|
||||||
: request.getParameter("query"+numField));
|
String fieldStr = "field" + numField;
|
||||||
|
queryMap.put(queryStr, StringUtils.defaultString(request.getParameter(queryStr), ""));
|
||||||
|
queryMap.put(fieldStr, StringUtils.defaultString(request.getParameter(fieldStr), "ANY"));
|
||||||
|
|
||||||
queryHash.put("field"+numField,
|
return (queryMap);
|
||||||
(request.getParameter("field"+numField) == null) ? "ANY"
|
|
||||||
: request.getParameter("field"+numField));
|
|
||||||
|
|
||||||
return (queryHash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -396,25 +394,23 @@ public class QueryArgs
|
|||||||
public String buildHTTPQuery(HttpServletRequest request)
|
public String buildHTTPQuery(HttpServletRequest request)
|
||||||
throws UnsupportedEncodingException
|
throws UnsupportedEncodingException
|
||||||
{
|
{
|
||||||
String querystring = "";
|
StringBuilder queryString = new StringBuilder();
|
||||||
HashMap queryHash = buildQueryHash(request);
|
Map<String, String> queryMap = buildQueryMap(request);
|
||||||
|
|
||||||
Iterator i = queryHash.keySet().iterator();
|
for (Map.Entry<String, String> query : queryMap.entrySet())
|
||||||
|
|
||||||
while (i.hasNext())
|
|
||||||
{
|
{
|
||||||
String key = (String) i.next();
|
queryString.append("&")
|
||||||
String value = (String) queryHash.get(key);
|
.append(query.getKey())
|
||||||
|
.append("=")
|
||||||
querystring = querystring + "&" + key + "="
|
.append(URLEncoder.encode(query.getValue(), Constants.DEFAULT_ENCODING));
|
||||||
+ URLEncoder.encode(value, Constants.DEFAULT_ENCODING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.getParameter("num_search_field") != null)
|
if (request.getParameter("num_search_field") != null)
|
||||||
{
|
{
|
||||||
querystring = querystring + "&num_search_field="+request.getParameter("num_search_field");
|
queryString.append("&num_search_field=").append(request.getParameter("num_search_field"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the result with the leading "&" removed
|
// return the result with the leading "&" removed
|
||||||
return (querystring.substring(1));
|
return queryString.substring(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -259,7 +259,7 @@ public class MARC21InitialArticleWord extends InitialArticleWord
|
|||||||
|
|
||||||
// Iterate through word/language array
|
// Iterate through word/language array
|
||||||
// Generate temporary language map
|
// Generate temporary language map
|
||||||
Map langWordMap = new HashMap();
|
Map<Language, List> langWordMap = new HashMap<Language, List>();
|
||||||
for (wordIdx = 0; wordIdx < articleWordArray.length; wordIdx++)
|
for (wordIdx = 0; wordIdx < articleWordArray.length; wordIdx++)
|
||||||
{
|
{
|
||||||
for (langIdx = 1; langIdx < articleWordArray[wordIdx].length; langIdx++)
|
for (langIdx = 1; langIdx < articleWordArray[wordIdx].length; langIdx++)
|
||||||
@@ -268,7 +268,7 @@ public class MARC21InitialArticleWord extends InitialArticleWord
|
|||||||
|
|
||||||
if (lang != null && lang.IANA.length() > 0)
|
if (lang != null && lang.IANA.length() > 0)
|
||||||
{
|
{
|
||||||
List words = (List)langWordMap.get(lang);
|
List words = langWordMap.get(lang);
|
||||||
|
|
||||||
if (words == null)
|
if (words == null)
|
||||||
{
|
{
|
||||||
@@ -284,11 +284,10 @@ public class MARC21InitialArticleWord extends InitialArticleWord
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through languages
|
// Iterate through languages
|
||||||
Iterator langIter = langWordMap.keySet().iterator();
|
for (Map.Entry<Language, List> langToWord : langWordMap.entrySet())
|
||||||
while (langIter.hasNext())
|
|
||||||
{
|
{
|
||||||
Language lang = (Language)langIter.next();
|
Language lang = langToWord.getKey();
|
||||||
List wordList = (List)langWordMap.get(lang);
|
List wordList = langToWord.getValue();
|
||||||
|
|
||||||
// Convert the list into an array of strings
|
// Convert the list into an array of strings
|
||||||
String[] words = new String[wordList.size()];
|
String[] words = new String[wordList.size()];
|
||||||
|
@@ -46,7 +46,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -71,7 +71,6 @@ import org.dspace.search.DSQuery;
|
|||||||
import org.dspace.search.QueryArgs;
|
import org.dspace.search.QueryArgs;
|
||||||
import org.dspace.search.QueryResults;
|
import org.dspace.search.QueryResults;
|
||||||
import org.dspace.sort.SortOption;
|
import org.dspace.sort.SortOption;
|
||||||
import org.dspace.browse.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Servlet for handling a simple search.
|
* Servlet for handling a simple search.
|
||||||
@@ -108,7 +107,7 @@ public class SimpleSearchServlet extends DSpaceServlet
|
|||||||
String order = request.getParameter("order");
|
String order = request.getParameter("order");
|
||||||
int rpp = UIUtil.getIntParameter(request, "rpp");
|
int rpp = UIUtil.getIntParameter(request, "rpp");
|
||||||
String advancedQuery = "";
|
String advancedQuery = "";
|
||||||
HashMap queryHash = new HashMap();
|
Map<String, String> queryHash = new HashMap<String, String>();
|
||||||
|
|
||||||
// can't start earlier than 0 in the results!
|
// can't start earlier than 0 in the results!
|
||||||
if (start < 0)
|
if (start < 0)
|
||||||
@@ -402,7 +401,7 @@ public class SimpleSearchServlet extends DSpaceServlet
|
|||||||
request.setAttribute("communities", communities);
|
request.setAttribute("communities", communities);
|
||||||
request.setAttribute("no_results", "yes");
|
request.setAttribute("no_results", "yes");
|
||||||
|
|
||||||
queryHash = qArgs.buildQueryHash(request);
|
queryHash = qArgs.buildQueryMap(request);
|
||||||
|
|
||||||
Iterator i = queryHash.keySet().iterator();
|
Iterator i = queryHash.keySet().iterator();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user