Remove unused parts of the API, reduce db contention when an item is updated

git-svn-id: http://scm.dspace.org/svn/repo/trunk@2627 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Graham Triggs
2008-02-10 16:51:36 +00:00
parent ad0851eddd
commit 60c869ace5
4 changed files with 122 additions and 56 deletions

View File

@@ -107,31 +107,28 @@ public interface BrowseCreateDAO
public void insertIndex(String table, int itemID, Map sortCols) throws BrowseException;
/**
* Insert an index record into the given table for the given item id. The value
* is the human readable value for the field, the sortValue is the normalised version
* (normalised in whatever way the caller sees fit), and the Map should contain
* Updates an index record into the given table for the given item id. The Map should contain
* key value pairs representing the sort column integer representation and the normalised
* value for that field.
*
*
* For example, the caller might do as follows:
*
*
* <code>
* Map map = new HashMap();
* map.put(new Integer(1), "the title");
* map.put(new Integer(2), "the subject");
*
*
* BrowseCreateDAO dao = BrowseDAOFactory.getCreateInstance();
* dao.insertIndex("index_1", 21, "Human Readable", "human readable", map);
* dao.updateIndex("index_1", 21, map);
* </code>
*
* @param table the browse table to insert the index in
* @param itemID the database id of the item being indexed
* @param value the human readable value of the index
* @param sortValue the sortable value of the index
* @param sortCols an Integer-String map of sort column numbers and values
*
* @param table the browse table to insert the index in
* @param itemID the database id of the item being indexed
* @param sortCols an Integer-String map of sort column numbers and values
* @return true if the record is updated, false if not found
* @throws BrowseException
*/
public void insertIndex(String table, int itemID, String value, String sortValue, Map sortCols) throws BrowseException;
public boolean updateIndex(String table, int itemID, Map sortCols) throws BrowseException;
/**
* Get the browse index's internal id for the location of the given string

View File

@@ -591,39 +591,66 @@ public class BrowseCreateDAOOracle implements BrowseCreateDAO
throw new BrowseException(e);
}
}
/* (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#updateIndex(java.lang.String, int, java.util.Map)
*/
public void insertIndex(String table, int itemID, String value, String sortValue, Map sortCols)
public boolean updateIndex(String table, int itemID, Map sortCols)
throws BrowseException
{
try
{
// create us a row in the index
TableRow row = DatabaseManager.create(context, table);
// set the primary information for the index
row.setColumn("item_id", itemID);
row.setColumn("value", utils.truncateValue(value));
row.setColumn("sort_value", utils.truncateSortValue(sortValue));
// now set the columns for the other sort values
boolean rowUpdated = false;
TableRow row = DatabaseManager.findByUnique(context, table, "item_id", itemID);
// If the item does not exist in the table, return that it couldn't be found
if (row == null)
return false;
// Iterate through all the sort values
Iterator itra = sortCols.keySet().iterator();
while (itra.hasNext())
{
Integer key = (Integer) itra.next();
String nValue = (String) sortCols.get(key);
row.setColumn("sort_" + key.toString(), utils.truncateSortValue(nValue));
// Generate the appropriate column name
String column = "sort_" + key.toString();
// Create the value that will be written in to the column
String newValue = utils.truncateSortValue( (String) sortCols.get(key) );
// Check the column exists - if it doesn't, something has gone seriously wrong
if (!row.hasColumn(column))
throw new BrowseException("Column '" + column + "' does not exist in table " + table);
// Get the existing value from the column
String oldValue = row.getStringColumn(column);
// If the new value differs from the old value, update the column and flag that the row has changed
if (oldValue != null && !oldValue.equals(newValue))
{
row.setColumn(column, newValue);
rowUpdated = true;
}
else if (newValue != null && !newValue.equals(oldValue))
{
row.setColumn(column, newValue);
rowUpdated = true;
}
}
DatabaseManager.update(context, row);
// We've updated the row, so save it back to the database
if (rowUpdated)
DatabaseManager.update(context, row);
}
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new BrowseException(e);
}
// Return that the original record was found
return true;
}
/* (non-Javadoc)

View File

@@ -590,39 +590,66 @@ public class BrowseCreateDAOPostgres implements BrowseCreateDAO
}
/* (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#updateIndex(java.lang.String, int, java.util.Map)
*/
public void insertIndex(String table, int itemID, String value, String sortValue, Map sortCols)
throws BrowseException
public boolean updateIndex(String table, int itemID, Map sortCols)
throws BrowseException
{
try
{
// create us a row in the index
TableRow row = DatabaseManager.create(context, table);
// set the primary information for the index
row.setColumn("item_id", itemID);
row.setColumn("value", utils.truncateValue(value));
row.setColumn("sort_value", utils.truncateSortValue(sortValue));
// now set the columns for the other sort values
boolean rowUpdated = false;
TableRow row = DatabaseManager.findByUnique(context, table, "item_id", itemID);
// If the item does not exist in the table, return that it couldn't be found
if (row == null)
return false;
// Iterate through all the sort values
Iterator itra = sortCols.keySet().iterator();
while (itra.hasNext())
{
Integer key = (Integer) itra.next();
String nValue = (String) sortCols.get(key);
row.setColumn("sort_" + key.toString(), utils.truncateSortValue(nValue));
// Generate the appropriate column name
String column = "sort_" + key.toString();
// Create the value that will be written in to the column
String newValue = utils.truncateSortValue( (String) sortCols.get(key) );
// Check the column exists - if it doesn't, something has gone seriously wrong
if (!row.hasColumn(column))
throw new BrowseException("Column '" + column + "' does not exist in table " + table);
// Get the existing value from the column
String oldValue = row.getStringColumn(column);
// If the new value differs from the old value, update the column and flag that the row has changed
if (oldValue != null && !oldValue.equals(newValue))
{
row.setColumn(column, newValue);
rowUpdated = true;
}
else if (newValue != null && !newValue.equals(oldValue))
{
row.setColumn(column, newValue);
rowUpdated = true;
}
}
DatabaseManager.update(context, row);
// We've updated the row, so save it back to the database
if (rowUpdated)
DatabaseManager.update(context, row);
}
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new BrowseException(e);
}
// Return that the original record was found
return true;
}
/* (non-Javadoc)
* @see org.dspace.browse.BrowseCreateDAO#pruneDistinct(java.lang.String, java.lang.String)
*/

View File

@@ -365,23 +365,38 @@ public class IndexBrowse
try
{
// Remove from the item indexes (archive and withdrawn)
removeIndex(item.getID(), BrowseIndex.getItemBrowseIndex().getTableName());
removeIndex(item.getID(), BrowseIndex.getWithdrawnBrowseIndex().getTableName());
// Delete community mappings - we'll add them again if necessary
dao.deleteCommunityMappings(item.getID());
// Index any archived item that isn't withdrawn
Map<Integer, String> sortMap = getSortValues(item, itemMDMap);
if (item.isArchived() && !item.isWithdrawn())
{
Map<Integer, String> sortMap = getSortValues(item, itemMDMap);
dao.insertIndex(BrowseIndex.getItemBrowseIndex().getTableName(), item.getID(), sortMap);
// Try to update an existing record in the item index
if (!dao.updateIndex(BrowseIndex.getItemBrowseIndex().getTableName(), item.getID(), sortMap))
{
// Record doesn't exist - ensure that it doesn't exist in the withdrawn index,
// and add it to the archived item index
removeIndex(item.getID(), BrowseIndex.getWithdrawnBrowseIndex().getTableName());
dao.insertIndex(BrowseIndex.getItemBrowseIndex().getTableName(), item.getID(), sortMap);
}
dao.insertCommunityMappings(item.getID());
}
else if (item.isWithdrawn())
{
// If it's withdrawn, add it to the withdrawn items index
Map<Integer, String> sortMap = getSortValues(item, itemMDMap);
dao.insertIndex(BrowseIndex.getWithdrawnBrowseIndex().getTableName(), item.getID(), sortMap);
// Try to update an existing record in the withdrawn index
if (!dao.updateIndex(BrowseIndex.getWithdrawnBrowseIndex().getTableName(), item.getID(), sortMap))
{
// Record doesn't exist - ensure that it doesn't exist in the item index,
// and add it to the withdrawn item index
removeIndex(item.getID(), BrowseIndex.getItemBrowseIndex().getTableName());
dao.insertIndex(BrowseIndex.getWithdrawnBrowseIndex().getTableName(), item.getID(), sortMap);
}
}
else
{
// This item shouldn't exist in either index - ensure that it is removed
removeIndex(item.getID(), BrowseIndex.getItemBrowseIndex().getTableName());
removeIndex(item.getID(), BrowseIndex.getWithdrawnBrowseIndex().getTableName());
}
// Now update the metadata indexes