Class ConfigDatabaseLogic

java.lang.Object
edu.internet2.middleware.grouperClient.config.db.ConfigDatabaseLogic

public class ConfigDatabaseLogic extends Object
logic to cache and retrieve the grouper config from the DB note: do not use any Grouper classes in this class. Cant use anything that could use anything configurable. This class has some config which will be injected from the outside there should be no imports here
  • Field Details

    • DATABASE_CACHE_KEY

      public static String DATABASE_CACHE_KEY
      database cache key
    • databaseConfigRefreshCount

      public static int databaseConfigRefreshCount
      keep this for testing
  • Constructor Details

    • ConfigDatabaseLogic

      public ConfigDatabaseLogic()
  • Method Details

    • clearCache

      public static void clearCache()
    • clearCache

      public static void clearCache(boolean checkConfigTableExists)
    • main

      public static void main(String[] args)
      Parameters:
      args -
    • assignSecondsBetweenUpdateChecksToDb

      public static void assignSecondsBetweenUpdateChecksToDb(int theSeconds)
      seconds between checking to see if the config files are updated in the database. If anything edited, then refresh all. Note that the last edited is stored in a config property for deletes. -1 means dont check for incrementals. Note if *.config.secondsBetweenUpdateChecks is greater than this number for this config, then it wont update until that amount has passed. grouper.config.secondsBetweenUpdateChecksToDb = 60
      Parameters:
      theSeconds -
    • assignReadonly

      public static void assignReadonly(boolean theReadonly)
      set the API as readonly (e.g. during upgrades). Any updates will throw an exception grouper.api.readonly = false
      Parameters:
      theReadonly -
    • assignSecondsBetweenFullRefresh

      public static void assignSecondsBetweenFullRefresh(int theSeconds)
      Parameters:
      theSeconds -
    • retrieveConfigInputStream

      public static InputStream retrieveConfigInputStream(String mainConfigFileName)
      Parameters:
      mainConfigFileName - configPropertiesCascadeBase.getMainConfigFileName() e.g. grouper.properties
      Returns:
      the inputStream for this config's properties
    • retrieveConfigMap

      public static Map<String,String> retrieveConfigMap(String mainConfigFileName)
      Parameters:
      mainConfigFileName - configPropertiesCascadeBase.getMainConfigFileName() e.g. grouper.properties
      Returns:
      the inputStream for this config's properties
    • sha256

      public static String sha256(String input)
      get hash for db creds
      Parameters:
      input -
      Returns:
      bytes
    • toHexString

      public static String toHexString(byte[] hash)
      Parameters:
      hash -
      Returns:
      string
    • equals

      public static boolean equals(String first, String second)
      null safe string compare
      Parameters:
      first -
      second -
      Returns:
      true if equal
    • nullOrBlank

      public static boolean nullOrBlank(Object object)
      is an object null or blank
      Parameters:
      object -
      Returns:
      true if null or blank
    • booleanValue

      public static boolean booleanValue(Object object)
      get the boolean value for an object, cant be null or blank
      Parameters:
      object -
      Returns:
      the boolean
    • mapToString

      public static String mapToString(Map map)
      convert a set to a string (comma separate)
      Parameters:
      map -
      Returns:
      the String
    • closeQuietly

      public static void closeQuietly(Connection theConnection)
      close a connection null safe and dont throw exception
      Parameters:
      theConnection -
    • closeQuietly

      public static void closeQuietly(InputStream input)
      Unconditionally close an InputStream. Equivalent to InputStream.close(), except any exceptions will be ignored.
      Parameters:
      input - A (possibly null) InputStream
    • closeQuietly

      public static void closeQuietly(Statement input)
      Unconditionally close an InputStream. Equivalent to InputStream.close(), except any exceptions will be ignored.
      Parameters:
      input - A (possibly null) InputStream
    • closeQuietly

      public static void closeQuietly(ResultSet resultSet)
      close a resultSet null safe and dont throw exception
      Parameters:
      resultSet -
    • isBlank

      public static boolean isBlank(Object input)
      See if the input is null or if string, if it is empty or blank (whitespace)
      Parameters:
      input -
      Returns:
      true if blank
    • isBlank

      public static boolean isBlank(String str)

      Checks if a String is whitespace, empty ("") or null.

       isBlank(null)      = true
       isBlank("")        = true
       isBlank(" ")       = true
       isBlank("bob")     = false
       isBlank("  bob  ") = false
       
      Parameters:
      str - the String to check, may be null
      Returns:
      true if the String is null, empty or whitespace
      Since:
      2.0
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(String str1, String str2)
      equalsignorecase
      Parameters:
      str1 -
      str2 -
      Returns:
      true if the strings are equal ignore case
    • booleanValue

      public static boolean booleanValue(Object object, boolean defaultBoolean)
      get the boolean value for an object
      Parameters:
      object -
      defaultBoolean - if object is null or empty
      Returns:
      the boolean
    • sleep

      public static void sleep(long millis)
      sleep, if interrupted, throw runtime
      Parameters:
      millis -
    • uuid

      public static String uuid()
      generate a uuid
      Returns:
      uuid
    • className

      public static String className(Object object)
      null safe classname method, gets the unenhanced name
      Parameters:
      object -
      Returns:
      the classname
    • longValue

      public static long longValue(Object input)
      convert an object to a long
      Parameters:
      input -
      Returns:
      the number
    • convertUrlToDriverClassIfNeeded

      public static String convertUrlToDriverClassIfNeeded(String connectionUrl, String driverClassName)
      if there is no driver class specified, then try to derive it from the URL
      Parameters:
      connectionUrl -
      driverClassName -
      Returns:
      the driver class
    • isMysql

      public static boolean isMysql(String connectionUrl)
      see if the config file seems to be mysql
      Parameters:
      connectionUrl -
      Returns:
      see if mysql
    • isOracle

      public static boolean isOracle(String connectionUrl)
      see if the config file seems to be oracle
      Parameters:
      connectionUrl -
      Returns:
      see if oracle
    • isPostgres

      public static boolean isPostgres(String connectionUrl)
      see if the config file seems to be postgres
      Parameters:
      connectionUrl -
      Returns:
      see if postgres
    • isSQLServer

      public static boolean isSQLServer(String connectionUrl)
      see if the config file seems to be sql server
      Parameters:
      connectionUrl -
      Returns:
      see if sql server
    • defaultString

      public static String defaultString(String str)

      Returns either the passed in String, or if the String is null, an empty String ("").

       StringUtils.defaultString(null)  = ""
       StringUtils.defaultString("")    = ""
       StringUtils.defaultString("bat") = "bat"
       
      Parameters:
      str - the String to check, may be null
      Returns:
      the passed in String, or the empty String if it was null
      See Also: