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;
|
return false;
|
||||||
|
|
||||||
// for schema.element, just check schema->elementSet
|
// for schema.element, just check schema->elementSet
|
||||||
|
if (!isInitialized())
|
||||||
|
{
|
||||||
init();
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
if (qualifier == null)
|
if (qualifier == null)
|
||||||
{
|
{
|
||||||
Set<String> elts = hiddenElementSets.get(schema);
|
Set<String> elts = hiddenElementSets.get(schema);
|
||||||
@@ -121,10 +125,15 @@ public class MetadataExposure
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load maps from configuration unless it's already done.
|
private static boolean isInitialized()
|
||||||
private static void init()
|
|
||||||
{
|
{
|
||||||
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>>();
|
hiddenElementSets = new HashMap<String,Set<String>>();
|
||||||
hiddenElementMaps = new HashMap<String,Map<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)
|
public static MetadataField find(Context context, int id)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
|
{
|
||||||
|
if (!isCacheInitialized())
|
||||||
{
|
{
|
||||||
initCache(context);
|
initCache(context);
|
||||||
|
}
|
||||||
|
|
||||||
// 'sanity check' first.
|
// 'sanity check' first.
|
||||||
Integer iid = new Integer(id);
|
Integer iid = new Integer(id);
|
||||||
@@ -636,15 +639,15 @@ public class MetadataField
|
|||||||
id2field = null;
|
id2field = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load caches if necessary
|
private static boolean isCacheInitialized()
|
||||||
private static void initCache(Context context) throws SQLException
|
|
||||||
{
|
{
|
||||||
if (id2field != null)
|
return id2field != null;
|
||||||
return;
|
}
|
||||||
|
|
||||||
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();
|
HashMap new_id2field = new HashMap();
|
||||||
log.info("Loading MetadataField elements into cache.");
|
log.info("Loading MetadataField elements into cache.");
|
||||||
@@ -672,7 +675,6 @@ public class MetadataField
|
|||||||
id2field = new_id2field;
|
id2field = new_id2field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return <code>true</code> if <code>other</code> is the same MetadataField
|
* 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)
|
public static MetadataSchema find(Context context, int id)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
|
{
|
||||||
|
if (!isCacheInitialized())
|
||||||
{
|
{
|
||||||
initCache(context);
|
initCache(context);
|
||||||
|
}
|
||||||
|
|
||||||
Integer iid = new Integer(id);
|
Integer iid = new Integer(id);
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
@@ -563,7 +567,10 @@ public class MetadataSchema
|
|||||||
if (shortName == null)
|
if (shortName == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
if (!isCacheInitialized())
|
||||||
|
{
|
||||||
initCache(context);
|
initCache(context);
|
||||||
|
}
|
||||||
|
|
||||||
if (!name2schema.containsKey(shortName))
|
if (!name2schema.containsKey(shortName))
|
||||||
return null;
|
return null;
|
||||||
@@ -578,15 +585,15 @@ public class MetadataSchema
|
|||||||
name2schema = null;
|
name2schema = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load caches if necessary
|
private static boolean isCacheInitialized()
|
||||||
private static void initCache(Context context) throws SQLException
|
|
||||||
{
|
{
|
||||||
if (id2schema != null && name2schema != null)
|
return (id2schema != null && name2schema != null);
|
||||||
return;
|
}
|
||||||
|
|
||||||
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");
|
log.info("Loading schema cache for fast finds");
|
||||||
HashMap new_id2schema = new HashMap();
|
HashMap new_id2schema = new HashMap();
|
||||||
@@ -618,4 +625,3 @@ public class MetadataSchema
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@@ -98,7 +98,10 @@ public class DCInputAuthority extends SelfNamedPlugin implements ChoiceAuthority
|
|||||||
List<String> names = new ArrayList<String>();
|
List<String> names = new ArrayList<String>();
|
||||||
Iterator pi = dci.getPairsNameIterator();
|
Iterator pi = dci.getPairsNameIterator();
|
||||||
while (pi.hasNext())
|
while (pi.hasNext())
|
||||||
|
{
|
||||||
names.add((String)pi.next());
|
names.add((String)pi.next());
|
||||||
|
}
|
||||||
|
|
||||||
pluginNames = names.toArray(new String[names.size()]);
|
pluginNames = names.toArray(new String[names.size()]);
|
||||||
log.debug("Got plugin names = "+Arrays.deepToString(pluginNames));
|
log.debug("Got plugin names = "+Arrays.deepToString(pluginNames));
|
||||||
}
|
}
|
||||||
|
@@ -408,7 +408,7 @@ public class DSQuery
|
|||||||
/**
|
/**
|
||||||
* Close any IndexSearcher that is currently open.
|
* Close any IndexSearcher that is currently open.
|
||||||
*/
|
*/
|
||||||
public static void close()
|
public static synchronized void close()
|
||||||
{
|
{
|
||||||
if (searcher != null)
|
if (searcher != null)
|
||||||
{
|
{
|
||||||
|
@@ -44,6 +44,7 @@ import java.util.StringTokenizer;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,6 +55,8 @@ import org.dspace.core.ConfigurationManager;
|
|||||||
*/
|
*/
|
||||||
public class SortOption
|
public class SortOption
|
||||||
{
|
{
|
||||||
|
private static final Logger log = Logger.getLogger(SortOption.class);
|
||||||
|
|
||||||
public static final String ASCENDING = "ASC";
|
public static final String ASCENDING = "ASC";
|
||||||
public static final String DESCENDING = "DESC";
|
public static final String DESCENDING = "DESC";
|
||||||
|
|
||||||
@@ -77,8 +80,27 @@ public class SortOption
|
|||||||
|
|
||||||
/** the sort options available for this index */
|
/** the sort options available for this index */
|
||||||
private static Set<SortOption> sortOptionsSet = null;
|
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
|
* Construct a new SortOption object with the given parameters
|
||||||
*
|
*
|
||||||
@@ -297,58 +319,16 @@ public class SortOption
|
|||||||
return false;
|
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 all the configured sort options
|
||||||
* @return
|
* @return
|
||||||
* @throws SortException
|
* @throws SortException
|
||||||
*/
|
*/
|
||||||
public static Set<SortOption> getSortOptions() throws SortException
|
public static Set<SortOption> getSortOptions() throws SortException
|
||||||
{
|
|
||||||
if (SortOption.sortOptionsSet != null)
|
|
||||||
return SortOption.sortOptionsSet;
|
|
||||||
|
|
||||||
synchronized (SortOption.class)
|
|
||||||
{
|
{
|
||||||
if (SortOption.sortOptionsSet == null)
|
if (SortOption.sortOptionsSet == null)
|
||||||
{
|
{
|
||||||
Set<SortOption> newSortOptionsSet = new HashSet<SortOption>();
|
throw new SortException("Sort options not loaded");
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SortOption.sortOptionsSet;
|
return SortOption.sortOptionsSet;
|
||||||
|
Reference in New Issue
Block a user