Class BaseStorage
- java.lang.Object
-
- uk.ac.warwick.dcs.sherlock.engine.storage.BaseStorage
-
- All Implemented Interfaces:
ISourceFileHelper,IStorageWrapper
public class BaseStorage extends java.lang.Object implements IStorageWrapper
Basic storage implementation
-
-
Constructor Summary
Constructors Constructor Description BaseStorage()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Shutdown the databaseIWorkspacecreateWorkspace(java.lang.String name, java.lang.String lang)Create a new IWorkspace instancejava.lang.Class<? extends ICodeBlockGroup>getCodeBlockGroupClass()Fetches the class of ICodeBlockGroup used in this IStorageWrapper implementationEmbeddedDatabasegetDatabase()ReportManagergetReportGenerator(IResultJob resultJob)Returns a prepared report manager for the IResultJob, uses cached instances were possibleISourceFilegetSourceFile(long persistentId)Fetches instance of theISourceFilefor the unique id passedISubmissiongetSubmissionFromName(IWorkspace workspace, java.lang.String submissionName)Fetches a submission for the passed name if one exists, else returns nulljava.util.List<IWorkspace>getWorkspaces()Get all stored workspacesjava.util.List<IWorkspace>getWorkspaces(java.util.List<java.lang.Long> ids)voidmergePendingSubmission(ISubmission existing, ISubmission pending)Merge two submissions into a single submission, can be used to sort out name collisionsvoidremovePendingSubmission(ISubmission pendingSubmission)Forget and remove a pending submission, and cleans up after itbooleanstoreCodeBlockGroups(java.util.List<ICodeBlockGroup> groups)Stores the passed code block groups to the databasejava.util.List<ITuple<ISubmission,ISubmission>>storeFile(IWorkspace workspace, java.lang.String filename, byte[] fileContent)Store filejava.util.List<ITuple<ISubmission,ISubmission>>storeFile(IWorkspace workspace, java.lang.String filename, byte[] fileContent, boolean archiveContainsMultipleSubmissions)Store filevoidwritePendingSubmission(ISubmission pendingSubmission)If the submission clashes with an already existing submission, it will be set as pending
-
-
-
Method Detail
-
close
public void close()
Description copied from interface:IStorageWrapperShutdown the database- Specified by:
closein interfaceIStorageWrapper
-
createWorkspace
public IWorkspace createWorkspace(java.lang.String name, java.lang.String lang)
Description copied from interface:IStorageWrapperCreate a new IWorkspace instance- Specified by:
createWorkspacein interfaceIStorageWrapper- Parameters:
name- name to create workspace underlang- language of the workspace- Returns:
- instance
-
getCodeBlockGroupClass
public java.lang.Class<? extends ICodeBlockGroup> getCodeBlockGroupClass()
Description copied from interface:IStorageWrapperFetches the class of ICodeBlockGroup used in this IStorageWrapper implementation- Specified by:
getCodeBlockGroupClassin interfaceIStorageWrapper- Returns:
- class for ICodeBlockGroup
-
getReportGenerator
public ReportManager getReportGenerator(IResultJob resultJob) throws ResultJobUnsupportedException
Description copied from interface:IStorageWrapperReturns a prepared report manager for the IResultJob, uses cached instances were possible- Specified by:
getReportGeneratorin interfaceIStorageWrapper- Parameters:
resultJob- result to generate reports for- Returns:
- instance of ReportManager
- Throws:
ResultJobUnsupportedException- Thrown if IResultJob instance was not created by this IStorageWrapper implementation
-
getSourceFile
public ISourceFile getSourceFile(long persistentId)
Description copied from interface:ISourceFileHelperFetches instance of theISourceFilefor the unique id passed- Specified by:
getSourceFilein interfaceISourceFileHelper- Parameters:
persistentId- unique id of the file- Returns:
- instance
-
getSubmissionFromName
public ISubmission getSubmissionFromName(IWorkspace workspace, java.lang.String submissionName) throws WorkspaceUnsupportedException
Description copied from interface:IStorageWrapperFetches a submission for the passed name if one exists, else returns null- Specified by:
getSubmissionFromNamein interfaceIStorageWrapper- Parameters:
workspace- workspace to search for submissionsubmissionName- submission name- Returns:
- submission if exists, else null
- Throws:
WorkspaceUnsupportedException- Thrown if IWorkspace instance was not created by this IStorageWrapper implementation
-
getWorkspaces
public java.util.List<IWorkspace> getWorkspaces(java.util.List<java.lang.Long> ids)
- Specified by:
getWorkspacesin interfaceIStorageWrapper- Parameters:
ids- workspace ids to fetch- Returns:
- a list of all workspaces matching the passed ids in the database
-
getWorkspaces
public java.util.List<IWorkspace> getWorkspaces()
Description copied from interface:IStorageWrapperGet all stored workspaces- Specified by:
getWorkspacesin interfaceIStorageWrapper- Returns:
- a list of all workspaces in the database
-
mergePendingSubmission
public void mergePendingSubmission(ISubmission existing, ISubmission pending) throws SubmissionUnsupportedException
Description copied from interface:IStorageWrapperMerge two submissions into a single submission, can be used to sort out name collisions- Specified by:
mergePendingSubmissionin interfaceIStorageWrapper- Parameters:
existing- first submission, is left, must already exist in the databasepending- second submission, is removed after merge- Throws:
SubmissionUnsupportedException- Thrown if ISubmission instance was not created by this IStorageWrapper implementation
-
removePendingSubmission
public void removePendingSubmission(ISubmission pendingSubmission) throws SubmissionUnsupportedException
Description copied from interface:IStorageWrapperForget and remove a pending submission, and cleans up after it- Specified by:
removePendingSubmissionin interfaceIStorageWrapper- Parameters:
pendingSubmission- pending submission to forget and remove- Throws:
SubmissionUnsupportedException- Thrown if ISubmission instance was not created by this IStorageWrapper implementation
-
storeCodeBlockGroups
public boolean storeCodeBlockGroups(java.util.List<ICodeBlockGroup> groups)
Description copied from interface:IStorageWrapperStores the passed code block groups to the database- Specified by:
storeCodeBlockGroupsin interfaceIStorageWrapper- Parameters:
groups- list of the code block groups to store- Returns:
- was successful?
-
storeFile
public java.util.List<ITuple<ISubmission,ISubmission>> storeFile(IWorkspace workspace, java.lang.String filename, byte[] fileContent) throws WorkspaceUnsupportedException
Description copied from interface:IStorageWrapperStore file- Specified by:
storeFilein interfaceIStorageWrapper- Parameters:
workspace- workspace to upload file tofilename- filename uploaded, used as the identifier to show to the user, identifying the file or filesfileContent- raw content of the file- Returns:
- list of tuples, which contain any collisions between submission names. The first element is the existing submission, the second is the new
- Throws:
WorkspaceUnsupportedException- Thrown if IWorkspace instance was not created by this IStorageWrapper implementation
-
storeFile
public java.util.List<ITuple<ISubmission,ISubmission>> storeFile(IWorkspace workspace, java.lang.String filename, byte[] fileContent, boolean archiveContainsMultipleSubmissions) throws WorkspaceUnsupportedException
Description copied from interface:IStorageWrapperStore file- Specified by:
storeFilein interfaceIStorageWrapper- Parameters:
workspace- workspace to upload file tofilename- filename uploaded, used as the identifier to show to the user, identifying the file or filesfileContent- raw content of the filearchiveContainsMultipleSubmissions- are the archive top level directories separate submissions?- Returns:
- list of tuples, which contain any collisions between submission names. The first element is the existing submission, the second is the new
- Throws:
WorkspaceUnsupportedException- Thrown if IWorkspace instance was not created by this IStorageWrapper implementation
-
writePendingSubmission
public void writePendingSubmission(ISubmission pendingSubmission) throws SubmissionUnsupportedException
Description copied from interface:IStorageWrapperIf the submission clashes with an already existing submission, it will be set as pendingIF a submission is pending this method will remove existing submission with the same name and write the pending submission to the database
- Specified by:
writePendingSubmissionin interfaceIStorageWrapper- Parameters:
pendingSubmission- pending submission to properly write- Throws:
SubmissionUnsupportedException- Thrown if ISubmission instance was not created by this IStorageWrapper implementation
-
getDatabase
public EmbeddedDatabase getDatabase()
-
-