Functionality which didn't need to be moved to FileProjectManager as it wasn't file system specific has been moved back to ProjectManager.

Some additional source code documentation added.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@991 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Iain Sproat 2010-06-18 19:16:30 +00:00
parent 367c86fdd4
commit c72b4571a5
2 changed files with 75 additions and 30 deletions

View File

@ -49,6 +49,11 @@ public abstract class ProjectManager {
return _interProjectModel;
}
/**
* Registers the project in the memory of the current session
* @param project
* @param projectMetadata
*/
public void registerProject(Project project, ProjectMetadata projectMetadata) {
synchronized (this) {
_projects.put(project.id, project);
@ -80,12 +85,21 @@ public abstract class ProjectManager {
*/
public abstract void exportProject(long projectId, TarOutputStream tos) throws IOException;
/**
*
* @param id
*/
public abstract void ensureProjectSaved(long id);
public ProjectMetadata getProjectMetadata(long id) {
return _projectsMetadata.get(id);
}
/**
*
* @param name
* @return
*/
public ProjectMetadata getProjectMetadata(String name) {
for (ProjectMetadata pm : _projectsMetadata.values()) {
if (pm.getName().equals(name)) {
@ -95,6 +109,13 @@ public abstract class ProjectManager {
return null;
}
/**
* Tries to find the project id when given a project name
* @param name
* The name of the project
* @return
* The id of the project, or -1 if it cannot be found
*/
public long getProjectID(String name) {
for (Entry<Long, ProjectMetadata> entry : _projectsMetadata.entrySet()) {
if (entry.getValue().getName().equals(name)) {
@ -109,8 +130,33 @@ public abstract class ProjectManager {
return _projectsMetadata;
}
public abstract Project getProject(long parseLong);
/**
* Gets the required project from the data store
* @param id
* the id of the project
* @return
* the project with the matching id, or null if it can't be found
*/
public Project getProject(long id) {
synchronized (this) {
if (_projects.containsKey(id)) {
return _projects.get(id);
} else {
Project project = loadProject(id);
_projects.put(id, project);
return project;
}
}
}
protected abstract Project loadProject(long id);
/**
* Sets the flag for long running operations
* @param busy
*/
public void setBusy(boolean busy) {
synchronized (this) {
if (busy) {
@ -141,6 +187,10 @@ public abstract class ProjectManager {
*/
public abstract void save(boolean b);
/**
* Remove the project from the data store
* @param project
*/
public void deleteProject(Project project) {
deleteProject(project.id);
}
@ -149,7 +199,16 @@ public abstract class ProjectManager {
* Remove project from data store
* @param projectID
*/
public abstract void deleteProject(long projectID) ;
public abstract void deleteProject(long projectID);
protected void removeProject(long projectID){
if (_projectsMetadata.containsKey(projectID)) {
_projectsMetadata.remove(projectID);
}
if (_projects.containsKey(projectID)) {
_projects.remove(projectID);
}
}
/**
* The history entry manager deals with changes

View File

@ -209,18 +209,9 @@ public class FileProjectManager extends ProjectManager {
}
}
public Project getProject(long id) {
synchronized (this) {
if (_projects.containsKey(id)) {
return _projects.get(id);
} else {
Project project = ProjectUtilities.load(getProjectDir(id), id);
_projects.put(id, project);
return project;
}
}
@Override
public Project loadProject(long id) {
return ProjectUtilities.load(getProjectDir(id), id);
}
public void save(boolean allModified) {
@ -373,12 +364,7 @@ public class FileProjectManager extends ProjectManager {
public void deleteProject(long projectID) {
synchronized (this) {
if (_projectsMetadata.containsKey(projectID)) {
_projectsMetadata.remove(projectID);
}
if (_projects.containsKey(projectID)) {
_projects.remove(projectID);
}
removeProject(projectID);
File dir = getProjectDir(projectID);
if (dir.exists()) {