Package org.openrefine.history
Class History
- java.lang.Object
-
- org.openrefine.history.History
-
public class History extends Object
Track done and undone changes. Done changes can be undone; undone changes can be redone. Each change is actually not tracked directly but through a history entry. The history entry stores only the metadata, while the change object stores the actual data. Thus, the history entries are much smaller and can be kept in memory, while the change objects are only loaded into memory on demand.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classHistory.StepA step in the history, which is aGridwith associated metadata.
-
Field Summary
Fields Modifier and Type Field Description protected int_cachedPositionprotected ExecutorService_cachingExecutorServiceprotected Future<Void>_cachingFutureprotected ChangeDataStore_dataStoreprotected int_desiredCachedPositionprotected List<HistoryEntry>_entriesprotected GridCache_gridStoreprotected Instant_lastModifiedprotected int_positionprotected int_positionBeingCachedprotected long_projectIdprotected List<History.Step>_steps
-
Constructor Summary
Constructors Constructor Description History(Grid initialGrid, ChangeDataStore dataStore, GridCache gridStore, long projectId)Creates an empty on an initial grid.History(Grid initialGrid, ChangeDataStore dataStore, GridCache gridStore, List<HistoryEntry> entries, int position, long projectId)Constructs a history with an initial grid and a list of history entries.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OperationApplicationResultaddEntry(long id, Operation operation)Adds aHistoryEntryto the list of past histories.OperationApplicationResultaddEntry(Operation operation)Applies an operation on top of the existing history.protected voidcacheGridOnDisk(int position)booleancurrentGridNeedsRefreshing()Is the current grid incomplete?voiddispose()Uncaches all grids from memory and stops all related fetching and caching processes.intentryIndex(long entryID)Return the position of the history entry with the supplied id, or throwsIllegalArgumentExceptionif that id cannot be found.intgetCachedPosition()ChangeDataStoregetChangeDataStore()longgetCurrentEntryId()GridgetCurrentGrid()Returns the state of the grid at the current position in the history.List<HistoryEntry>getEntries()protected HistoryEntrygetEntry(long entryID)protected GridgetGrid(int position, boolean refresh)Returns the state of the grid at a given index in the historyGridCachegetGridCache()GridgetInitialGrid()Returns the state of the grid at before any operation was applied on itInstantgetLastModified()The last time this history was modified (or created).List<HistoryEntry>getLastPastEntries(int count)intgetPosition()longgetPrecedingEntryID(long entryID)Given an history entry id, return the id of the preceding history entry, or -1 if there is none.voidrefreshCurrentGrid()protected voiduncacheGridFromDisk(int position)GridPreservationundoRedo(long lastDoneEntryID)Rewinds or brings the history forward.protected voidupdateCachedPosition()voidwaitForCaching()Wait for any caching operation currently being executed asynchronously.
-
-
-
Field Detail
-
_projectId
protected final long _projectId
-
_entries
protected List<HistoryEntry> _entries
-
_position
protected int _position
-
_cachedPosition
protected int _cachedPosition
-
_desiredCachedPosition
protected int _desiredCachedPosition
-
_positionBeingCached
protected int _positionBeingCached
-
_cachingExecutorService
protected final ExecutorService _cachingExecutorService
-
_steps
protected List<History.Step> _steps
-
_dataStore
protected ChangeDataStore _dataStore
-
_gridStore
protected GridCache _gridStore
-
_lastModified
protected Instant _lastModified
-
-
Constructor Detail
-
History
public History(Grid initialGrid, ChangeDataStore dataStore, GridCache gridStore, long projectId)
Creates an empty on an initial grid.- Parameters:
initialGrid- the initial state of the projectdataStore- where to store change datagridStore- where to store intermediate cached grids
-
History
public History(Grid initialGrid, ChangeDataStore dataStore, GridCache gridStore, List<HistoryEntry> entries, int position, long projectId) throws OperationException
Constructs a history with an initial grid and a list of history entries.- Parameters:
initialGrid- the first grid of the project, at creation timedataStore- where change data is stored for all changes of the projectentries- the list of entries of the historyposition- the current position in the history- Throws:
OperationException- if one step in the list of history entries failed to apply to the supplied grid
-
-
Method Detail
-
waitForCaching
public void waitForCaching() throws InterruptedException, ExecutionExceptionWait for any caching operation currently being executed asynchronously. Mostly for testing purposes.
-
getCurrentGrid
public Grid getCurrentGrid()
Returns the state of the grid at the current position in the history.
-
currentGridNeedsRefreshing
public boolean currentGridNeedsRefreshing()
Is the current grid incomplete? If so, it should be refreshed withrefreshCurrentGrid()after a while.
-
getInitialGrid
public Grid getInitialGrid()
Returns the state of the grid at before any operation was applied on it
-
getGrid
protected Grid getGrid(int position, boolean refresh) throws OperationException
Returns the state of the grid at a given index in the history- Parameters:
position- a 0-based index in the list of successive gridsrefresh- whether the grid should be refreshed if it depends on change data being currently fetched- Throws:
OperationException
-
getPosition
public int getPosition()
-
getCurrentEntryId
public long getCurrentEntryId()
-
getCachedPosition
public int getCachedPosition()
-
getEntries
public List<HistoryEntry> getEntries()
-
getChangeDataStore
public ChangeDataStore getChangeDataStore()
-
getGridCache
public GridCache getGridCache()
-
getLastModified
public Instant getLastModified()
The last time this history was modified (or created).
-
addEntry
public OperationApplicationResult addEntry(Operation operation)
Applies an operation on top of the existing history. This will modify this instance. If the operation application failed, the exception will be returned inOperationApplicationResult.getException().- Parameters:
operation- the operation to apply.
-
addEntry
public OperationApplicationResult addEntry(long id, Operation operation)
Adds aHistoryEntryto the list of past histories. Adding a new entry clears all currently held future histories
-
cacheGridOnDisk
protected void cacheGridOnDisk(int position) throws OperationException, IOException- Throws:
OperationExceptionIOException
-
uncacheGridFromDisk
protected void uncacheGridFromDisk(int position) throws IOException, OperationException- Throws:
IOExceptionOperationException
-
updateCachedPosition
protected void updateCachedPosition()
-
refreshCurrentGrid
public void refreshCurrentGrid()
-
getLastPastEntries
public List<HistoryEntry> getLastPastEntries(int count)
-
undoRedo
public GridPreservation undoRedo(long lastDoneEntryID) throws OperationException
Rewinds or brings the history forward.- Parameters:
lastDoneEntryID- the id of the last change to be performed before the desired state of the project. Use 0L for the initial state.- Returns:
- the degree to which the grid was preserved while changing the position in the history
- Throws:
OperationException- if the application of changes required for this move did not succeed
-
getPrecedingEntryID
public long getPrecedingEntryID(long entryID)
Given an history entry id, return the id of the preceding history entry, or -1 if there is none.
-
dispose
public void dispose()
Uncaches all grids from memory and stops all related fetching and caching processes.
-
entryIndex
public int entryIndex(long entryID)
Return the position of the history entry with the supplied id, or throwsIllegalArgumentExceptionif that id cannot be found.
-
getEntry
protected HistoryEntry getEntry(long entryID)
-
-