Package org.openrefine
Class ProjectManager
- java.lang.Object
-
- org.openrefine.ProjectManager
-
- Direct Known Subclasses:
FileProjectManager
,ProjectManagerStub
public abstract class ProjectManager extends Object
ProjectManager is responsible for loading and saving the workspace and projects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ProjectManager.SaveRecord
A utility class to prioritize projects for saving, depending on how long ago they have been changed but have not been saved.
-
Field Summary
Fields Modifier and Type Field Description protected FacetCountCacheManager
_facetCountCacheManager
Caches the facet counts of projects (for the GREL facetCount function)protected LookupCacheManager
_lookupCacheManager
What caches the lookups of projects (for the GRELÂ cross function)protected PreferenceStore
_preferenceStore
protected Map<Long,Project>
_projects
While each project's metadata is loaded completely at start-up, each project's raw data is loaded only when the project is accessed by the user.protected Map<Long,ProjectMetadata>
_projectsMetadata
protected Map<String,Integer>
_projectsTags
static int
EXPRESSION_HISTORY_MAX
protected static Duration
PROJECT_FLUSH_DELAY
protected static Duration
QUICK_SAVE_MAX_TIME
static ProjectManager
singleton
-
Constructor Summary
Constructors Modifier Constructor Description protected
ProjectManager()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addLatestExpression(String s)
Add the latest expression to the preference storeabstract void
deleteProject(long projectID)
Remove project from data storevoid
deleteProject(Project project)
Remove the project from the data storevoid
dispose()
protected void
disposeUnmodifiedProjects()
Flush all unmodified projects from memory.void
ensureProjectSaved(long id, ProgressReporter progressReporter)
Saves a project and its metadata to the data storeabstract void
exportProject(long projectId, org.apache.commons.compress.archivers.tar.TarArchiveOutputStream tos)
Export project to a Refine archiveMap<Long,ProjectMetadata>
getAllProjectMetadata()
Gets all the project Metadata currently held in memory.Map<String,Integer>
getAllProjectTags()
Gets all the project tags currently held in memoryabstract ChangeDataStore
getChangeDataStore(long projectID)
Return the change data store for a given projectList<String>
getExpressions()
Gets all expressions from the preference storeFacetCountCacheManager
getFacetCountCache()
abstract GridCache
getGridCache(long projectId)
Return the cached grid store for a given projectabstract HistoryEntryManager
getHistoryEntryManager()
The history entry manager deals with changesProject
getLoadedProject(long id)
Gets the required project, assuming it has already been leaded.LookupCacheManager
getLookupCacheManager()
Gets the LookupCacheManager from memoryPreferenceStore
getPreferenceStore()
Gets the preference storeProject
getProject(long id)
Gets the required project from the data store If project does not already exist in memory, it is loaded from the data storelong
getProjectID(String name)
Tries to find the project id when given a project name Requires that all project metadata exists has been loaded to memory from the data storeProjectMetadata
getProjectMetadata(long id)
Gets the project metadata from memory Requires that the metadata has already been loaded from the data storeProjectMetadata
getProjectMetadata(String name)
Gets the project metadata from memory Requires that the metadata has already been loaded from the data storeabstract void
importProject(long projectID, InputStream inputStream, boolean gziped)
Import project from a Refine archiveprotected abstract Project
loadProject(long id)
Loads a project from the data store into memoryabstract boolean
loadProjectMetadata(long projectID)
Load project metadata from data storagevoid
mergeEmptyUserMetadata(ProjectMetadata metadata)
protected static void
preparePreferenceStore(PreferenceStore ps)
void
registerProject(Project project, ProjectMetadata projectMetadata)
Registers the project in the memory of the current sessionabstract void
reloadProjectFromWorkspace(long id, ProgressReporter progressReporter)
Ensures a project is saved in the workspace and its grids are read from there.protected void
removeProject(long projectID)
Removes project from memoryvoid
save()
Save workspace and all projects to data storeabstract void
saveMetadata(ProjectMetadata metadata, long projectId)
Save project metadata to the data storeabstract void
saveProject(Project project, ProgressReporter progressReporter)
Save project to the data storevoid
saveProjects()
Saves all projects to the data storeprotected abstract void
saveWorkspace()
Saves the workspace to the data store
-
-
-
Field Detail
-
EXPRESSION_HISTORY_MAX
public static final int EXPRESSION_HISTORY_MAX
- See Also:
- Constant Field Values
-
PROJECT_FLUSH_DELAY
protected static final Duration PROJECT_FLUSH_DELAY
-
QUICK_SAVE_MAX_TIME
protected static final Duration QUICK_SAVE_MAX_TIME
-
_projectsMetadata
protected Map<Long,ProjectMetadata> _projectsMetadata
-
_preferenceStore
protected PreferenceStore _preferenceStore
-
_lookupCacheManager
protected transient LookupCacheManager _lookupCacheManager
What caches the lookups of projects (for the GRELÂ cross function)
-
_facetCountCacheManager
protected transient FacetCountCacheManager _facetCountCacheManager
Caches the facet counts of projects (for the GREL facetCount function)
-
_projects
protected transient Map<Long,Project> _projects
While each project's metadata is loaded completely at start-up, each project's raw data is loaded only when the project is accessed by the user. This is because project metadata is tiny compared to raw project data. This hash map from project ID to project is more like a last accessed-last out cache.
-
singleton
public static ProjectManager singleton
-
-
Method Detail
-
dispose
public void dispose()
-
registerProject
public void registerProject(Project project, ProjectMetadata projectMetadata)
Registers the project in the memory of the current session
-
getChangeDataStore
public abstract ChangeDataStore getChangeDataStore(long projectID)
Return the change data store for a given project
-
getGridCache
public abstract GridCache getGridCache(long projectId)
Return the cached grid store for a given project
-
loadProjectMetadata
public abstract boolean loadProjectMetadata(long projectID)
Load project metadata from data storage
-
loadProject
protected abstract Project loadProject(long id) throws IOException
Loads a project from the data store into memory- Throws:
IOException
-
importProject
public abstract void importProject(long projectID, InputStream inputStream, boolean gziped) throws IOException
Import project from a Refine archive- Throws:
IOException
-
exportProject
public abstract void exportProject(long projectId, org.apache.commons.compress.archivers.tar.TarArchiveOutputStream tos) throws IOException
Export project to a Refine archive- Throws:
IOException
-
ensureProjectSaved
public void ensureProjectSaved(long id, ProgressReporter progressReporter)
Saves a project and its metadata to the data store
-
reloadProjectFromWorkspace
public abstract void reloadProjectFromWorkspace(long id, ProgressReporter progressReporter) throws IOException
Ensures a project is saved in the workspace and its grids are read from there.- Parameters:
id
- the project id to loadprogressReporter
-- Throws:
IOException
-
saveMetadata
public abstract void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception
Save project metadata to the data store- Throws:
Exception
-
saveProject
public abstract void saveProject(Project project, ProgressReporter progressReporter) throws IOException
Save project to the data store- Throws:
IOException
-
save
public void save()
Save workspace and all projects to data store
-
saveWorkspace
protected abstract void saveWorkspace()
Saves the workspace to the data store
-
saveProjects
public void saveProjects()
Saves all projects to the data store
-
disposeUnmodifiedProjects
protected void disposeUnmodifiedProjects()
Flush all unmodified projects from memory.
-
getLookupCacheManager
public LookupCacheManager getLookupCacheManager()
Gets the LookupCacheManager from memory
-
getFacetCountCache
public FacetCountCacheManager getFacetCountCache()
-
getProjectMetadata
public ProjectMetadata getProjectMetadata(long id)
Gets the project metadata from memory Requires that the metadata has already been loaded from the data store
-
getProjectMetadata
public ProjectMetadata getProjectMetadata(String name)
Gets the project metadata from memory Requires that the metadata has already been loaded from the data store
-
getProjectID
public long getProjectID(String name) throws GetProjectIDException
Tries to find the project id when given a project name Requires that all project metadata exists has been loaded to memory from the data store- Parameters:
name
- The name of the project- Returns:
- The id of the project
- Throws:
GetProjectIDException
- If no unique project is found with the given name
-
mergeEmptyUserMetadata
public void mergeEmptyUserMetadata(ProjectMetadata metadata)
-
getAllProjectMetadata
public Map<Long,ProjectMetadata> getAllProjectMetadata()
Gets all the project Metadata currently held in memory.
-
getAllProjectTags
public Map<String,Integer> getAllProjectTags()
Gets all the project tags currently held in memory
-
getProject
public Project getProject(long id)
Gets the required project from the data store If project does not already exist in memory, it is loaded from the data store- Parameters:
id
- the id of the project- Returns:
- the project with the matching id, or null if it can't be found
-
getLoadedProject
public Project getLoadedProject(long id)
Gets the required project, assuming it has already been leaded.- Parameters:
id
- the id of the project- Returns:
- null if the project is not loaded yet.
-
getPreferenceStore
public PreferenceStore getPreferenceStore()
Gets the preference store
-
getHistoryEntryManager
public abstract HistoryEntryManager getHistoryEntryManager()
The history entry manager deals with changes- Returns:
- manager for handling history
-
deleteProject
public void deleteProject(Project project)
Remove the project from the data store
-
deleteProject
public abstract void deleteProject(long projectID)
Remove project from data store
-
removeProject
protected void removeProject(long projectID)
Removes project from memory
-
addLatestExpression
public void addLatestExpression(String s)
Add the latest expression to the preference store
-
preparePreferenceStore
protected static void preparePreferenceStore(PreferenceStore ps)
-
-