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 class
History.Step
A step in the history, which is aGrid
with associated metadata.
-
Field Summary
Fields Modifier and Type Field Description protected int
_cachedPosition
protected ExecutorService
_cachingExecutorService
protected Future<Void>
_cachingFuture
protected ChangeDataStore
_dataStore
protected int
_desiredCachedPosition
protected List<HistoryEntry>
_entries
protected GridCache
_gridStore
protected Instant
_lastModified
protected int
_position
protected int
_positionBeingCached
protected long
_projectId
protected 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 OperationApplicationResult
addEntry(long id, Operation operation)
Adds aHistoryEntry
to the list of past histories.OperationApplicationResult
addEntry(Operation operation)
Applies an operation on top of the existing history.protected void
cacheGridOnDisk(int position)
boolean
currentGridNeedsRefreshing()
Is the current grid incomplete?void
dispose()
Uncaches all grids from memory and stops all related fetching and caching processes.int
entryIndex(long entryID)
Return the position of the history entry with the supplied id, or throwsIllegalArgumentException
if that id cannot be found.int
getCachedPosition()
ChangeDataStore
getChangeDataStore()
long
getCurrentEntryId()
Grid
getCurrentGrid()
Returns the state of the grid at the current position in the history.List<HistoryEntry>
getEntries()
protected HistoryEntry
getEntry(long entryID)
protected Grid
getGrid(int position, boolean refresh)
Returns the state of the grid at a given index in the historyGridCache
getGridCache()
Grid
getInitialGrid()
Returns the state of the grid at before any operation was applied on itInstant
getLastModified()
The last time this history was modified (or created).List<HistoryEntry>
getLastPastEntries(int count)
int
getPosition()
long
getPrecedingEntryID(long entryID)
Given an history entry id, return the id of the preceding history entry, or -1 if there is none.void
refreshCurrentGrid()
protected void
uncacheGridFromDisk(int position)
GridPreservation
undoRedo(long lastDoneEntryID)
Rewinds or brings the history forward.protected void
updateCachedPosition()
void
waitForCaching()
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, ExecutionException
Wait 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 aHistoryEntry
to 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:
OperationException
IOException
-
uncacheGridFromDisk
protected void uncacheGridFromDisk(int position) throws IOException, OperationException
- Throws:
IOException
OperationException
-
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 throwsIllegalArgumentException
if that id cannot be found.
-
getEntry
protected HistoryEntry getEntry(long entryID)
-
-