Class SystemPersistenceManagerImpl

  • All Implemented Interfaces:
    SystemPersistenceManager

    @Eager
    @ApplicationScoped
    public class SystemPersistenceManagerImpl
    extends Object
    implements SystemPersistenceManager
    Implementation of the SystemPersistenceManager interface. This class is responsible for managing the lifecycle of the EntityManagerFactory for the system persistence unit, as well as providing access to the DataSource and handling schema and encryption migrations. It listens to events related to the health of the system database and reacts accordingly by opening or closing the EntityManagerFactory. It also provides methods to suspend and resume the persistence layer, which can be used during maintenance operations. The class ensures that all operations that modify the state of the persistence layer are synchronized to prevent concurrent modifications and ensure thread safety.
    Since:
    8.5.0
    Author:
    Michael Kohlsche
    • Method Detail

      • getDataSourceInfo

        public IDataSourceInfo getDataSourceInfo()
                                          throws FcPersistenceException
        Description copied from interface: SystemPersistenceManager
        Retrieves information about the system data source, such as database type, version, encryption settings, and other metadata. This information can be used for diagnostics, monitoring, or to make decisions about how to interact with the database based on its capabilities and configuration.
        Specified by:
        getDataSourceInfo in interface SystemPersistenceManager
        Returns:
        an IDataSourceInfo object containing metadata about the system data source
        Throws:
        FcPersistenceException - if there is an error while retrieving the data source information, such as if the data source cannot be accessed or if there is an error related to the database driver
      • suspend

        public void suspend()
        Description copied from interface: SystemPersistenceManager
        Suspends the system persistence layer, releasing any resources held by the EntityManagerFactory and DataSource. This method should be called before performing operations that require exclusive access to the database, such as schema migrations or encryption changes. After the necessary operations are completed, the SystemPersistenceManager.resume() method should be called to reinitialize the persistence layer.
        Specified by:
        suspend in interface SystemPersistenceManager
      • resume

        public void resume()
        Description copied from interface: SystemPersistenceManager
        Resumes the system persistence layer after it has been suspended. This method triggers a system persistence layer check which will fire appropriate events to reinitialize the EntityManagerFactory and DataSource if they were released during suspension. This method should be called after performing operations that required exclusive access to the database, such as schema migrations or encryption changes, to restore the normal operation of the persistence layer.
        Specified by:
        resume in interface SystemPersistenceManager
      • reloadEncryptionSettings

        public void reloadEncryptionSettings()
                                      throws FcPersistenceException
        Description copied from interface: SystemPersistenceManager
        Reloads the encryption settings for the system data source. This method should be called after changing the encryption settings (e.g., password, algorithm) to ensure that the new settings are applied and used for all subsequent database operations. This may involve reinitializing the DataSource and EntityManagerFactory to use the updated encryption configuration.
        Specified by:
        reloadEncryptionSettings in interface SystemPersistenceManager
        Throws:
        FcPersistenceException - if there is an error related to the persistence layer while reloading the encryption settings, such as if the DataSource cannot be reinitialized with the new settings or if there is an error related to the database driver
      • migrateEncryption

        public void migrateEncryption​(char[] newEncryptionPassword,
                                      String newEncryptionAlgorithm,
                                      Set<String> additionalEncryptionScopes)
                               throws FcPersistenceException
        Description copied from interface: SystemPersistenceManager
        Migrates the encryption of the system data source to use a new encryption password and algorithm. This method should be used when changing the encryption settings for the system database. It reads all encrypted data with the old settings and re-encrypts it using the new settings.
        Specified by:
        migrateEncryption in interface SystemPersistenceManager
        Parameters:
        newEncryptionPassword - the new encryption password to be used
        newEncryptionAlgorithm - the new encryption algorithm to be used
        additionalEncryptionScopes - optional scopes for encryption; can be null or empty; if null, only unscoped data will be re-encrypted. If not null, data with the specified scopes will also be re-encrypted. Example scope: "form" for form data encryption.
        Throws:
        FcPersistenceException - f there is an error during the migration process
      • getDataSourceEncryptionState

        public DataSourceEncryptionState getDataSourceEncryptionState​(ConnectionProperties connectionProperties,
                                                                      char[] password,
                                                                      String encryptionAlgorithm)
                                                               throws FcPersistenceException
        Description copied from interface: SystemPersistenceManager
        Checks the encryption state of the data source defined by the given connection properties. This method verifies whether the encryption settings (password, algorithm) match those used to encrypt the data in the database.
        Specified by:
        getDataSourceEncryptionState in interface SystemPersistenceManager
        Parameters:
        connectionProperties - the connection properties defining the data source to check
        password - the password to check against the system data source encryption
        encryptionAlgorithm - the encryption algorithm to check against the system data source encryption
        Returns:
        the encryption state of the system data source
        Throws:
        FcDriverException - if there is an error related to the database driver
        FcPersistenceException
      • isSchemaMigrationRunning

        public boolean isSchemaMigrationRunning()
      • isEncryptionMigrationRunning

        public boolean isEncryptionMigrationRunning()
      • isSuspended

        public boolean isSuspended()
      • getEntityManagerFactoryRuntime

        public de.xima.fc.persistence.impl.EntityManagerFactoryRuntime getEntityManagerFactoryRuntime()