mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 21:43:11 +00:00
Add functions to do a manual flush of the db session and call flush before change to READ_ONLY mode to be sure we index the current object
This commit is contained in:
@@ -880,6 +880,16 @@ public class Context implements AutoCloseable {
|
||||
dbConnection.uncacheEntity(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the current Session to synchronizes the in-memory state of the Session
|
||||
* with the database (write changes to the database)
|
||||
*
|
||||
* @throws SQLException passed through.
|
||||
*/
|
||||
public void flushDBChanges() throws SQLException {
|
||||
dbConnection.flushSession();
|
||||
}
|
||||
|
||||
public Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson) {
|
||||
if (isReadOnly()) {
|
||||
return readOnlyCache.getCachedAuthorizationResult(dspaceObject, action, eperson);
|
||||
|
@@ -148,4 +148,12 @@ public interface DBConnection<T> {
|
||||
* @throws java.sql.SQLException passed through.
|
||||
*/
|
||||
public <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLException;
|
||||
|
||||
/**
|
||||
* Do a manual flush. This synchronizes the in-memory state of the Session
|
||||
* with the database (write changes to the database)
|
||||
*
|
||||
* @throws SQLException passed through.
|
||||
*/
|
||||
public void flushSession() throws SQLException;
|
||||
}
|
||||
|
@@ -337,4 +337,17 @@ public class HibernateDBConnection implements DBConnection<Session> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do a manual flush. This synchronizes the in-memory state of the Session
|
||||
* with the database (write changes to the database)
|
||||
*
|
||||
* @throws SQLException passed through.
|
||||
*/
|
||||
@Override
|
||||
public void flushSession() throws SQLException {
|
||||
if (getSession().isDirty()) {
|
||||
getSession().flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -201,7 +201,11 @@ public class IndexEventConsumer implements Consumer {
|
||||
@Override
|
||||
public void end(Context ctx) throws Exception {
|
||||
|
||||
// Change the mode to readonly to improve the performance
|
||||
// Change the mode to readonly to improve performance
|
||||
// First, we flush the changes to database, if session is dirty, has pending changes
|
||||
// to synchronize with database, without this flush it could index an old version of
|
||||
// the object
|
||||
ctx.flushDBChanges();
|
||||
Context.Mode originalMode = ctx.getCurrentMode();
|
||||
ctx.setMode(Context.Mode.READ_ONLY);
|
||||
|
||||
@@ -234,9 +238,9 @@ public class IndexEventConsumer implements Consumer {
|
||||
uniqueIdsToDelete.clear();
|
||||
createdItemsToUpdate.clear();
|
||||
}
|
||||
}
|
||||
|
||||
ctx.setMode(originalMode);
|
||||
ctx.setMode(originalMode);
|
||||
}
|
||||
}
|
||||
|
||||
private void indexObject(Context ctx, IndexableObject iu, boolean preDb) throws SQLException {
|
||||
|
Reference in New Issue
Block a user