mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 12:33:18 +00:00
[DS-707] Fix multithreading issues
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5481 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -103,7 +103,11 @@ public class MetadataExposure
|
||||
return false;
|
||||
|
||||
// for schema.element, just check schema->elementSet
|
||||
if (!isInitialized())
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
if (qualifier == null)
|
||||
{
|
||||
Set<String> elts = hiddenElementSets.get(schema);
|
||||
@@ -121,10 +125,15 @@ public class MetadataExposure
|
||||
}
|
||||
}
|
||||
|
||||
// load maps from configuration unless it's already done.
|
||||
private static void init()
|
||||
private static boolean isInitialized()
|
||||
{
|
||||
if (hiddenElementSets == null)
|
||||
return hiddenElementSets != null;
|
||||
}
|
||||
|
||||
// load maps from configuration unless it's already done.
|
||||
private static synchronized void init()
|
||||
{
|
||||
if (!isInitialized())
|
||||
{
|
||||
hiddenElementSets = new HashMap<String,Set<String>>();
|
||||
hiddenElementMaps = new HashMap<String,Map<String,Set<String>>>();
|
||||
|
@@ -619,8 +619,11 @@ public class MetadataField
|
||||
*/
|
||||
public static MetadataField find(Context context, int id)
|
||||
throws SQLException
|
||||
{
|
||||
if (!isCacheInitialized())
|
||||
{
|
||||
initCache(context);
|
||||
}
|
||||
|
||||
// 'sanity check' first.
|
||||
Integer iid = new Integer(id);
|
||||
@@ -636,15 +639,15 @@ public class MetadataField
|
||||
id2field = null;
|
||||
}
|
||||
|
||||
// load caches if necessary
|
||||
private static void initCache(Context context) throws SQLException
|
||||
private static boolean isCacheInitialized()
|
||||
{
|
||||
if (id2field != null)
|
||||
return;
|
||||
return id2field != null;
|
||||
}
|
||||
|
||||
synchronized (MetadataField.class)
|
||||
// load caches if necessary
|
||||
private static synchronized void initCache(Context context) throws SQLException
|
||||
{
|
||||
if (id2field == null)
|
||||
if (!isCacheInitialized())
|
||||
{
|
||||
HashMap new_id2field = new HashMap();
|
||||
log.info("Loading MetadataField elements into cache.");
|
||||
@@ -672,7 +675,6 @@ public class MetadataField
|
||||
id2field = new_id2field;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return <code>true</code> if <code>other</code> is the same MetadataField
|
||||
|
@@ -535,8 +535,12 @@ public class MetadataSchema
|
||||
*/
|
||||
public static MetadataSchema find(Context context, int id)
|
||||
throws SQLException
|
||||
{
|
||||
if (!isCacheInitialized())
|
||||
{
|
||||
initCache(context);
|
||||
}
|
||||
|
||||
Integer iid = new Integer(id);
|
||||
|
||||
// sanity check
|
||||
@@ -563,7 +567,10 @@ public class MetadataSchema
|
||||
if (shortName == null)
|
||||
return null;
|
||||
|
||||
if (!isCacheInitialized())
|
||||
{
|
||||
initCache(context);
|
||||
}
|
||||
|
||||
if (!name2schema.containsKey(shortName))
|
||||
return null;
|
||||
@@ -578,15 +585,15 @@ public class MetadataSchema
|
||||
name2schema = null;
|
||||
}
|
||||
|
||||
// load caches if necessary
|
||||
private static void initCache(Context context) throws SQLException
|
||||
private static boolean isCacheInitialized()
|
||||
{
|
||||
if (id2schema != null && name2schema != null)
|
||||
return;
|
||||
return (id2schema != null && name2schema != null);
|
||||
}
|
||||
|
||||
synchronized (MetadataSchema.class)
|
||||
// load caches if necessary
|
||||
private static synchronized void initCache(Context context) throws SQLException
|
||||
{
|
||||
if (id2schema == null && name2schema == null)
|
||||
if (!isCacheInitialized())
|
||||
{
|
||||
log.info("Loading schema cache for fast finds");
|
||||
HashMap new_id2schema = new HashMap();
|
||||
@@ -617,5 +624,4 @@ public class MetadataSchema
|
||||
name2schema = new_name2schema;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -98,7 +98,10 @@ public class DCInputAuthority extends SelfNamedPlugin implements ChoiceAuthority
|
||||
List<String> names = new ArrayList<String>();
|
||||
Iterator pi = dci.getPairsNameIterator();
|
||||
while (pi.hasNext())
|
||||
{
|
||||
names.add((String)pi.next());
|
||||
}
|
||||
|
||||
pluginNames = names.toArray(new String[names.size()]);
|
||||
log.debug("Got plugin names = "+Arrays.deepToString(pluginNames));
|
||||
}
|
||||
|
@@ -408,7 +408,7 @@ public class DSQuery
|
||||
/**
|
||||
* Close any IndexSearcher that is currently open.
|
||||
*/
|
||||
public static void close()
|
||||
public static synchronized void close()
|
||||
{
|
||||
if (searcher != null)
|
||||
{
|
||||
|
@@ -44,6 +44,7 @@ import java.util.StringTokenizer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
|
||||
/**
|
||||
@@ -54,6 +55,8 @@ import org.dspace.core.ConfigurationManager;
|
||||
*/
|
||||
public class SortOption
|
||||
{
|
||||
private static final Logger log = Logger.getLogger(SortOption.class);
|
||||
|
||||
public static final String ASCENDING = "ASC";
|
||||
public static final String DESCENDING = "DESC";
|
||||
|
||||
@@ -77,8 +80,27 @@ public class SortOption
|
||||
|
||||
/** the sort options available for this index */
|
||||
private static Set<SortOption> sortOptionsSet = null;
|
||||
private static Map<Integer, SortOption> sortOptionsMap = null;
|
||||
static {
|
||||
try
|
||||
{
|
||||
Set<SortOption> newSortOptionsSet = new HashSet<SortOption>();
|
||||
int idx = 1;
|
||||
String option;
|
||||
|
||||
while ( ((option = ConfigurationManager.getProperty("webui.itemlist.sort-option." + idx))) != null)
|
||||
{
|
||||
SortOption so = new SortOption(idx, option);
|
||||
newSortOptionsSet.add(so);
|
||||
idx++;
|
||||
}
|
||||
|
||||
SortOption.sortOptionsSet = newSortOptionsSet;
|
||||
}
|
||||
catch (SortException se)
|
||||
{
|
||||
log.fatal("Unable to load SortOptions", se);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Construct a new SortOption object with the given parameters
|
||||
*
|
||||
@@ -297,58 +319,16 @@ public class SortOption
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map of the configured sort options
|
||||
*/
|
||||
public static Map<Integer, SortOption> getSortOptionsMap() throws SortException
|
||||
{
|
||||
if (SortOption.sortOptionsMap != null)
|
||||
return SortOption.sortOptionsMap;
|
||||
|
||||
synchronized (SortOption.class)
|
||||
{
|
||||
if (SortOption.sortOptionsMap == null)
|
||||
{
|
||||
Map<Integer, SortOption> newSortOptionsMap = new HashMap<Integer, SortOption>();
|
||||
for (SortOption so : SortOption.getSortOptions())
|
||||
{
|
||||
newSortOptionsMap.put(new Integer(so.getNumber()), so);
|
||||
}
|
||||
|
||||
SortOption.sortOptionsMap = newSortOptionsMap;
|
||||
}
|
||||
}
|
||||
|
||||
return SortOption.sortOptionsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the configured sort options
|
||||
* @return
|
||||
* @throws SortException
|
||||
*/
|
||||
public static Set<SortOption> getSortOptions() throws SortException
|
||||
{
|
||||
if (SortOption.sortOptionsSet != null)
|
||||
return SortOption.sortOptionsSet;
|
||||
|
||||
synchronized (SortOption.class)
|
||||
{
|
||||
if (SortOption.sortOptionsSet == null)
|
||||
{
|
||||
Set<SortOption> newSortOptionsSet = new HashSet<SortOption>();
|
||||
int idx = 1;
|
||||
String option;
|
||||
|
||||
while ( ((option = ConfigurationManager.getProperty("webui.itemlist.sort-option." + idx))) != null)
|
||||
{
|
||||
SortOption so = new SortOption(idx, option);
|
||||
newSortOptionsSet.add(so);
|
||||
idx++;
|
||||
}
|
||||
|
||||
SortOption.sortOptionsSet = newSortOptionsSet;
|
||||
}
|
||||
throw new SortException("Sort options not loaded");
|
||||
}
|
||||
|
||||
return SortOption.sortOptionsSet;
|
||||
|
Reference in New Issue
Block a user