Fix problem searching by author in item mapping. Remove even more database contention (when editing / mapping items)

git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@2631 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Graham Triggs
2008-02-10 20:46:27 +00:00
parent be03336a63
commit 4fe54b6079
7 changed files with 108 additions and 19 deletions

View File

@@ -81,8 +81,8 @@ public interface BrowseCreateDAO
public void deleteByItemID(String table, int itemID) throws BrowseException;
public void deleteCommunityMappings(int itemID) throws BrowseException;
public void insertCommunityMappings(int itemID) throws BrowseException;
public void updateCommunityMappings(int itemID) throws BrowseException;
/**
* Insert an index record into the given table for the given item id. The Map should contain

View File

@@ -534,17 +534,54 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseCreateDAO#insertCommunityMappings(java.lang.String, java.lang.String, java.lang.String)
* @see org.dspace.browse.BrowseCreateDAO#updateCommunityMappings(int)
*/
public void insertCommunityMappings(int itemID) throws BrowseException
public void updateCommunityMappings(int itemID) throws BrowseException
{
try
{
// Get all the communities for this item
int[] commID = getAllCommunityIDs(itemID);
// Remove (set to -1) any duplicate communities
for (int i = 0; i < commID.length; i++)
{
if (isFirstOccurrence(commID, i))
if (!isFirstOccurrence(commID, i))
commID[i] = -1;
}
// Find all existing mappings for this item
TableRowIterator tri = DatabaseManager.queryTable(context, "Communities2Item", "SELECT * FROM Communities2Item WHERE item_id=?", itemID);
if (tri != null)
{
while (tri.hasNext())
{
TableRow tr = tri.next();
// Check the item mappings to see if it contains this community mapping
boolean itemIsMapped = false;
int trCommID = tr.getIntColumn("community_id");
for (int i = 0; i < commID.length; i++)
{
// Found this community
if (commID[i] == trCommID)
{
// Flag it, and remove (-1) from the item mappings
itemIsMapped = true;
commID[i] = -1;
}
}
// The item is no longer mapped to this community, so remove the database record
if (!itemIsMapped)
DatabaseManager.delete(context, tr);
}
}
// Any remaining mappings need to be added to the database
for (int i = 0; i < commID.length; i++)
{
if (commID[i] > -1)
{
TableRow row = DatabaseManager.create(context, "Communities2Item");
row.setColumn("item_id", itemID);

View File

@@ -535,17 +535,54 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseCreateDAO#insertCommunityMappings(java.lang.String, java.lang.String, java.lang.String)
* @see org.dspace.browse.BrowseCreateDAO#updateCommunityMappings(int)
*/
public void insertCommunityMappings(int itemID) throws BrowseException
public void updateCommunityMappings(int itemID) throws BrowseException
{
try
{
// Get all the communities for this item
int[] commID = getAllCommunityIDs(itemID);
// Remove (set to -1) any duplicate communities
for (int i = 0; i < commID.length; i++)
{
if (isFirstOccurrence(commID, i))
if (!isFirstOccurrence(commID, i))
commID[i] = -1;
}
// Find all existing mappings for this item
TableRowIterator tri = DatabaseManager.queryTable(context, "Communities2Item", "SELECT * FROM Communities2Item WHERE item_id=?", itemID);
if (tri != null)
{
while (tri.hasNext())
{
TableRow tr = tri.next();
// Check the item mappings to see if it contains this community mapping
boolean itemIsMapped = false;
int trCommID = tr.getIntColumn("community_id");
for (int i = 0; i < commID.length; i++)
{
// Found this community
if (commID[i] == trCommID)
{
// Flag it, and remove (-1) from the item mappings
itemIsMapped = true;
commID[i] = -1;
}
}
// The item is no longer mapped to this community, so remove the database record
if (!itemIsMapped)
DatabaseManager.delete(context, tr);
}
}
// Any remaining mappings need to be added to the database
for (int i = 0; i < commID.length; i++)
{
if (commID[i] > -1)
{
TableRow row = DatabaseManager.create(context, "Communities2Item");
row.setColumn("item_id", itemID);

View File

@@ -720,13 +720,20 @@ public class BrowseEngine
// to do comparisons in other columns. The use of the focus value needs to be consistent
// across the browse
SortOption so = scope.getSortOption();
String col = "sort_value";
if (so == null || so.getNumber() == 0)
{
if (browseIndex.getSortOption() != null)
so = browseIndex.getSortOption();
}
String col = "sort_1";
if (so.getNumber() > 0)
{
col = "sort_" + Integer.toString(so.getNumber());
}
// now get the DAO to do the query for us, returning the highest
// now get the DAO to do the query for us, returning the highest
// string value in the given column in the given table for the
// item (I think)
String max = dao.doMaxQuery(col, tableName, id);

View File

@@ -78,7 +78,7 @@ public class BrowserScope
private String filterValueLang;
/** the item id focus of the browse */
private int jumpItemId;
private int jumpItemId = -1;
/** the string value to start with */
private String startsWith;

View File

@@ -362,9 +362,7 @@ public class IndexBrowse
try
{
// Delete community mappings - we'll add them again if necessary
dao.deleteCommunityMappings(item.getID());
boolean reqCommunityMappings = false;
Map<Integer, String> sortMap = getSortValues(item, itemMDMap);
if (item.isArchived() && !item.isWithdrawn())
{
@@ -376,7 +374,8 @@ public class IndexBrowse
removeIndex(item.getID(), BrowseIndex.getWithdrawnBrowseIndex().getTableName());
dao.insertIndex(BrowseIndex.getItemBrowseIndex().getTableName(), item.getID(), sortMap);
}
dao.insertCommunityMappings(item.getID());
reqCommunityMappings = true;
}
else if (item.isWithdrawn())
{
@@ -395,7 +394,17 @@ public class IndexBrowse
removeIndex(item.getID(), BrowseIndex.getItemBrowseIndex().getTableName());
removeIndex(item.getID(), BrowseIndex.getWithdrawnBrowseIndex().getTableName());
}
// Update the community mappings if they are required, or remove them if they aren't
if (reqCommunityMappings)
{
dao.updateCommunityMappings(item.getID());
}
else
{
dao.deleteCommunityMappings(item.getID());
}
// Now update the metadata indexes
for (int i = 0; i < bis.length; i++)
{

View File

@@ -372,7 +372,6 @@ public class ItemMapServlet extends DSpaceServlet
bs.setFilterValuePartial(true);
bs.setJumpToValue(null);
bs.setResultsPerPage(10000); // an arbitrary number (large) for the time being
bs.setSortBy(0);
bs.setBrowseLevel(1);
BrowseEngine be = new BrowseEngine(context);