Class SystemMetadataManager
java.lang.Object
edu.ucsb.nceas.metacat.systemmetadata.SystemMetadataManager
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic intconvertPermission(org.dataone.service.types.v1.Permission permission) Utility method to convert a permission object to an integervoiddelete(org.dataone.service.types.v1.Identifier id) Delete a system metadata record from the store.voiddelete(org.dataone.service.types.v1.Identifier guid, DBConnection dbConn) Delete the system metadata for the given guid with the DBConnection object.org.dataone.service.types.v2.SystemMetadataget(org.dataone.service.types.v1.Identifier pid) Get the system metadata associated with the given identifier from the store.static SystemMetadataManagerGet the singleton SystemMetadataManager instancestatic voidlock(org.dataone.service.types.v1.Identifier pid) Lock a PID so only one thread can modify the system metadata in database/file system.protected voidReset the manager instance to null.voidstore(org.dataone.service.types.v2.SystemMetadata sysmeta) Store a system metadata record into the store Note: This method is not thread safe.voidstore(org.dataone.service.types.v2.SystemMetadata sysmeta, boolean changeModifyTime, DBConnection dbConn, SystemMetadataManager.SysMetaVersion sysMetaCheck) Store a system metadata record into the store.voidstore(org.dataone.service.types.v2.SystemMetadata sysmeta, boolean changeModifyTime, SystemMetadataManager.SysMetaVersion sysMetaCheck) Store a system metadata record into the store Note: This method is not thread safe.static StringstoreRollBack(org.dataone.service.types.v1.Identifier pid, Exception e, DBConnection conn, org.dataone.service.types.v2.SystemMetadata... backupCopies) RollBack the change in database and hashtore when the store methods failedstatic voidunLock(org.dataone.service.types.v1.Identifier pid) Unlock a pid so allow another thread to modify the system metadata in database/file system Note: put this method in the final block while put the lock and store method in the try blockprotected voidupdateSystemMetadata(org.dataone.service.types.v2.SystemMetadata sm, DBConnection dbConn) Insert the system metadata fields into the db
-
Method Details
-
getInstance
Get the singleton SystemMetadataManager instance- Returns:
- the instance of SystemMetadataManager
-
get
public org.dataone.service.types.v2.SystemMetadata get(org.dataone.service.types.v1.Identifier pid) throws org.dataone.service.exceptions.ServiceFailure Get the system metadata associated with the given identifier from the store. If the returned value is null, this means the system metadata is not found- Parameters:
pid- the identifier to determine the system metadata- Returns:
- the system metadata associated with the given identifier
- Throws:
org.dataone.service.exceptions.ServiceFailure
-
store
public void store(org.dataone.service.types.v2.SystemMetadata sysmeta) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure Store a system metadata record into the store Note: This method is not thread safe. Please put it into a try-finally statement. Before call this method, you need to call the lock method first in the `try` block and unLock method in the `finally` block. The modification time will be changed and system metadata version will be checked during the process- Parameters:
sysmeta- the new system metadata will be inserted- Throws:
org.dataone.service.exceptions.InvalidRequestorg.dataone.service.exceptions.ServiceFailure
-
store
public void store(org.dataone.service.types.v2.SystemMetadata sysmeta, boolean changeModifyTime, SystemMetadataManager.SysMetaVersion sysMetaCheck) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure Store a system metadata record into the store Note: This method is not thread safe. Please put it into a try-finally statement. Before call this method, you need to call the lock method first in the `try` block and unLock method in the `finally` block.- Parameters:
sysmeta- the new system metadata will be insertedchangeModifyTime- if we need to change the modify timesysMetaCheck- check whether the version of the provided '@param sysmeta' matches the version of the existing metadata- Throws:
org.dataone.service.exceptions.InvalidRequestorg.dataone.service.exceptions.ServiceFailure
-
store
public void store(org.dataone.service.types.v2.SystemMetadata sysmeta, boolean changeModifyTime, DBConnection dbConn, SystemMetadataManager.SysMetaVersion sysMetaCheck) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure Store a system metadata record into the store. Note: This method is not thread safe. Please put it into a try-finally statement. Before call this method, you need to call the lock method first in the `try` block and unLock method in the `finally` block. The calling code is responsible for (a) setting setAutoCommit(false) before passing the DBConnection, and (b) calling commit() after this method has finished execution.- Parameters:
sysmeta- the new system metadata will be insertedchangeModifyTime- if we need to change the modify timedbConn- the db connection will be used during storing the system metadata into dbsysMetaCheck- if Metacat needs to check the version of the coming system metadata matching the version of the existing one.- Throws:
org.dataone.service.exceptions.InvalidRequestorg.dataone.service.exceptions.ServiceFailure
-
storeRollBack
public static String storeRollBack(org.dataone.service.types.v1.Identifier pid, Exception e, DBConnection conn, org.dataone.service.types.v2.SystemMetadata... backupCopies) RollBack the change in database and hashtore when the store methods failed- Parameters:
pid- the pid Metacat would like to savee- the exception causes the failure of store.conn- the connection used to store system metadata into databasebackupCopies- the original copies of system metadata before Metacat modified them- Returns:
- the error message. It combines both the main exception and exceptions occurs during the rollback process. If rollback doesn't have any exceptions, it only has the main exception message.
-
lock
Lock a PID so only one thread can modify the system metadata in database/file system. Note: put the lock and store method in the try block while the unLock method in the final block.- Parameters:
pid- the identifier which will be locked- Throws:
RuntimeException
-
unLock
public static void unLock(org.dataone.service.types.v1.Identifier pid) Unlock a pid so allow another thread to modify the system metadata in database/file system Note: put this method in the final block while put the lock and store method in the try block- Parameters:
pid- the identifier which will be unlocked
-
delete
public void delete(org.dataone.service.types.v1.Identifier id) throws org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure Delete a system metadata record from the store. Note: This method is not thread safe. Please put it into a try-finally statement. Before call this method, you need to call the lock method first in the `try` block and unLock method in the `finally` block.- Parameters:
id- the identifier to determine the system metadata record- Throws:
org.dataone.service.exceptions.InvalidRequestorg.dataone.service.exceptions.ServiceFailure
-
updateSystemMetadata
protected void updateSystemMetadata(org.dataone.service.types.v2.SystemMetadata sm, DBConnection dbConn) throws McdbDocNotFoundException, SQLException, org.dataone.service.exceptions.InvalidSystemMetadata, AccessException Insert the system metadata fields into the db- Parameters:
sm-- Throws:
McdbDocNotFoundExceptionSQLExceptionorg.dataone.service.exceptions.InvalidSystemMetadataAccessException
-
convertPermission
public static int convertPermission(org.dataone.service.types.v1.Permission permission) Utility method to convert a permission object to an integer- Parameters:
permission- the permission which needs to be convert- Returns:
- the integer presentation of the permission
-
delete
public void delete(org.dataone.service.types.v1.Identifier guid, DBConnection dbConn) throws org.dataone.service.exceptions.InvalidRequest, SQLException, org.dataone.service.exceptions.ServiceFailure Delete the system metadata for the given guid with the DBConnection object. It doesn't delete the system metadata in hashstore. The caller should do the job. Note: This method is not thread safe. Please put it into a try-finally statement. Before call this method, you need to call the lock method first in the `try` block and unLock method in the `finally` block.- Parameters:
guid- the identifier of the object whose system metadata will be deleteddbConn- the DBConnection object which will execute the delete actions- Throws:
org.dataone.service.exceptions.InvalidRequestSQLExceptionorg.dataone.service.exceptions.ServiceFailure
-
refreshInstance
protected void refreshInstance()Reset the manager instance to null. This is for testing only!
-