Class DatabasePropertiesFile


  • public final class DatabasePropertiesFile
    extends Object
    Represents our 'database.properties' file and manipulations with it.
    Since:
    8.0
    Author:
    Leonid Bushuev from JetBrains
    • Constructor Detail

      • DatabasePropertiesFile

        public DatabasePropertiesFile​(@NotNull
                                      File dataDir)
        Constructs the class for a properties file in the default location.
        Parameters:
        dataDir - the TeamCity Data Directory.
      • DatabasePropertiesFile

        public DatabasePropertiesFile​(@NotNull
                                      File dataDir,
                                      @NotNull
                                      Map<String,​String> environment)
        Constructs the class for a properties file in the default location.
        Parameters:
        dataDir - the TeamCity Data Directory.
        environment - process environment
        Since:
        2023.11
    • Method Detail

      • refreshState

        public void refreshState​(boolean setupExplicitly)

        For all origins except virtual, re-reads the database properties from disk, optionally falling back to the default (HSQL) connection if the custom "database.properties" doesn't exist.

        If the underlying file exists, the setupExplicitly parameter is ignored. If the "database.properties" file doesn't exist and setupExplicitly is false, this method does nothing.

        If the current origin is virtual, the file is ignored if it exists, the setupExplicitly parameter is ignored, too, and the default (HSQL) connection is always used.

        Parameters:
        setupExplicitly - whether database properties should be initialized with the default (HSQL) connection in case "database.properties" doesn't exist.
      • removeExtraSpacesFromPropertiesValues

        public static void removeExtraSpacesFromPropertiesValues​(@NotNull
                                                                 Properties properties)
        Workarounds a problem (feature aka bug) in java.util.Properties#load0(java.util.Properties.LineReader) with trailing white spaces.
        Parameters:
        properties - a set of properties; their values will be truncated in place.
      • getDataDir

        @NotNull
        public File getDataDir()
      • getFile

        @NotNull
        public File getFile()
      • isConfigurationPresent

        public boolean isConfigurationPresent()
        Returns:
        true if database properties were configured, either via properties file or via environment variables, or both
        Since:
        2023.11
      • isFileExists

        public boolean isFileExists()
      • getProperties

        @Nullable
        public Properties getProperties()
      • getDatabaseType

        @NotNull
        public DatabaseType getDatabaseType()
      • getExplicitConnectionDescription

        @NotNull
        public String getExplicitConnectionDescription​(boolean html)
        It is supposed to use this method as "TeamCity database is" + getExplicitConnectionDescription(false)
        Returns:
        textual description of the explicit DB configuration, see above
      • hasDatabaseUrlInEnvironment

        public static boolean hasDatabaseUrlInEnvironment​(Map<String,​String> environment)
      • getSpecifiedHsqlMajorVersion

        public int getSpecifiedHsqlMajorVersion()
      • getConnectionUrl

        @NotNull
        public String getConnectionUrl()