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:
parent
367c86fdd4
commit
c72b4571a5
@ -49,6 +49,11 @@ public abstract class ProjectManager {
|
|||||||
return _interProjectModel;
|
return _interProjectModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the project in the memory of the current session
|
||||||
|
* @param project
|
||||||
|
* @param projectMetadata
|
||||||
|
*/
|
||||||
public void registerProject(Project project, ProjectMetadata projectMetadata) {
|
public void registerProject(Project project, ProjectMetadata projectMetadata) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
_projects.put(project.id, project);
|
_projects.put(project.id, project);
|
||||||
@ -80,12 +85,21 @@ public abstract class ProjectManager {
|
|||||||
*/
|
*/
|
||||||
public abstract void exportProject(long projectId, TarOutputStream tos) throws IOException;
|
public abstract void exportProject(long projectId, TarOutputStream tos) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
public abstract void ensureProjectSaved(long id);
|
public abstract void ensureProjectSaved(long id);
|
||||||
|
|
||||||
public ProjectMetadata getProjectMetadata(long id) {
|
public ProjectMetadata getProjectMetadata(long id) {
|
||||||
return _projectsMetadata.get(id);
|
return _projectsMetadata.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public ProjectMetadata getProjectMetadata(String name) {
|
public ProjectMetadata getProjectMetadata(String name) {
|
||||||
for (ProjectMetadata pm : _projectsMetadata.values()) {
|
for (ProjectMetadata pm : _projectsMetadata.values()) {
|
||||||
if (pm.getName().equals(name)) {
|
if (pm.getName().equals(name)) {
|
||||||
@ -95,6 +109,13 @@ public abstract class ProjectManager {
|
|||||||
return null;
|
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) {
|
public long getProjectID(String name) {
|
||||||
for (Entry<Long, ProjectMetadata> entry : _projectsMetadata.entrySet()) {
|
for (Entry<Long, ProjectMetadata> entry : _projectsMetadata.entrySet()) {
|
||||||
if (entry.getValue().getName().equals(name)) {
|
if (entry.getValue().getName().equals(name)) {
|
||||||
@ -109,8 +130,33 @@ public abstract class ProjectManager {
|
|||||||
return _projectsMetadata;
|
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) {
|
public void setBusy(boolean busy) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (busy) {
|
if (busy) {
|
||||||
@ -141,6 +187,10 @@ public abstract class ProjectManager {
|
|||||||
*/
|
*/
|
||||||
public abstract void save(boolean b);
|
public abstract void save(boolean b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the project from the data store
|
||||||
|
* @param project
|
||||||
|
*/
|
||||||
public void deleteProject(Project project) {
|
public void deleteProject(Project project) {
|
||||||
deleteProject(project.id);
|
deleteProject(project.id);
|
||||||
}
|
}
|
||||||
@ -149,7 +199,16 @@ public abstract class ProjectManager {
|
|||||||
* Remove project from data store
|
* Remove project from data store
|
||||||
* @param projectID
|
* @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
|
* The history entry manager deals with changes
|
||||||
|
@ -209,18 +209,9 @@ public class FileProjectManager extends ProjectManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Project getProject(long id) {
|
@Override
|
||||||
synchronized (this) {
|
public Project loadProject(long id) {
|
||||||
if (_projects.containsKey(id)) {
|
return ProjectUtilities.load(getProjectDir(id), id);
|
||||||
return _projects.get(id);
|
|
||||||
} else {
|
|
||||||
Project project = ProjectUtilities.load(getProjectDir(id), id);
|
|
||||||
|
|
||||||
_projects.put(id, project);
|
|
||||||
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(boolean allModified) {
|
public void save(boolean allModified) {
|
||||||
@ -373,12 +364,7 @@ public class FileProjectManager extends ProjectManager {
|
|||||||
|
|
||||||
public void deleteProject(long projectID) {
|
public void deleteProject(long projectID) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_projectsMetadata.containsKey(projectID)) {
|
removeProject(projectID);
|
||||||
_projectsMetadata.remove(projectID);
|
|
||||||
}
|
|
||||||
if (_projects.containsKey(projectID)) {
|
|
||||||
_projects.remove(projectID);
|
|
||||||
}
|
|
||||||
|
|
||||||
File dir = getProjectDir(projectID);
|
File dir = getProjectDir(projectID);
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user