mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 04:23:13 +00:00
DS-3579: Improve cache usage update-handle-prefix
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -98,7 +99,7 @@ public class MetadataValueServiceImpl implements MetadataValueService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataValue> findByValueLike(Context context, String value) throws SQLException {
|
||||
public Iterator<MetadataValue> findByValueLike(Context context, String value) throws SQLException {
|
||||
return metadataValueDAO.findByValueLike(context, value);
|
||||
}
|
||||
|
||||
|
@@ -13,6 +13,7 @@ import org.dspace.core.Context;
|
||||
import org.dspace.core.GenericDAO;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -26,7 +27,7 @@ public interface MetadataValueDAO extends GenericDAO<MetadataValue> {
|
||||
|
||||
public List<MetadataValue> findByField(Context context, MetadataField fieldId) throws SQLException;
|
||||
|
||||
public List<MetadataValue> findByValueLike(Context context, String value) throws SQLException;
|
||||
public Iterator<MetadataValue> findByValueLike(Context context, String value) throws SQLException;
|
||||
|
||||
public void deleteByMetadataField(Context context, MetadataField metadataField) throws SQLException;
|
||||
|
||||
|
@@ -18,6 +18,7 @@ import org.hibernate.Query;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -48,14 +49,14 @@ public class MetadataValueDAOImpl extends AbstractHibernateDAO<MetadataValue> im
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataValue> findByValueLike(Context context, String value) throws SQLException {
|
||||
Criteria criteria = createCriteria(context, MetadataValue.class);
|
||||
criteria.add(
|
||||
Restrictions.like("value", "%" + value + "%")
|
||||
);
|
||||
criteria.setFetchMode("metadataField", FetchMode.JOIN);
|
||||
public Iterator<MetadataValue> findByValueLike(Context context, String value) throws SQLException {
|
||||
String queryString = "SELECT m FROM MetadataValue m JOIN FETCH m.metadataField f " +
|
||||
"WHERE m.value like concat('%', concat(:searchString,'%')) ORDER BY m.id ASC";
|
||||
|
||||
return list(criteria);
|
||||
Query query = createQuery(context, queryString);
|
||||
query.setString("searchString", value);
|
||||
|
||||
return iterate(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -15,6 +15,7 @@ import org.dspace.core.Context;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -82,7 +83,7 @@ public interface MetadataValueService {
|
||||
*/
|
||||
public void delete(Context context, MetadataValue metadataValue) throws SQLException;
|
||||
|
||||
public List<MetadataValue> findByValueLike(Context context, String value) throws SQLException;
|
||||
public Iterator<MetadataValue> findByValueLike(Context context, String value) throws SQLException;
|
||||
|
||||
public void deleteByMetadataField(Context context, MetadataField metadataField) throws SQLException;
|
||||
|
||||
|
@@ -231,6 +231,7 @@ public class HandleServiceImpl implements HandleService
|
||||
// can verify during a restore whether the same *type* of resource
|
||||
// is reusing this handle!
|
||||
handle.setDSpaceObject(null);
|
||||
dso.getHandles().remove(handle);
|
||||
handleDAO.save(context, handle);
|
||||
|
||||
if(log.isDebugEnabled())
|
||||
@@ -241,7 +242,7 @@ public class HandleServiceImpl implements HandleService
|
||||
}
|
||||
else
|
||||
{
|
||||
log.warn("Cannot find Handle entry to unbind for object " + Constants.typeText[dso.getType()] + " id=" + dso.getID());
|
||||
log.trace("Cannot find Handle entry to unbind for object " + Constants.typeText[dso.getType()] + " id=" + dso.getID() + ". Handle could have been unbinded before.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,10 +7,6 @@
|
||||
*/
|
||||
package org.dspace.handle;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
@@ -19,6 +15,13 @@ import org.dspace.core.Context;
|
||||
import org.dspace.discovery.IndexClient;
|
||||
import org.dspace.handle.factory.HandleServiceFactory;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A script to update the handle values in the database. This is typically used
|
||||
@@ -32,6 +35,7 @@ public class UpdateHandlePrefix
|
||||
{
|
||||
|
||||
private static final Logger log = Logger.getLogger(UpdateHandlePrefix.class);
|
||||
private static final ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
|
||||
/**
|
||||
* When invoked as a command-line tool, updates handle prefix
|
||||
@@ -94,12 +98,19 @@ public class UpdateHandlePrefix
|
||||
|
||||
System.out.print("Updating metadatavalues table... ");
|
||||
MetadataValueService metadataValueService = ContentServiceFactory.getInstance().getMetadataValueService();
|
||||
List<MetadataValue> metadataValues = metadataValueService.findByValueLike(context, "http://hdl.handle.net/");
|
||||
int updMeta = metadataValues.size();
|
||||
for (MetadataValue metadataValue : metadataValues) {
|
||||
metadataValue.setValue(metadataValue.getValue().replace("http://hdl.handle.net/" + oldH, "http://hdl.handle.net/" + newH));
|
||||
|
||||
String handlePrefix = configurationService.getProperty("handle.canonical.prefix");
|
||||
Iterator<MetadataValue> metadataValues = metadataValueService.findByValueLike(context, handlePrefix);
|
||||
|
||||
int updMeta = 0;
|
||||
while(metadataValues.hasNext()) {
|
||||
MetadataValue metadataValue = metadataValues.next();
|
||||
metadataValue.setValue(metadataValue.getValue().replace(handlePrefix + oldH, handlePrefix + newH));
|
||||
metadataValueService.update(context, metadataValue, true);
|
||||
context.uncacheEntity(metadataValue);
|
||||
updMeta++;
|
||||
}
|
||||
|
||||
System.out.println(
|
||||
updMeta + " metadata value" + ((updMeta > 1) ? "s" : "") + " updated"
|
||||
);
|
||||
|
Reference in New Issue
Block a user