Class SystemMetadataManager

java.lang.Object
edu.ucsb.nceas.metacat.systemmetadata.SystemMetadataManager

public class SystemMetadataManager extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    convertPermission(org.dataone.service.types.v1.Permission permission)
    Utility method to convert a permission object to an integer
    void
    delete(org.dataone.service.types.v1.Identifier id)
    Delete a system metadata record from the store.
    void
    delete(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.SystemMetadata
    get(org.dataone.service.types.v1.Identifier pid)
    Get the system metadata associated with the given identifier from the store.
    Get the singleton SystemMetadataManager instance
    static void
    lock(org.dataone.service.types.v1.Identifier pid)
    Lock a PID so only one thread can modify the system metadata in database/file system.
    protected void
    Reset the manager instance to null.
    void
    store(org.dataone.service.types.v2.SystemMetadata sysmeta)
    Store a system metadata record into the store Note: This method is not thread safe.
    void
    store(org.dataone.service.types.v2.SystemMetadata sysmeta, boolean changeModifyTime, DBConnection dbConn, SystemMetadataManager.SysMetaVersion sysMetaCheck)
    Store a system metadata record into the store.
    void
    store(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 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
    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
    protected void
    updateSystemMetadata(org.dataone.service.types.v2.SystemMetadata sm, DBConnection dbConn)
    Insert the system metadata fields into the db

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getInstance

      public static SystemMetadataManager 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.InvalidRequest
      org.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 inserted
      changeModifyTime - if we need to change the modify time
      sysMetaCheck - check whether the version of the provided '@param sysmeta' matches the version of the existing metadata
      Throws:
      org.dataone.service.exceptions.InvalidRequest
      org.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 inserted
      changeModifyTime - if we need to change the modify time
      dbConn - the db connection will be used during storing the system metadata into db
      sysMetaCheck - if Metacat needs to check the version of the coming system metadata matching the version of the existing one.
      Throws:
      org.dataone.service.exceptions.InvalidRequest
      org.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 save
      e - the exception causes the failure of store.
      conn - the connection used to store system metadata into database
      backupCopies - 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

      public static void lock(org.dataone.service.types.v1.Identifier pid) throws RuntimeException
      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.InvalidRequest
      org.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:
      McdbDocNotFoundException
      SQLException
      org.dataone.service.exceptions.InvalidSystemMetadata
      AccessException
    • 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 deleted
      dbConn - the DBConnection object which will execute the delete actions
      Throws:
      org.dataone.service.exceptions.InvalidRequest
      SQLException
      org.dataone.service.exceptions.ServiceFailure
    • refreshInstance

      protected void refreshInstance()
      Reset the manager instance to null. This is for testing only!