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 void
close()
Shutdown the databaseIWorkspace
createWorkspace(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 implementationEmbeddedDatabase
getDatabase()
ReportManager
getReportGenerator(IResultJob resultJob)
Returns a prepared report manager for the IResultJob, uses cached instances were possibleISourceFile
getSourceFile(long persistentId)
Fetches instance of theISourceFile
for the unique id passedISubmission
getSubmissionFromName(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)
void
mergePendingSubmission(ISubmission existing, ISubmission pending)
Merge two submissions into a single submission, can be used to sort out name collisionsvoid
removePendingSubmission(ISubmission pendingSubmission)
Forget and remove a pending submission, and cleans up after itboolean
storeCodeBlockGroups(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 filevoid
writePendingSubmission(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:IStorageWrapper
Shutdown the database- Specified by:
close
in interfaceIStorageWrapper
-
createWorkspace
public IWorkspace createWorkspace(java.lang.String name, java.lang.String lang)
Description copied from interface:IStorageWrapper
Create a new IWorkspace instance- Specified by:
createWorkspace
in 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:IStorageWrapper
Fetches the class of ICodeBlockGroup used in this IStorageWrapper implementation- Specified by:
getCodeBlockGroupClass
in interfaceIStorageWrapper
- Returns:
- class for ICodeBlockGroup
-
getReportGenerator
public ReportManager getReportGenerator(IResultJob resultJob) throws ResultJobUnsupportedException
Description copied from interface:IStorageWrapper
Returns a prepared report manager for the IResultJob, uses cached instances were possible- Specified by:
getReportGenerator
in 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:ISourceFileHelper
Fetches instance of theISourceFile
for the unique id passed- Specified by:
getSourceFile
in 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:IStorageWrapper
Fetches a submission for the passed name if one exists, else returns null- Specified by:
getSubmissionFromName
in 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:
getWorkspaces
in 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:IStorageWrapper
Get all stored workspaces- Specified by:
getWorkspaces
in interfaceIStorageWrapper
- Returns:
- a list of all workspaces in the database
-
mergePendingSubmission
public void mergePendingSubmission(ISubmission existing, ISubmission pending) throws SubmissionUnsupportedException
Description copied from interface:IStorageWrapper
Merge two submissions into a single submission, can be used to sort out name collisions- Specified by:
mergePendingSubmission
in 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:IStorageWrapper
Forget and remove a pending submission, and cleans up after it- Specified by:
removePendingSubmission
in 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:IStorageWrapper
Stores the passed code block groups to the database- Specified by:
storeCodeBlockGroups
in 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:IStorageWrapper
Store file- Specified by:
storeFile
in 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:IStorageWrapper
Store file- Specified by:
storeFile
in 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:IStorageWrapper
If 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:
writePendingSubmission
in 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()
-
-